Research
Numerical Fragility in Transformers: A Layer-wise Theory for Risk Estimation and Selective Stabilization
Overview Research area: Numerical stability and finite-precision (low-precision) execution of Transformer networks, combining floating-point error analysis with a runtime stabilization algorithm. Tech

- arXiv
- 2510.21770
- Published
- 2025-10-17
- Authors
- Jinwoo Baek
AI summary
Overview
- Research area: Numerical stability and finite-precision (low-precision) execution of Transformer networks, combining floating-point error analysis with a runtime stabilization algorithm.
- Technical level: Advanced. The paper is built on matrix perturbation bounds, condition numbers, Jacobian norms, and spectral-norm arguments, and it assumes familiarity with attention, LayerNorm, and mixed-precision execution.
- Scope (one sentence): The paper derives a first-order, layer-wise decomposition of Transformer forward error under finite-precision arithmetic and converts it into a practical layer-wise risk estimator plus a budgeted controller (BGSS) that selectively raises LayerNorm epsilon (ε) on high-risk, LayerNorm-dominated layers.
What This Paper Is About
Low-precision execution (BF16, FP16, quantized formats) can make a Transformer produce noticeably different outputs even when the weights and inputs are fixed, and this mismatch is usually only watched at the final output. That tells you a run is numerically unstable, but not which layers caused it, which mechanism dominates, or where a limited stabilization budget should be spent. The paper builds a layer-wise theory that splits the output mismatch into attention-side sensitivity, LayerNorm ε-dependence, and residual transport, then turns that theory into an online controller that stabilizes only the layers the theory flags.
Key Contributions
- A unified layer-wise forward-fragility theory. Attention-side forward error (Theorem 1), residual relaxation (Theorem 2 and Corollary 1), and LayerNorm normalization-path forward error with explicit ε-dependence (Proposition 1) are combined into a single bound (Theorem 3) that expresses relative output mismatch as a sum of layer-local magnitudes transported by downstream residual factors ∏(1 + ρ_k).
- A practical causal estimator derived from the bound. The exact coefficients are replaced by causal, nonnegative surrogates computed from the monitored pass, preserving the score structure of local magnitude / final-output scale × downstream transport × monotone ε-dependence.
- Bound-Guided Selective Stabilization (BGSS). A budgeted online controller that increases LayerNorm ε only on layers that are simultaneously high-risk (Ĝ ≥ τ_G), LayerNorm-dominant (φ̂ ≥ τ_φ), and in the ε-dominated regime (ρ̂_LN < 1), with a top-B budget, cooldown, and monotone bounded updates. Weights, optimizer states, and architecture are left unchanged.
- Empirical validation of the full pipeline. Controlled mechanism probes (E1), GPT-2 end-to-end predictor evaluation (E2), reference-patch attribution fidelity (E3), and budget-matched mitigation experiments (E5).
Main Findings
- Local mechanisms validate the theory (E1). In a 2×2 toy attention sweep varying score margin and value scale, the attention proxy tracks the measured attention-output perturbation with Pearson = 0.999999 and Spearman = 1.0, matching Theorem 1. In a LayerNorm sweep over 10 logarithmically spaced ε values, both the measured normalization-path change and the causal proxy decrease monotonically with ε, matching Proposition 1. In a residual sweep over 8 local gain values with depth-6 transport, measured downstream amplification stays below the predicted transport bound at all tested ρ values, matching Theorem 2 and Corollary 1.
- Transport matters for end-to-end prediction (E2). On GPT-2, the transport-aware combined predictor is positively correlated with FP32-reference mismatch in all 18 runs. Mean Pearson/Spearman is 0.370 ± 0.119 and 0.351 ± 0.060, versus 0.206/0.212 for the no_transport ablation. Adding transport improves correlation in 17/18 runs and improves top-k retrieval of high-mismatch windows in 12/18 runs.
- The score preserves layer ordering information (E3). Reference-patch attribution on the top-8 highest-mismatch windows per run yields mean Spearman 0.362 ± 0.156, pairwise ordering accuracy 0.643 ± 0.061, top-3 overlap 0.505 ± 0.108, and top-5 overlap 0.622 ± 0.084. The recomputed baseline mismatch agrees with the source E2 mismatch to within an average absolute gap of 9.24 × 10⁻⁷ ± 3.47 × 10⁻⁷, so the attribution is not confounded by a different forward path.
- Selective stabilization beats random at matched budget (E5). Relative to a random same-budget controller, BGSS reduces onset events (10.67 ± 1.15 vs. 11.67), final mismatch (1.243 × 10⁻³ ± 2.87 × 10⁻⁵ vs. 1.284 × 10⁻³), and worst-case mismatch (3.14 × 10⁻³ ± 1.01 × 10⁻³ vs. 8.49 × 10⁻³).
- BGSS trades a little mean error for much better tails versus a risk-only controller (E5). Against a risk-only same-budget controller, BGSS matches mean onset events (10.67 vs. 10.67) while reducing worst-case mismatch (3.14 × 10⁻³ vs. 5.71 × 10⁻³), at a slight cost in mean final mismatch (1.243 × 10⁻³ vs. 1.221 × 10⁻³).
- The mitigation result is tied to a monotonicity guarantee. Proposition 2 shows the frozen-scale LayerNorm contribution and the corresponding layer score are nonincreasing in ε, with a closed-form derivative; the update rule is the smallest bounded monotone local risk-reducing action toward the target ratio ρ*. The algorithmic analogue under frozen monitored statistics is stated for the surrogate.
- Not reported in the provided content: results for an "E4" experiment (the protocol describes E1, E2, E3, and E5 only), wall-clock or memory savings from BGSS, and the LayerNorm/residual curves referenced to Appendix A.8, which is not included in the supplied text.
Methodology in Plain English
The authors start from a standard floating-point model in which every arithmetic operation is exact up to a relative factor (1 + δ) with |δ| ≤ ε_mach. They then analyze three places where error enters a Transformer block separately, in each case deriving a first-order bound: the attention path (softmax sensitivity, score-formation error, and value amplification, captured by quantities like κ_softmax, χ_score, and κ_val), the LayerNorm path (a term whose size depends explicitly on ε and on the layer's variance), and the residual path (shown to be well-conditioned when the local Jacobian norm is below 1). Combining these gives a single bound in which each layer contributes a local magnitude that is then amplified by downstream residual factors on its way to the output.
To make this usable at runtime, they replace the exact coefficients with surrogates measurable from the monitored forward pass — attention score/query/key/probability/value norms, the softmax Jacobian norm, the observed variance, and the current ε — while keeping the same algebraic structure. The resulting per-layer score Ĝ and LayerNorm-dominance ratio φ̂ drive a controller. Every m steps, BGSS ranks eligible layers by Ĝ, keeps the top B, and raises ε to the smallest clipped value that would push the monitored LayerNorm ratio below a target ρ*, never decreasing ε and enforcing a cooldown. Validation follows the theory-to-algorithm structure: synthetic sweeps for the local claims, then GPT-2 runs (HuggingFace gpt2 checkpoint, BF16/FP16 monitored passes on WikiText-103 validation, sequence lengths {128, 512, 1024}, 3 seeds, 96 monitored windows per run, 18 completed runs) for the predictor and attribution, and FP32-master/FP16-shadow training on WikiText-2 train (sequence length 256, 256 monitored steps, 3 seeds, shared budget of 24 actions) for the budget-matched mitigation comparisons. FP32 execution serves as the numerical reference throughout.
Why This Matters
- Impact on research: Numerical fragility under low precision is usually treated as a global implementation artifact or measured only through task accuracy. This paper reframes it as a structured, layer-local phenomenon with a decomposition that can be estimated online and acted on selectively, giving low-precision robustness a causal, per-layer account rather than a single scalar.
- Real-world applications:
- Mixed-precision and low-precision training or inference pipelines that need to run stably without falling back to full FP32 everywhere.
- Quantized or compressed LLM deployment, where output drift from reduced precision is a practical risk.
- Large-scale serving systems that want a cheap online monitor to flag numerically fragile layers or runs.
- Numerical debugging and reproducibility tooling that needs to localize which blocks cause forward discrepancy.
- Industry relevance: The intervention only changes LayerNorm ε values, leaving weights, optimizer state, and architecture untouched, and it operates under an explicit action budget. That makes it compatible with existing training and inference stacks where a full precision upgrade is too expensive and where spending stabilization effort on every layer is not affordable.
Future Directions
- Calibration across kernels and hardware. The paper explicitly does not claim exact calibration of the practical score Ĝ across kernels or runtimes, so establishing how thresholds and the surrogate constants transfer between accelerators and libraries is an open question.
- Closing the gap to the risk-only controller on mean final mismatch. BGSS matches the risk-only controller on onset events and sharply improves worst-case mismatch, but pays a slight cost in mean final mismatch (1.243 × 10⁻³ vs. 1.221 × 10⁻³); improving both simultaneously is unresolved.
- Broadening the intervention class. BGSS acts only through LayerNorm ε and only on the top-B eligible layers, so extending the same causal risk score to other precision-control levers and to larger models, longer sequences, and quantized formats remains to be tested.
- Theoretical coverage of the constants. The bounds rely on kernel- and dimension-dependent constants (c_smx, c_gemm, c'_gemm, a_ln) that are absorbed into thresholds in practice; characterizing them explicitly would let the bound be compared directly to measured mismatch rather than used for ranking.
Target Audience
This paper is most valuable to numerical-precision and machine-learning-systems researchers working on low-precision training and inference, and to engineers building mixed-precision or quantized Transformer training and serving pipelines. It also suits readers interested in mechanistic interpretability-style attribution, since the reference-patch layer localization connects the risk score to causal layer importance. The theory sections require comfort with floating-point error analysis, condition numbers, and spectral norms, so readers without a numerical-analysis background will find the algorithm and experimental sections the most accessible entry points.
Authors’ abstract
Low-precision execution can induce substantial forward discrepancies in Transformers even for fixed weights and input, yet these discrepancies are usually monitored only at the output and lack a layer-wise theoretical account. We develop a first-order decomposition of output mismatch into layer-local attention, LayerNorm, and residual-transport terms, and derive from it a practical causal risk estimator and a budgeted controller, Bound-Guided Selective Stabilization (BGSS). Controlled sweeps verify the predicted local sign, monotonicity, and transport structure. On GPT-2, the transport-aware combined predictor is positively correlated with FP32-reference mismatch in all $18$ runs and improves over a no-transport ablation in $17/18$ runs. Reference-patch attribution shows that the same score preserves useful layer ordering information (mean Spearman $0.362$). In budget-matched mitigation, BGSS outperforms random same-budget control in onset events ($10.67$ vs. $11.67$), final mismatch ($1.243\times 10^{-3}$ vs. $1.284\times 10^{-3}$), and worst-case mismatch ($3.14\times 10^{-3}$ vs. $8.49\times 10^{-3}$), while matching a risk-only same-budget controller on onset suppression and sharply reducing worst-case mismatch ($3.14\times 10^{-3}$ vs. $5.71\times 10^{-3}$). These results support a theory-to-algorithm account of Transformer numerical fragility in which finite-precision risk can be analyzed, estimated, localized, and selectively stabilized.