← Back to Pull requests

Feature/quadrature tree shap gpu improvements #12652

Closed
unknown closed this pull request without merging on Oct 07, 2026 09:16 UTC
View on GitHub
unknown unknown commented on Oct 04, 2026 13:29 UTC
Author

Simplify and speed up QuadratureTreeSHAP on GPU

This PR speeds up SHAP values and, especially, interaction values on the GPU, and makes shap.cu
more 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_enter and q_prev and 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).

Diff: 340 lines (+255 / -85) across 4 files Reviewer: RAMitchell Review duration: 4066m
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
0.42
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
60%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
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
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 60.5% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 42.3% (MEDIUM) · Higher = larger blast radius
42.3%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 60.5% · Lower = rushed or shallow review
60.5%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 16.7% · Safe to merge
16.7%
Repository