feature/simplify_and_speedup_QuadratureTreeSHAP_CPU #12650
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 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.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #12650"
general
weight: 0.35
ron-wettenstein
Faster QuadratureTreeSHAP on CPU (
pred_contribsandpred_interactions)Summary.
In the last few days I reviews the QuadratureTreeSHAP CPU code. Used this opportunity to:
1. Speedup the approach. SHAP interaction values are 1.6–4.9× faster, more for deeper trees and more threads. SHAP values are 1.5-1.9× faster with GCC (the Linux wheel compiler) and unchanged with MSVC (on Windows).
2. Simplify the code. Uniting logic between Shapley values and interaction values, removing several utility classes and make the code follows Alg 1. psuedo code from https://arxiv.org/pdf/2605.04497 more closely. This refactor, and the deletion of utility classes speed up parallelization as threads are less dependent now on shared objects.
Changes
1. Interaction values share the shared polynomial construction code with Shapley values. The interaction values logic build the shared polynomial (c and H_u in Alg 1 of the paper) once reuse it for each feature pair in the path. Estimated 1.2–2.7× on 1 thread, growing with depth, plus a further 2.7–3.4× at 8 threads.
2. Cover ratios are precomputed once per call, instead of a division and three
CHECKs on every visited node.SHAP values 1.30–1.44× (GCC) and 1.09–1.21× (MSVC); interactions 1.07–1.17× and 1.01–1.14×.
4. Hot-path
CHECKs removed: Removed CHECKs that occur for every row and every node/leaf. All removed CHECKs holds by construction. About 1.04–1.09× (GCC) and 1.01–1.07× (MSVC).5. Quadrature weights applied per return edge, as in the paper, instead of at the leaves. This change speed up the GCC complied code, as it allows for better SIMD vectorization but slows down Windows complied code as it requires more multiplications than the previous version. SHAP values 1.07–1.10× (GCC) but 0.83–0.85× (MSVC); interactions about 1.0× (GCC) and 0.90–0.93× (MSVC).
6. Plain Gauss–Legendre rule The previous implementation used instead of the t = s² endpoint rule. This improves the algorithm accuracy on very deep trees. In most cases both approaches reach float32 noise.
7. Cleanup. Removed: QuadraturePathElement, QuadraturePathView, EmptyQuadraturePathState, LiveQuadraturePathState, ForEachPartner, AccumulatePair, ResetPath/PushPathSplit/PopPathSplit. InteractionContributionFormulation and AdditiveContributionFormulation formulations only now include
HandleReturn. No speed change.The per-change numbers were measured one at a time on intermediate versions during development, so they don't
multiply to the totals below.
Benchmark: speedup over master (master time / branch time)
| Model | Features | Depth | Task | MSVC 1T | MSVC 8T | GCC 1T | GCC 8T |
|---|---|---|---|---|---|---|---|
| heloc | 23 | 6 | SHAP values | 1.01× | 1.10× | 1.68× | 1.71× |
| | | | interactions | 1.57× | 2.78× | 2.64× | 4.25× |
| superconductivity | 81 | 6 | SHAP values | 1.00× | 1.04× | 1.88× | 1.71× |
| | | | interactions | 1.62× | 2.73× | 2.83× | 3.94× |
| superconductivity | 81 | 16 | SHAP values | 1.03× | 1.14× | 1.67× | 1.73× |
| | | | interactions | 2.56× | 3.14× | 3.61× | 4.52× |
| superconductivity | 81 | 24 | SHAP values | 1.04× | 1.08× | 1.50× | 1.61× |
| | | | interactions | 3.18× | 3.54× | 4.37× | 4.89× |
| bioresponse | 1776 | 6 | SHAP values | 0.99× | 1.12× | 1.91× | 1.58× |
| | | | interactions | 1.03× | 1.02× | 1.30× | 1.10× |
| synthetic, 3-class | 20 | 6 | SHAP values | 1.00× | 0.98× | 1.86× | 1.72× |
| | | | interactions | 1.62× | 2.75× | 2.99× | 4.30× |
<details><summary>Absolute times (ms per call, master → branch)</summary>
| Model | Task | Rows 1T / 8T | MSVC 1T | MSVC 8T | GCC 1T | GCC 8T |
|---|---|---|---|---|---|---|
| heloc d6 | SHAP values | 672 / 5376 | 176 → 175 | 355 → 335 | 131 → 78 | 247 → 141 |
| heloc d6 | interactions | 446 / 3568 | 292 → 186 | 920 → 330 | 282 → 99 | 759 → 181 |
| superconductivity d6 | SHAP values | 526 / 4208 | 191 → 190 | 377 → 361 | 157 → 83 | 265 → 153 |
| superconductivity d6 | interactions | 297 / 2376 | 289 → 179 | 881 → 323 | 264 → 93 | 757 → 193 |
| superconductivity d16 | SHAP values | 26 / 208 | 226 → 220 | 412 → 364 | 185 → 111 | 303 → 179 |
| superconductivity d16 | interactions | 13 / 104 | 576 → 225 | 1183 → 374 | 550 → 149 | 1157 → 249 |
| superconductivity d24 | SHAP values | 13 / 104 | 238 → 230 | 421 → 387 | 195 → 123 | 310 → 192 |
| superconductivity d24 | interactions | 6 / 48 | 763 → 241 | 1395 → 392 | 738 → 165 | 1407 → 293 |
| bioresponse d6 | SHAP values | 468 / 3751 | 137 → 139 | 261 → 234 | 100 → 52 | 165 → 105 |
| bioresponse d6 | interactions | 4 / 32 | 42 → 41 | 170 → 168 | 54 → 40 | 207 → 213 |
| synthetic 3-class d6 | SHAP values | 413 / 3304 | 217 → 217 | 422 → 425 | 177 → 96 | 326 → 184 |
| synthetic 3-class d6 | interactions | 221 / 1768 | 307 → 190 | 931 → 348 | 306 → 98 | 775 → 181 |
</details>
Setup.
/O2, Release, the same flags as the Windows wheel, on Windows 11.-O3, a pip-style build like the Linux wheels, in WSL2 Ubuntu 24.04 on the same machine.nthread1 and 8.synthetic 3-class
multi:softprobmodel with 150 trees.round takes the median of 3 calls after a warm-up, and the table shows the median speedup across rounds. 8-thread
results on this laptop vary by about ±10% between rounds.
Correctness.
are in the tens to hundreds, and at most 2e-6 on the other models.
superconductivity d6.
Predictor.Shap*tests pass, and so do the Python tests intest_shap.py,test_interpret.py,test_multi_target.pyandtest_predict.py.