Run elementwise prediction transforms in blocks of rows #12819
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
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.354
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #12819"
general
weight: 0.35
RAMitchell
The CPU prediction transforms ran
ParallelForwith one element per iteration: the sigmoid ofbinary:logistic, theexpofcount:poisson,reg:gamma,reg:tweedieandsurvival:aft, hinge, and the matchingProbToMargin. So a 16-rowpredictstarted 12 threads to compute 16 sigmoids. #12792 caps the threads at the loop size, but that only helps belownthreadelements.TransformCpuandAFTPredTransformCpunow calllinalg::cpu_impl::ElementWiseKernel, the kernelGradientCpualready 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 toParallelForitself, sinceParallelForruns 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
masterby md5 on both machines below.Benchmark. Warm-cache
booster.predict(d)on aDMatrixalready 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, defaultnthread. Best of 5 timed loops, 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 ||---|---:|---:|---:|---:|
| 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_predictof 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,HingeandPredictor*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:softprobwith 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 throughcommon::Transform, which other callers share.Risk: low; batches of up to 2048 predictions now run on one thread. Revert: the two source files.