fix(df): keep the best split's sample order when constant features are skipped #3856
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 · 590 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.382
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #3856"
general
weight: 0.35
Vika-F
Description
Random-forest training on CPU could split a node's samples by the wrong feature. The class histograms recorded for its children then belonged to other samples, and deeper nodes built from them came out with negative class counts. Through scikit-learn-intelex this showed up as
predict_probarows holding a negative probability, e.g.-0.005with 100 trees, onmake_classification(n_samples=200_000, n_features=30, n_informative=15, n_classes=7, n_clusters_per_class=1, random_state=0). Its clip to[0, 1]then broke the row sum, androc_auc_score(..., multi_class="ovr")rejected the scores. The wrapper side is uxlfoundation/scikit-learn-intelex#3449.Cause (
findBestSplitSerialindf_train_dense_default_impl.i). Features already known to be constant are skipped without counting as visited, so the feature loop can run pasti == _nFeaturesPerNode - 1. The code assumed that a split found at that index was the last one evaluated. So it neither savedaIdxintobestSplitIdxnor restored it afterwards. When a later feature took the non-indexed path,featureValuesToBufre-sortedaIdxby that feature. If that feature did not win, the node was then partitioned as "the firstnLeftsamples" in the wrong order. Only small nodes skip the precomputed bin indices, so this needs a node of a few rows with a single-bin feature, which the hist method produces regularly. Both the dense and hist methods are affected, with both splitters. Regression goes through the same code and got wrong leaf means silently. It is deterministic (single-threaded runs give the same leaf), not a race.On the reported data, 119 nodes over the 100 trees were split this way. Only one of them produced a visible negative probability; the others left leaves with wrong but non-negative values.
Fix: track whether
aIdxstill holds the best split's order. Save it whenever another feature may still be visited, and copy it back only if a later feature re-sorted it.Test: "df cls probabilities stay valid when constant features are skipped" uses 2000 rows of 8 binary and 4 continuous features over 4 random classes. It checks that every probability is in
[0, 1], that rows sum to 1, and that each training row's own class has a positive probability. It fails before the fix on CPU in every float/double × dense/hist variant with the best splitter, with values down to -0.1, and passes after it. The wholedecision_forestsuite passes on CPU and GPU. Through scikit-learn-intelex, with only this fix and the current clip-only wrapper, the reported script gives non-negative raw probabilities, row sums within2.2e-16, androc_auc_scoresucceeds, for bothRandomForestClassifierandExtraTreesClassifier.Not fixed here: the GPU hist path does not have this bug, because it splits by bin index. But the GPU
randomsplitter has a separate one:random_splitlets each work-item read one row, so for nodes overmax_work_group_sizerows (1024 on the test device) the histogram is built from only the first 1024 rows, and that also yields invalid probabilities. The new test skips random splitter on GPU, with a comment, until that gets its own fix.---
<details>
<summary>Checklist:</summary>
Completeness and readability
Testing
Performance
No performance change is expected: one extra
memcpyof a node's index range in the rare case where the best split was found at the last index but more features follow. Model quality can change slightly, since affected nodes are now split correctly.</details>
🤖 Generated with Claude Code