[BUG] Avoid intermediate overflow in vectorized QuantileLoss #2465
All Vouch review confidence checks passed
Residual risk 0.29 = Change Risk (0.50) × (1 − Review Confidence (0.43)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.50 · 421 lines diff across 5 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 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.362
Shallow Review Depth
shallow_review_depth
0.344
Ai Authored
ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #2465"
general
weight: 0.35
phoeenniixx
LLM generated content, by OpenAI Codex
Reference Issues/PRs
Follow-up to the vectorization in #2447. This addresses numerical overflow rather than the input-shape change proposed in #2113.
What does this implement/fix? Explain your changes.
The equivalent pinball expression
(abs(error) - error) / 2first doubles negative residuals. That intermediate can overflow even when the final quantile loss is representable. In float16, a residual of -40000 at q=.75 produces infinity instead of 20000; the public metric then substitutes its nonfinite-loss fallback of 1e9.Use
q error - min(error, 0)before the existing factor of two. This avoids doubling the residual, retains broadcasting and the vectorized implementation, and preserves the existing zero-residual subgradient throughtorch.minimum.Reproducible example and motivation
This standalone CPU example addresses the request for a concrete failure:
The residual
-40000and final value2 (1 - .75) * 40000 = 20000both fit in float16. The former intermediateabs(error) - error = 80000exceeds float16's maximum 65504 before division by two can bring it back into range.MultiHorizonMetricthen substitutes 1e9, so this affects the public loss value rather than only a private intermediate. Keeping finite, representable quantile losses correct is the reason for the change.I reran this exact input against the clean base's actual
QuantileLossclass and the PR head on CPU; the values above were reproduced. This targets loss computations with float16 residuals; it does not claim every autocast training configuration uses that dtype or is affected.What should a reviewer concentrate their feedback on?
The equivalent pinball expression and preservation of the zero-residual subgradient. Cases where the final mathematical loss itself exceeds the dtype range are outside this fix.
Did you add any tests for the change?
28 numerical regression cases cover float16/32/64, positive/negative and ordinary/large residuals, two batch/horizon layouts, analytical prediction gradients, zero-residual subgradients and the public one-quantile metric. Clean main: 7 failures, 21 passing controls. Final numerical plus existing metric suites: 98 passed, 6 existing skips because optional
cpflowsis absent.Any other comments?
Python 3.12.14, PyTorch 2.13.0+cpu. Configured pre-commit hooks and
git diff --checkpass. Full-package, GPU, documentation and training-throughput tests were not run. A small one-thread CPU arithmetic benchmark at shape (256,32,7) showed no slowdown for float16/32; this is not a general performance claim.AI disclosure: prepared and tested autonomously with OpenAI Codex. No independent human review has been performed.
PR checklist