Sarvam Fixes a Hidden Bug That Let Future Tokens Corrupt AI Memory
Sarvam's new kernel runs attention natively in MXFP8 without letting future tokens leak into earlier predictions, hitting 4.9% faster training at 32K context.
Takeaways
- Sarvam released a kernel making MXFP8 attention causality-safe during training and prefill, now merged into cuDNN, Transformer Engine, and vLLM.
- Stock MXFP8 attention leaks future information because 32-token V blocks share a quantization scale the causal mask does not cover.
- The fix handles only the boundary block specially, folding token-local scales into P while keeping both matmuls in native MXFP8.
- Training Qwen3-4B at 32K context on 16 B200s runs 4.9% faster and uses 5.2% less peak memory than BF16.
- Single-request Qwen3-4B decode on B200 is 5.2 to 14.7% faster than BF16 attention from 4K to 32K context.
- Paper and blog detail the causality tests and benchmarks: arXiv preprint.
Sarvam has published an MXFP8 attention kernel that prevents future tokens from influencing earlier outputs through shared quantization scales. Many transformer components already use FP8 or FP4, including projection layers, feed-forward networks, mixture-of-experts routing, and KV caches. Attention has proved harder to quantize safely because block scaling can introduce dependencies that the causal mask does not remove.
The release combines a paper, an implementation, and proposed integrations with widely used training and inference libraries:
Because the library integrations are pull requests, developers should verify merge status, release versions, hardware requirements, and supported configurations before relying on the kernel in production.
How future tokens change earlier values
MXFP8, or microscaling FP8, stores low-precision values in blocks of 32 and assigns each block a shared power-of-two scale. The scale determines the range and precision available to every value in that block. A large value can therefore alter how the other 31 values are represented.
Attention forms a probability matrix P from queries Q and keys K, then multiplies P by the value matrix V. In the PV product, MXFP8 can group a feature across 32 token positions in V. The shared scale is consequently derived along the token dimension.
A causal mask sets the attention weights for future positions to zero, but it does not remove those positions from the scale calculation for V. If one scale block covers positions 32 through 63, a large value at position 55 can change the quantized representation at position 32. A query at position 47 can read that changed value even though its attention weight for position 55 is zero.
Sarvam tested this dependency with Qwen3-4B-Base at a 32K context length. The test compared next-token top-1 predictions produced from a full sequence with predictions produced from the corresponding prefix. Lower disagreement indicates stronger causal consistency.
| Attention path | One disagreement per |
|---|---|
| Stock MXFP8 | 240 predictions |
| Sarvam causal MXFP8 | 4,800 predictions |
| BF16 baseline | 6,700 predictions |
One mixed block needs repair
Each query divides the value matrix into three regions. Earlier 32-token blocks contain only visible positions, later blocks are fully masked, and one boundary block can contain both visible and future positions. Only that mixed block can carry a future-token dependency through its shared scale.
Sarvam normalizes each value vector in the boundary block using a scale computed from that token alone. It then folds the token’s scale into the corresponding column of the attention matrix. The transformation follows the identity Pij × (sjUj) = (Pijsj) × Uj, preserving the underlying product while changing where scaling occurs.
Once the token-specific scales move into P, the normalized values U can use a fixed shared scale across the 32-token block. Future values can no longer change the representation of visible values. The kernel also masks future entries before selecting scales for the folded attention weights. This keeps the boundary computation in native MXFP8; earlier MXFP4 work from MatX handled the boundary at higher precision.
Forward, backward, and decode paths
The implementation covers the main attention stages used during training and serving:
- Forward and prefill: Causal MXFP8 attention handles training forward passes and inference prefill, when the prompt tokens are processed together.
- Backward: A BF16 surrogate backward pass dequantizes saved
Q,K, andVtensors without introducing additional shared scales. - Decode: An MXFP8 paged KV cache supports vLLM’s token-by-token decoding and dynamically rescales a block when appended values exceed its current range.
Long contexts absorb the setup costs
Sarvam benchmarked training on 16 NVIDIA B200 GPUs with Qwen3-4B, changing only the attention path. At 32K context, causal MXFP8 delivered 4.9% higher training throughput and 5.2% lower peak memory than the BF16 attention baseline. It also ran 1.8% faster than stock MXFP8 while removing the measured future-token dependency.
At 4K context, the implementation ran 2.1% slower than BF16. Quantization, boundary preparation, and result merging impose fixed costs that shorter sequences cannot amortize as effectively, making the current kernel better suited to long-context workloads.
A separate decode benchmark used Qwen3-4B on one B200 at batch size 1. The causal MXFP8 path outperformed the BF16-attention baseline at every tested context length, with the gap increasing from 5.2% at 4K to 14.7% at 32K.
| Context | BF16 attention, FP8 cache | vLLM FP8 attention, FP8 cache | Causal MXFP8 | Gain over BF16 |
|---|---|---|---|---|
| 4K | 345.7 | 331.0 | 363.7 | 5.2% |
| 8K | 312.8 | 327.3 | 345.5 | 10.5% |
| 16K | 298.5 | 315.0 | 334.0 | 11.9% |
| 32K | 272.1 | 300.7 | 312.2 | 14.7% |
The Qwen3-14B results were narrower, ranging from 0.5% to 4.2% over vLLM’s FP8 path. Sarvam reports that only the 16K result clearly exceeded run-to-run variation.
The scale must obey the mask
A causal mask controls which values receive nonzero attention weights. It cannot remove a dependency already embedded in the quantized representation of V. Any block-scaled format that shares scales along the token dimension must therefore calculate those scales within the same visibility boundary enforced by the mask.
Developers evaluating the implementation have several practical considerations:
- Training: The Transformer Engine and cuDNN pull requests provide the proposed integration path for long-context workloads.
- Serving: The vLLM pull request combines causal MXFP8 attention with a paged, dynamically rescaled KV cache.
- Short contexts: The reported 4K training result favors BF16, so workload-specific benchmarking remains necessary.
- Validation: Comparing full-sequence predictions with prefix-only predictions provides a direct test for future-token dependence.
The published results cover Qwen3-4B and Qwen3-14B on B200 GPUs under the listed configurations. They do not establish performance on other accelerators, larger batches, different model families, full training convergence, or downstream task quality. The top-1 consistency test measures causal dependence specifically, so adopters should also test loss, accuracy, memory use, and end-to-end latency on their own workloads.