← Back to Pull requests

Run elementwise prediction transforms in blocks of rows #12819

Closed
unknown closed this pull request without merging on Nov 09, 2026 14:13 UTC
View on GitHub
unknown unknown commented on Nov 09, 2026 12:11 UTC
Author

The CPU prediction transforms ran ParallelFor with one element per iteration: the sigmoid of binary:logistic, the exp of count:poisson, reg:gamma, reg:tweedie and survival:aft, hinge, and the matching ProbToMargin. So a 16-row predict started 12 threads to compute 16 sigmoids. #12792 caps the threads at the loop size, but that only helps below nthread elements.

TransformCpu and AFTPredTransformCpu now call linalg::cpu_impl::ElementWiseKernel, the kernel GradientCpu already uses in the same header. It runs blocks of 2048 elements, so a batch of up to 2048 predictions runs on one thread, and larger batches still split across threads by block. I kept the change at these two call sites instead of adding a minimum block to ParallelFor itself, since ParallelFor runs loops whose per-iteration cost varies a lot; that is a judgment, not something I measured.

Results are identical: the functor is the same, and predictions on 1M and 16 rows match master by md5 on both machines below.

Benchmark. Warm-cache booster.predict(d) on a DMatrix already predicted once, so the trees are skipped and the time is the transform plus the API around it. binary:logistic, 100 trees, 42 float32 columns, default nthread. Best of 5 timed loops, 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 |
|---|---:|---:|---:|---:|
| 1 | 10.7-11.4 µs | 10.8 µs | 12.6-17.7 µs | 12.4-12.7 µs |
| 16 | 56-64 µs | 10.7-11.0 µs | 14.6-18.1 µs | 12.5-12.6 µs |
| 256 | 63-64 µs | 11.1-11.3 µs | 14.0-15.4 µs | 13.0 µs |
| 2048 | 64-65 µs | 13.6-13.7 µs | 15.2-17.0 µs | 15.8-15.9 µs |
| 20000 | 69-71 µs | 67-67.5 µs | 26.5-28.0 µs | 26.5-27.4 µs |
| 1M | 0.35-0.36 ms | 0.35-0.36 ms | 0.63-0.64 ms | 0.58-0.62 ms |

The 1M row on Linux is the median of 7 loops per round over 5 rounds, since the first run there was noisy.

inplace_predict of 16 rows goes from 117-133 to 85 µs on macOS and is unchanged on Linux (32-36 µs). Peak RSS is the same. 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 Objective, Obj, AFT, Hinge and Predictor* gtests pass (97 tests; the distributed ones can't open sockets in my sandbox and were skipped).

Not in this PR. The row-wise transforms (multiclass softmax, expectile, quantile) have the same overhead: multi:softprob with 5 classes takes 64 µs for 16 rows with 12 threads and 11 µs with 1. They need their own block size, since each row costs more than one element, so I left them for a follow-up. Cox goes through common::Transform, which other callers share.

Risk: low; batches of up to 2048 predictions now run on one thread. Revert: the two source files.

Diff: 371 lines (+278 / -93) across 4 files Reviewer: RAMitchell Review duration: 121m
All Vouch review confidence checks passed
Residual risk 0.17 = Change Risk (0.43) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.43 · 371 lines diff across 4 files
0.43
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.354
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #12819"
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: 42.8% (MEDIUM) · Higher = larger blast radius
42.8%
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.9% · Safe to merge
16.9%
Repository