Feature/quadrature tree shap gpu improvements #12652
All Vouch review confidence checks passed
Residual risk 0.17 = Change Risk (0.42) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.42 · 340 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.349
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #12652"
general
weight: 0.35
RAMitchell
Simplify and speed up QuadratureTreeSHAP on GPU
This PR speeds up SHAP values and, especially, interaction values on the GPU, and makes
shap.cumore than 100 lines shorter. Only the GPU code changes, and the results stay the same
(up to floating-point rounding). See the speedup results in a comment below.
1. Keep the features of the current path in shared memory (interaction values).
To compute interactions, the kernel repeatedly needs the distinct features on the current tree path. It used to rebuild this list at every step by rescanning the path in global memory, which costs O(D²) per step for a tree of depth D. It now keeps the list up to date in shared memory as it walks the tree, so the lookup costs O(D). On a T4, interaction values are about 1.1–1.2× faster for depth-6 trees and about 2× faster for depth-16 trees.
2. Parallelize the final step of interaction values.
After the tree walk, each interaction matrix is made symmetric (the (i, j) and (j, i) entries are
averaged) and its diagonal (each feature's interaction with itself) is computed. This used to run
with a single GPU thread per matrix. It now runs as two passes: one thread per entry to make the matrix symmetric, then one thread per column to compute its diagonal. The results are bit-for-bit the same. The gain is largest for models with many features: with 1000 features, interaction values are 3.4× faster in batch and about 60× faster for a single row.
3. Pad the last block of rows instead of handling it separately.
The GPU processes rows in blocks of 4. When the number of rows was not a multiple of 4, the leftover rows ran in a second, specialized kernel that could only start after the first one finished. For deep trees this could almost double the run time. Now the empty slots of the last block simply repeat the last row and are not allowed to write their results. For example, with 34 rows the last block gets rows 32, 33, [33], [33]. This is up to about 1.7× faster for deep trees (e.g. 70 rows at depth 16) and removes about 100 lines of code.
4. Let every thread read its own values.
Previously, one thread per row read values such as
p_enterandq_prevand passed them to the other 7 threads of that row with warp shuffles. Since padding guarantees that every thread works on a real row, each thread can now read these values directly. This removes more than half of the shuffles in the tree walk, gives a 3–8% speedup on deep trees, and removes about 40 lines of code.Validation: the GPU tests pass, and the outputs were checked against the CPU implementation and an exact float64 reference on several models (up to depth 16 and 1000 features).