Use fewer threads for small multiclass prediction transforms #12821
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 · 321 lines diff across 4 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.345
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #12821"
general
weight: 0.35
RAMitchell
Follow-up to #12819, for the row-wise transform it left out.
MulticlassTransformCpu(the softmax ofmulti:softproband the argmax ofmulti:softmax) ranParallelForover rows withctx->Threads(), so a 16-rowpredictwith 5 classes started 12 threads to transform 80 scores.It now caps the threads at one per 2048 scores, so a batch under 4096 scores runs on one thread, and large batches use
ctx->Threads()as before. The loop body and the static schedule are unchanged. The cap counts scores, not rows, since a row costsn_classesscores.I first tried
ParallelFor1dwith blocks of 256 rows, as #12819 does with 2048 elements. It ignored the class count and made 1M-rowmulti:softprobslower on Linux (2.9 to 3.7 ms), so I dropped it.Results are identical: predictions for 16 rows to 1M rows match
masterby md5 on both machines, for both objectives.Benchmark. Warm-cache
booster.predict(d)on aDMatrixalready predicted once, so the time is the transform plus the API around it. 5 classes, 50 trees of depth 6, 42 float32 columns, defaultnthread. Best of 5 timed loops, median of 3 rounds alternatingmasterand this branch. macOS: Apple M4 Pro, 12 threads, Apple clang. Linux: Dockerpython:3.12on the same Mac, 4 CPUs, GCC with GOMP.| | rows | macOS
master| macOS PR | Linuxmaster| Linux PR ||---|---:|---:|---:|---:|---:|
|
multi:softprob| 16 | 57.0 µs | 10.4 µs | 13.6 µs | 12.0 µs || | 256 | 53.7 µs | 13.5 µs | 14.3 µs | 14.3 µs |
| | 2048 | 57.8 µs | 46.9 µs | 20.5 µs | 21.0 µs |
| | 20000 | 101.7 µs | 103.0 µs | 78.1 µs | 75.3 µs |
| | 1M | 2.5 ms | 2.5 ms | 2.9 ms | 3.0 ms |
|
multi:softmax| 16 | 52.2 µs | 10.3 µs | 13.2 µs | 12.0 µs || | 2048 | 61.2 µs | 33.1 µs | 20.0 µs | 20.7 µs |
| | 1M | 1.2 ms | 1.2 ms | 1.4 ms | 1.4 ms |
At 1M rows both branches run the same code with the same thread count, so the Linux 2.9 vs 3.0 ms is run-to-run spread. Peak RSS is the same. As in #12819, the gain depends on what the OpenMP runtime pays to start a parallel region: about 50 µs with 12 threads on macOS, a few µs with GOMP on 4 CPUs.
Tests. The
Multiclass,Softmax,ObjectiveandPredictorgtests pass (87 tests; distributed ones skipped), andtests/python/test_predict.pypasses.Not in this PR. The expectile and quantile transforms have the same per-row pattern; I left them out to keep this one small.
Risk: low; only the thread count changes, and only below 2048 scores per thread. Revert:
src/objective/multiclass_obj.cc.