← Back to Pull requests

Use fewer threads for small multiclass prediction transforms #12821

Closed
unknown closed this pull request without merging on Nov 10, 2026 09:54 UTC
View on GitHub
unknown unknown commented on Nov 09, 2026 14:45 UTC
Author

Follow-up to #12819, for the row-wise transform it left out. MulticlassTransformCpu (the softmax of multi:softprob and the argmax of multi:softmax) ran ParallelFor over rows with ctx->Threads(), so a 16-row predict with 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 costs n_classes scores.

I first tried ParallelFor1d with blocks of 256 rows, as #12819 does with 2048 elements. It ignored the class count and made 1M-row multi:softprob slower on Linux (2.9 to 3.7 ms), so I dropped it.

Results are identical: predictions for 16 rows to 1M rows match master by md5 on both machines, for both objectives.

Benchmark. Warm-cache booster.predict(d) on a DMatrix already predicted once, so the time is the transform plus the API around it. 5 classes, 50 trees of depth 6, 42 float32 columns, default nthread. Best of 5 timed loops, median of 3 rounds alternating master and this branch. macOS: Apple M4 Pro, 12 threads, Apple clang. Linux: Docker python:3.12 on the same Mac, 4 CPUs, GCC with GOMP.

| | rows | macOS master | macOS PR | Linux master | 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, Objective and Predictor gtests pass (87 tests; distributed ones skipped), and tests/python/test_predict.py passes.

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.

Diff: 321 lines (+240 / -81) across 4 files Reviewer: RAMitchell Review duration: 1149m
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
0.42
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
60%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
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
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 60.5% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 41.9% (MEDIUM) · Higher = larger blast radius
41.9%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 60.5% · Lower = rushed or shallow review
60.5%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 16.6% · Safe to merge
16.6%
Repository