Only zero and accumulate split-feature columns in CPU SHAP contributions #12823
All Vouch review confidence checks passed
Residual risk 0.20 = Change Risk (0.50) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.50 · 561 lines diff across 7 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.379
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #12823"
general
weight: 0.35
RAMitchell
What
CPU
pred_contribs=True(QuadratureTreeSHAP) zeroed and accumulated every feature column for every row and every tree. A tree only writes to the features it splits on, becauseAdditiveContributionFormulation::HandleReturnonly adds tophi[split_index]. This PR builds each tree's sorted, unique split features once per call and zeroes and accumulates only those columns.Why
On wide data, that per-tree pass over all columns was most of the work. A text model with 38,563 TF-IDF features and 20 classes swept 38,563 columns × 2,000 trees for every row, while each depth-6 tree splits on at most 63 features.
Median
predict(..., pred_contribs=True)time, 100-roundmulti:softprobhistmodels, same model file and input on both sides:| Case | Environment | Pairs | Base | Branch |
|---|---|---:|---:|---:|
| 20 newsgroups TF-IDF, 38,563 features, 20 classes, 200 rows | macOS arm64, 12 threads | 6 | 0.272 s | 0.037 s |
| same | Linux arm64 Docker VM, 4 CPU / 8 GiB | 6 | 0.576 s | 0.053 s |
| MNIST, 784 features, 10 classes, 2,000 rows | macOS arm64 | 6 | 0.105 s | 0.087 s |
| same | Linux arm64 Docker VM | 6 | 0.214 s | 0.159 s |
| covertype, 54 features, 7 classes, 20,000 rows | macOS arm64 | 6 | 2.61 s | 2.56 s |
| same | Linux arm64 Docker VM | 4 runs of 6-8 | no measurable change | |
Peak RSS is unchanged (1,985 → 1,981 MiB on macOS for the text case, 1,844 MiB on both sides on Linux). On covertype the four Linux runs gave −16%, +12%, +4% and −4% for the branch, so the VM noise was larger than any effect there. The Linux VM runs on the same Apple Silicon Mac, not bare-metal Linux.
Numerical behavior
Every column still gets the same operations, in the same tree order. The skipped work was
p += 0.0f weighton columns the tree never writes.multi_output_tree, pruned (gamma),base_marginanditeration_rangemodels.-ffp-contract=off, base and branch are bit-identical, so the difference comes from where GCC fuses multiply-adds, not from the change in logic. The base output already differs bitwise between the clang and GCC builds.infornanturned every column of the row intonan(0 inf). Now only that tree's split columns get it. Finite weights are what DART produces; I only hit this with a hand-edited model.pred_interactionsdoes not build or use the new lists.approx_contribs=True(ApproxFeatureImportance) has the same full-width loop; I left it for a follow-up to keep this PR small.How to test
pytest tests/python/test_interpret.py tests/python/test_shap.py tests/python/test_multi_target.py: 73 passed. I did not build the C++ gtests locally;tests/cpp/predictor/test_shap.ccchecks that contributions sum to the margin.<details><summary>Benchmark script</summary>
Models:
xgb.train({"objective": "multi:softprob", "num_class": k, "tree_method": "hist", "max_depth": d, "seed": 0}, ..., 100)withmax_depth6 (news, MNIST) or 8 (covertype). News:TfidfVectorizer(min_df=3, stop_words="english")on the 20 newsgroups train split, scoring the first 200 test documents. MNIST: first 20,000 rows to train, rows 60,000-62,000 to score. Covertype: first 100,000 rows to train, rows 100,000-120,000 to score.</details>
Risk
Low. If a future contribution formulation writes to columns other than the tree's split features, those writes would be dropped; the sum-to-margin tests would catch a missing column. Revert by restoring the two full-width loops in
QuadratureTreeShapValues.