fix(df): make decision forest OOB results and variable importance independent of the thread count #3911
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 #3911"
general
weight: 0.35
Vika-F
Description
CPU decision forest training accumulates out-of-bag predictions and variable importance in thread-local buffers and merges them in scheduling order (
tlsCtx.reduceindf_train_dense_default_impl.i). The regression prediction sums and the importance means are floating-point, so the OOB error, the per-observation OOB results, the OOB predictions andvariableImportancediffer in the last bits between runs with the same seed and between thread counts. scikit-learn computes these sequentially in tree order and is reproducible; sklearnexoob_score_,oob_prediction_andfeature_importances_inherit the drift. Surfaced during the review of #3872.The threading layer's
static_threader_reduceuses TBB'sstatic_partitioner, whose chunking depends on the thread count, and a reducer body for OOB would be a fullnRowsbuffer per split, so a deterministic reduction would either depend on the thread count or multiply memory. This change sums every floating-point result in tree order instead and keeps tree building fully dynamic:nTrees x ceil(nRows / 8)bytes; only that task writes its tree's mask). After the parallel loop, a pass parallel over row blocks adds, for each row, the predictions of the trees for which it is OOB in tree index order, indouble, using the model's trees (findNodeon theDecisionTreeTable, as in prediction). This is the order scikit-learn uses foroob_prediction_, and no extended precision is involved. The per-thread regression OOB buffers are removed.nTrees x nFeaturesbuffer (each task writes the row of the tree it builds) and reduced in tree order after the parallel loop: a plain sum for MDI, Welford mean/variance for MDA_Raw and MDA_Scaled. The cross-thread Welford merge andvarImpVarianceare removed.oobBufpointer.init(par, x, nClasses, mainCtx)), andcreateTlsContextchecks its allocation before constructing.Both
defaultDenseandhist, best and random splitters, float and double sharecomputeImpl, so all CPU paths are covered. For regression with OOB results, the per-threadnRows x 16byte OOB buffers are replaced by thenTrees x nRows / 8byte masks; variable importance addsnTrees x nFeaturesvalues when requested.What changes for users: only the OOB outputs (OOB error, per-observation error, R2,
oob_prediction_) and variable importance, and only in the last bits, now identical across thread counts. The trees and thereforepredict()are unchanged. One exception to "last bits": with MDA_Raw or MDA_Scaled, a tree without OOB rows (possible for smallnRowswithobservations_per_tree_fractionnear 1) now enters the per-tree mean as a zero. Onmainit was counted in the divisor but not in the running mean, so how much it weighed depended on where it fell in its thread's sequence of trees, and MDA for such fits changes by more than rounding.Performance: to be re-measured for the tree-order OOB pass.
Tests:
df cls responses in the other float typeanddf reg responses in the other float typein//cpp/oneapi/dal/algo/decision_forest:teststrain the same forest twice, once with float and once with double responses holding the same float-representable values, and require bitwise-equal predictions, per-observation OOB error and MDI importance. Onmainthey fail in every run (the importance for classification, the OOB error or the importance for regression); with this PR they pass.//cpp/oneapi/dal/algo/decision_forest:testspasses.No public API or ABI changes.
---
<details>
<summary>Checklist:</summary>
Completeness and readability
Testing
Performance
</details>
🤖 Generated with Claude Code