Skip to content

Support parallel computing for treeshap function? #49

Open

Description

@HUI950319

Feature Request

It would be beneficial to add parallel computing support for the tree function to improve performance.

Background

The tree function can be slow when processing large datasets or performing complex computations.

Proposal

  • Evaluate the feasibility of implementing parallel computing for the tree function
  • Consider different approaches:
    • Multi-threading
    • Multi-processing
    • GPU acceleration
  • Assess potential architecture changes and compatibility issues
  • Design an implementation plan if feasible

Questions

  • Is parallel computing technically feasible for the tree function in the current architecture?
  • What would be the recommended approach for implementation?
  • Are there any breaking changes or compatibility concerns?

Activity

  1. mayer79 commented on Apr 24, 2026

    @mayer79
    Contributor

    The easiest way would be to parallelize the outer for-loop (the one that loops over observations) in the treeshap_cpp() function in https://github.com/ModelOriented/treeshap/blob/master/src/treeshap.cpp:

      for (int obs = 0; obs < x.ncol(); obs++) {
        NumericVector observation = x[obs];
        LogicalVector observation_is_na = is_na[obs];
    
        NumericVector shaps_row(x.nrow());
    
        for (int i = 0; i < roots.size(); ++i) {
          Path m;
          recurse(yes, no, missing, feature, is_leaf, value, cover, split, decision_type, observation, observation_is_na, shaps_row,
                  m, roots[i], 1, 1, -1,
                  0, 0, 1);
        }
    
        shaps(obs, _) = shaps_row;
    
    #if !defined(WIN32) && !defined(__WIN32) && !defined(__WIN32__)
        if (verbose) {
          updateProgressBar(obs + 1, x.ncol());
        }
    #endif
      }

    Maybe one could do that with rcppParallel?

  2. mayer79 commented on Apr 24, 2026

    @mayer79
    Contributor

    Or we could even move the outer loop outside cpp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions