Length-Aware Scaling for FP8 Encoder Pre-training with a Sequence-Length Curriculum

Two cheap tricks for pre-training language models have never been tested together. The first is training in 8-bit floating point (FP8), a number format that is much faster than 16-bit but can represent only a narrow band of magnitudes. The second is a length curriculum, which trains on short text windows first and lengthens them over time. The two interact in a specific way. Attention, the step where each token takes a weighted average over the other tokens in the window, changes the scale of its output when the window changes size. The backward pass also sums over more terms as the window grows. A scaling recipe calibrated for one window length is therefore miscalibrated at the next. We propose to measure this effect in a masked-language-model encoder trained without the next-sentence objective. We will then test a fix that rescales once per curriculum phase, so the model needs no step-by-step range tracking.

The setting matters because each ingredient has been shown to work separately. Encoders pre-trained purely on masked-token prediction match or beat those with the extra next-sentence classification task. Length curricula reach target loss several times faster in decoder language models. Unit-scaled FP8 trains at scale without loss scaling. If the three combine, training a BERT-class encoder gets much cheaper. If they do not combine cleanly, the reason should be numerical and predictable, and we want to locate it.

Core Claim

Unit scaling (Unit Scaling: Out-of-the-Box Low-Precision Training) designs every operation so that activations, weights and gradients have variance near one at initialization. It does this with fixed multipliers derived from layer widths, and it trained BERT-Large in FP8 and FP16 without loss scaling at a fixed 512-token length. The authors of µnit Scaling report that, in causal decoders, attention output variance shrinks as sequence position grows, and their static recipe does not correct this. In a bidirectional encoder every query averages over the whole window, so we expect the analogous effect to depend on window length rather than position. Under a simple model with independent value vectors of variance $\sigma_v^2$, the attention output has variance

$$\mathrm{Var}(o) \approx \sigma_v^2 / N_{\mathrm{eff}}, \qquad N_{\mathrm{eff}} = \exp(H),$$

where $H$ is the average entropy of a query's attention distribution and $N_{\mathrm{eff}}$ is the effective number of tokens attended to. At initialization attention is near uniform, so $N_{\mathrm{eff}} \approx N$, the window length. A curriculum running from 64 to 512 tokens then moves this tensor's scale by about a factor of eight in variance, roughly 1.5 binary exponents, at every transition. As attention sharpens during training, $N_{\mathrm{eff}}$ falls below $N$, so a naive $\sqrt{N}$ correction overshoots.

Separately, Accumulation Bit-Width Scaling shows that the accumulator width needed to avoid "swamping" grows with the number of summed terms. Swamping is the loss of small addends rounded away against a large running sum. The same paper finds the gradient pass is the bottleneck. In attention's backward pass that count scales with $N$.

The claim we test has two parts. The first is that FP8 failures in a length curriculum concentrate at phase transitions and inside attention, and are predicted by $N_{\mathrm{eff}}$ and $N$. The second is that a per-phase static multiplier $\alpha = \sqrt{N_{\mathrm{eff}}}$, recalibrated once at each transition from a few hundred steps of entropy statistics, matches per-step dynamic scaling in quality. Early short phases may additionally tolerate narrower accumulators. We treat that as a secondary, emulation-first question.

Research Program

The model is an LTG-BERT-style encoder trained on the British National Corpus, following Trained on 100 million words and still in shape. That work shows a carefully built encoder trained with span masking and no sentence-level objective reaches GLUE 88.2±0.5 on only 100M words. The modest budget makes a full factorial study affordable.

Three design choices come from prior work. We drop the next-sentence objective because RoBERTa and the BNC study both found it neutral or harmful. We set dropout to zero because Drop Dropout on Single Epoch Language Model Pretraining found it harmful in single-epoch pre-training. We build short-phase inputs by splitting each document into power-of-two chunks, as in Dataset Decomposition. That avoids packing unrelated documents together, which reintroduces the spurious cross-segment relations that next-sentence prediction was criticized for (Cost-effective Selection of Pretraining Data).

The precision recipe is µS-style unit scaling with weights and activations in E4M3 and gradients in E5M2. E4M3 and E5M2 are the two standard FP8 layouts, trading mantissa bits for exponent bits. The curriculum is a geometric schedule from 64 to 512 tokens with constant tokens per step, modeled on GrowLength. We compare it against BERT's original two-phase 128→512 heuristic.

The work proceeds in three steps. First, we instrument every FP8 tensor with three measurements. We log the fractions of values that underflow to zero or saturate. We log the variance retention ratio from the accumulation paper, meaning the variance of a reduced-precision sum divided by its exact-precision variance. We log per-layer attention entropy. Together these show where and when range is lost. Second, we implement the length-aware multiplier on the attention output and on its gradient. Following u-µP, we check whether learning rates tuned at the short phase still hold after rescaling. Third, we emulate reduced-width accumulation in software for the attention and gradient matrix multiplies. This maps the minimum safe accumulator width as a function of $N$. We then ask whether the early phases could run on an FP16-accumulating FP8 instruction of the kind SageAttention2++ uses for inference. That paper bounds quantization scales so sums stay within FP16's ±65,504 range.

Baselines

The naive reference is BF16 training at a fixed 512-token length with standard mixed precision, on the same data, model and token budget. It sets the quality ceiling and the wall-clock floor that every FP8 variant must beat. The BF16 Grow-P2 curriculum is the second reference. It separates the speed gained from the curriculum from the speed gained from FP8.

The strongest existing low-precision method is unit-scaled FP8 with the published static µS multipliers at fixed length 512. The µS authors report it trains 1B–13B decoders at "equal or better quality than standard precision" while running 25–33% faster than BF16 (µnit Scaling). For encoders, the closest reported number is unit-scaled FP16 BERT-Large at SQuAD v1.1 F1 92.14 against a 90.93 baseline (Unit Scaling). No reported result was found on Lacuna for FP8 BERT trained with a length curriculum, nor for any FP8 encoder on BNC.

The most dangerous competitor is per-tensor dynamic scaling in the style of NVIDIA TransformerEngine. It tracks the largest value of each tensor and rescales every step, so it adapts to length changes automatically. µS reports being only 1–6% faster than it.

Fairness rules apply to all variants. Every variant uses identical tokens, tokenizer, architecture, optimizer and step count. Every variant gets the same learning-rate sweep budget: five values, tuned on MLM validation loss at a reduced token budget. We report three seeds. Beating the static-µS baseline means fewer divergences or loss spikes at transitions, plus final MLM loss and GLUE average within seed noise of BF16 while static µS falls outside it. Beating dynamic scaling means matching its quality within noise while removing per-step range tracking, with measured throughput at least equal.

The key ablation applies the plain $\sqrt{N}$ correction, computed from window length alone, instead of the entropy-calibrated $\sqrt{N_{\mathrm{eff}}}$. If the two perform the same, the entropy measurement is unnecessary.

Why not just…?

Why not just use dynamic per-tensor scaling and skip the analysis? This is a real threat. Dynamic scaling may simply absorb length transitions. If it matches BF16 and our method only ties it, the contribution reduces to removing scale tracking, worth at most the small margin µS reports. The decisive comparison is the transition-window loss curve and the GLUE score of dynamic scaling against per-phase static scaling. We will report a tie as a tie. The diagnostic study still has value in that case, because it explains which tensors dynamic scaling is quietly rescuing.

Why not just rely on µS's normalization layers to absorb the scale change? Res-Post-LayerNorm normalizes after the residual addition. The attention-times-values product and its backward pass are computed in FP8 before any normalization, so their range is set before any correction applies. The ablation that applies length-aware scaling only to these tensors tests whether normalization is enough. If the static µS baseline shows no underflow growth across phases, our premise is wrong and we will say so.

Why not just run short phases in FP8 and the long phase in BF16? This hybrid is a sensible engineering fallback, and we include it as a baseline. It forfeits FP8 speed in the phase where attention cost is highest. BERT's original recipe spent only 10% of steps at 512, but the long phase still dominates per-step cost. The hybrid wins if our method cannot keep the 512 phase stable. The wall-clock comparison will show what that costs.

Why not just skip the curriculum, given fast attention kernels? At 512 tokens attention is a modest share of compute, so this alternative is plausible. Against it, Dataset Decomposition reports reaching baseline accuracy 6× faster with >4× better data efficiency, albeit in decoders. The fixed-length FP8 baseline settles whether the gain carries over to encoders at this scale.

Proposed Experiments

The main grid crosses four precision recipes with three schedules: fixed 512, two-phase 128→512, and Grow-P2 from 64 to 512. The precision recipes are BF16, static µS FP8, length-aware FP8, and dynamic-scaled FP8, plus the hybrid as an extra cell.

We evaluate four things. We track MLM validation loss over training, with attention to the 500 steps after each transition. We fine-tune on GLUE, reporting the average plus MNLI and RTE separately, and compare against LTG-BERT's 88.2 as the external anchor. We measure BLiMP zero-shot accuracy for syntax. We fine-tune on SQuAD v2.0 and RACE to probe cross-sentence and longer-range reasoning. That last check matters because the curriculum's short early windows remove much of the cross-sentence exposure that next-sentence prediction was originally meant to supply. We report measured wall-clock throughput on FP8-capable hardware for every cell.

The first decisive check is whether underflow and saturation fractions in static µS rise at each length doubling by roughly the amount the $1/N_{\mathrm{eff}}$ law predicts. If they do not, the core mechanism is absent. The second is whether length-aware static scaling closes the gap to BF16 that static µS leaves, at throughput no worse than dynamic scaling. The third is whether emulated accumulator widths that keep the variance retention ratio near one are measurably narrower at 64–128 tokens than at 512. A gap of at least two bits would justify building a staged-accumulator kernel. A smaller gap would close that line of work.