TL;DR
When running Large Language Models (LLMs) in fast, low-precision math, tiny rounding errors can snowball as they pass through layers of nonlinear operations. This paper introduces LAMP (Look-Ahead Mixed-Precision), an inference strategy that peeks ahead to see which specific matrix calculations will have their errors blown up by the next operation—like softmax—and selectively recomputes just those few culprits in high precision. By redoing less than 1% of calculations, LAMP boosts numerical accuracy by up to two orders of magnitude.
What Problem Does This Paper Address?
To make LLMs fast and energy-efficient, we rely on mixed-precision arithmetic: shrinking inputs (quantization) to low-precision formats while adding up the results (accumulation) of matrix multiplications in high precision. Usually, this accumulation precision is applied uniformly across an entire output.
However, a transformer isn't just one big matrix multiplication; it's a deep composition of functions $f(g(x))$, alternating between linear matrix products and nonlinearities like softmax or layer normalization. From a numerical analysis perspective, floating-point rounding errors in an inner function $g(x)$ don't affect the final output equally—some get harmlessly absorbed by the outer function $f$, while others get massively amplified. Prior to this work, mixed-precision accumulation that explicitly accounts for how errors propagate into the next operation had gone unexplored in transformer inference.
Methods
Instead of uniformly accumulating every dot product in high precision, the authors propose LAMP, which treats mixed-precision accumulation as a sparse optimization problem:
- Cheap First Pass: Compute the inner matrix-vector product $\hat{y} \approx g(x)$ using fast, low-precision accumulation.
- Look Ahead: Use Taylor's theorem and the Jacobian of the upcoming nonlinearity $f$ to estimate how sensitive $f(\hat{y})$ is to rounding errors in each component of $\hat{y}$.
- Selective Recomputation: Identify the smallest subset of components in $\hat{y}$ needed to keep the overall condition number (error amplification) below a chosen threshold $\tau$, and recompute only those entries in high precision (e.g., FP32).
Normally, finding the sparsest subset of elements to fix would be a combinatorial nightmare. Crucially, the authors prove that for standard transformer nonlinearities—entrywise activations, Root Mean Square (RMS) layer normalization, and softmax—this optimization problem admits simple, closed-form solutions. For attention's softmax, an inner product $y_j$ with softmax probability $z_j$ only needs high-precision recomputation if $2z_j(1 - z_j)|y_j| > \tau$.
Because this "strict" rule requires knowing the full softmax denominator upfront, the authors also introduce a relaxed relative-threshold variant that drops the normalization constant, paving the way for one-pass streaming algorithms.
Datasets
The authors evaluate pre-trained GPT-2 models (primarily GPT-2 XL) on OpenWebText, measuring output accuracy over 100 sequences of 1,024 tokens each against a full-precision (FP32) baseline. No new datasets are introduced, though the "strict" LAMP formulation is proposed as a theoretical optimality benchmark for future mixed-precision attention kernels.
Key Insights and Ideas
- Looking ahead is mandatory: What happens if you don't look at the upcoming softmax, and instead just recompute the dot products that are intrinsically ill-conditioned on their own? Nothing! As shown below, a "non-look-ahead" strategy performs no better than random guessing or doing no recomputation at all. Context—how the next function reacts to the number—is everything.
- "Confused" attention heads need more precision: Looking at the closed-form softmax rule $2z_j(1 - z_j)|y_j| > \tau$ reveals something neat. If an attention head is super confident ($z_j \approx 1$ for one token, $0$ for others), $z_j(1 - z_j)$ vanishes—meaning zero recomputations are needed! High precision is only routed to tokens when an attention head is "confused" and splitting probability mass across multiple competing outcomes.
- Not sparse attention: Unlike sparse attention, which throws away low-scoring tokens and shifts probability mass, LAMP keeps all tokens in low precision and dynamically routes high precision only where numerically necessary.
Key Results
Using simulated floating-point formats with $\mu$ mantissa bits for Key-Query (KQ) inner products in GPT-2 XL:
- Massive accuracy gains for tiny budgets: Recomputing just 0.3%, 1.6%, and 7.6% of KQ inner products in FP32 reduces Kullback–Leibler (KL) divergence (output distribution error) by 12×, 83×, and 385×, respectively, alongside exponential drops in top-1 token flip rates.
- Beating wider uniform formats: Accumulating in BF16 ($\mu = 7$) with 0.9% FP32 recomputation matches the accuracy of uniform TF32 ($\mu = 10$), while using an effective average of just ~8.9 mantissa bits per inner product instead of 10.
- Near-optimal relaxation: The normalization-free relaxed LAMP shifts the accuracy-vs-recomputation Pareto frontier only marginally upward compared to strict LAMP.
Limitations and Future Work
- Hardware support: Experiments rely on software-simulated low-precision accumulators, so no wall-clock speedups are reported. Current AI accelerators lack native instructions for packing multiple tiny accumulators (e.g., four 8-bit accumulators) into a 32-bit register; thus, LAMP currently serves as a mathematical blueprint for next-generation hardware.
- FlashAttention compatibility: Strict LAMP requires materializing all softmax probabilities in memory, making it impractical for long contexts. Integrating the relaxed, normalization-free variant into online one-pass FlashAttention is left for follow-up work.
- Scale and scope: Experiments focus on inference in moderate-sized GPT-2 models and isolate attention's softmax; extending LAMP to larger modern LLMs, simultaneous full-network nonlinearities, and backward passes during training are open directions.
Summary updated