Ensuring Causality in MXFP8 Attention
Causal MXFP8 attention kernels for training and inference

While evaluating different recipes for lower-precision training (particularly block scaled quantization schemes), we noticed that quantization is only applied in the attention projections and FFN/MoE layers, while the core attention operation is usually kept in higher precision, such as BF16. We wanted to understand what it would take to run attention itself in MXFP8.
In block scale quantization schemes, a scale is shared amongst multiple values. For example, in MXFP8, a power-of-two scale is shared amongst 32 contiguous values. We show how this property is the reason for a subtle leak in block scale quantization attention like MXFP8 attention and how we fixed it.
Causal self-attention computes two matrix products. NVIDIA’s cuDNN guide calls them BMM1 and BMM2. In each, MXFP8 groups values along the dimension the product sums over.
- BMM1 computes the attention scores. Each entry in QKᵀ is a dot product between one query and one key. The sum runs over features, so each scale covers 32 features within a single token. We then apply the causal mask and softmax to obtain the attention weights P.
- BMM2 computes the output. Each entry in PV is a weighted sum over token positions. The weights in each row of P sum to one and can be quantized with a fixed scale. For V, the kernel selects a scale for each feature from values at 32 consecutive positions. In BMM2, the reduction dimension for V is along the rows, and hence the scales are calculated along the token dimension.
Figure 1 shows the grouping directions described in NVIDIA’s cuDNN scaling guide. For a token-by-feature matrix of shape S × D, Q and K have scale tensors of shape S × (D/32). V instead has a scale tensor of shape (S/32) × D: each 32-token block shares a row of D scales, one per feature.
The scale tensor follows the grouping direction
Illustrated with S = 64 tokens and D = 64 features. Each scale applies to 32 elements.
BMM1: Q and K
One token: two 32-feature groups → two scales.
Q and K scales: S × (D/32)
BMM2: V
32 tokens × all D features → one row of D scales.
V scales: (S/32) × D
Q and K scales: S × (D/32), one scale per 32 features of a token. V scales: (S/32) × D, one row of D scales per 32-token block.
| Operand | Grouping | Scale tensor shape |
|---|---|---|
| Q (BMM1) | 32 features within one token | S × (D/32) |
| K (BMM1) | 32 features within one token | S × (D/32) |
| V (BMM2) | 32 tokens within one feature | (S/32) × D |
How a masked token changes an earlier output
For BMM2, a causal mask on P is not enough when visible and future values share a quantization scale. A future value can change that scale and alter how a visible value is rounded. Its attention weight is zero, but it can still influence an earlier output through quantization.
Consider query 47, using zero-based positions. It can read values 0 to 47, but each V scale in its block is selected from positions 32 to 63, including future positions 48 to 63. Each value channel has its own scale.
A large future value at position 55 can raise that scale and change the represented value at position 32. Query 47 reads the changed value even though position 55 has zero attention weight.
The animation below follows this dependency through PV: token 55 changes a shared V scale, visible token 32 can round differently, and output row 47 can change even though the future weight stays zero.
How a shared V scale can leak future information
Each 32-token V block has a 1 × D row of scales.
How a shared V scale can leak future information. Each 32-token V block has a 1 × D row of scales. Row 47 of P reads only tokens 0-47. But the V scale for block 32-63 also uses future tokens. A large value at token 55 can change that shared scale. The new scale can change how visible token 32 is rounded. P reads the changed value, so output 47 can change.
| Step | What happens |
|---|---|
| 1 | Each 32-token V block has a 1 × D row of scales. |
| 2 | Row 47 of P reads only tokens 0-47. |
| 3 | But the V scale for block 32-63 also uses future tokens. |
| 4 | A large value at token 55 can change that shared scale. |
| 5 | The new scale can change how visible token 32 is rounded. |
| 6 | P reads the changed value, so output 47 can change. |
MatX demonstrated this issue in MXFP4 attention and proposed a correction - keep the blocks that are fully visible to a query quantized, and compute the block crossing the causal mask without quantization. This restores causality by removing the shared-scale dependency on future tokens at that boundary.
We build on their approach for MXFP8 attention. Our approach keeps the boundary matrix product in native MXFP8 too, so both forward attention matrix products can use MXFP8 during training and prefill.
Fix the boundary, preserve the bulk
Figure 2 shows the 32-token MXFP8 scaling groups for query 47. Positions 0 to 31 form a fully visible block, and positions 64 onward are masked. We call the computation over fully visible blocks the bulk path. Only the boundary block, positions 32 to 63, contains both visible and future tokens and needs special handling.
Only the boundary block needs special handling
Each outlined block spans 32 token positions, matching MXFP8’s V scaling groups. Query 47 can attend to positions 0 to 47. Indexing starts at zero.
Bulk MXFP8
Every token in this block is visible. Its V scales consult no future tokens.
Boundary correction
The block contains visible and future tokens. Use token-local scales folded into P.
Zero attention weight
All positions in this block are masked. They contribute nothing to query 47.
The boundary is one 32-token block per query. All earlier complete blocks retain the bulk MXFP8 path.
Query 47 attends to positions 0 to 47. Positions 0 to 31 form a complete block on the bulk MXFP8 path. Positions 32 to 63 form the boundary block, with 32 to 47 visible and 48 to 63 future. Positions 64 onward are masked.
| Positions | Block | Path for query 47 |
|---|---|---|
| 0 to 31 | Complete block, fully visible | Bulk MXFP8 |
| 32 to 63 | Boundary block: 32 to 47 visible, 48 to 63 future | Boundary correction |
| 64 onward | Masked | Zero attention weight |
Move the scale into P
The first step is to normalize each value vector using a scale computed only from that token. In PV, each output feature sums over token positions: Oᵢₖ = ∑ⱼ PᵢⱼVⱼₖ, where i indexes query tokens, j indexes value tokens, and k indexes features. Native MXFP8 groups V along this reduction direction, sharing one scale across 32 tokens for each feature. At the boundary, future tokens can therefore change the scale used to represent visible values, even though their attention weights are zero.
We instead compute a scale sⱼ from each token’s own value vector Vⱼ and write Vⱼ = sⱼUⱼ. These token-local scales do not match V’s native scaling layout across 32 tokens. We absorb these scales into the corresponding columns of P, defining P̃ᵢⱼ = Pᵢⱼsⱼ, so that PV = P̃U.
Pᵢⱼ × (sⱼUⱼ) = (Pᵢⱼsⱼ) × Uⱼ
The hardware still groups U across 32 tokens, but its scale is a fixed constant, so future values cannot change how visible values are represented. Each scale sⱼ is carried by its corresponding weight in P. We mask future entries before selecting scales for these folded weights, so their contributing scales use only visible entries. Softmax normalization still uses the original weights. The identity is exact before folded-weight rounding; quantization error remains.
The animation below shows the boundary correction: normalize each token’s values, fold its scale into P, and use a fixed hardware scale for U. Complete blocks retain the bulk MXFP8 path.
Our fix: move token-local scales into P
Complete block: 1 × D shared scales. Boundary: 32 × 1 token-local scales.
Our fix: move token-local scales into P. Complete block: 1 × D shared scales. Boundary: 32 × 1 token-local scales. Give each boundary token its own scale: Vⱼ = sⱼUⱼ. Normalized U uses a fixed hardware scale across the 32-token groups. Move each scale sⱼ into its matching column of P. Mask future entries before choosing the folded P scales. Compute both paths in MXFP8 and merge using softmax statistics.
| Step | What happens |
|---|---|
| 1 | Complete block: 1 × D shared scales. Boundary: 32 × 1 token-local scales. |
| 2 | Give each boundary token its own scale: Vⱼ = sⱼUⱼ. |
| 3 | Normalized U uses a fixed hardware scale across the 32-token groups. |
| 4 | Move each scale sⱼ into its matching column of P. |
| 5 | Mask future entries before choosing the folded P scales. |
| 6 | Compute both paths in MXFP8 and merge using softmax statistics. |
We merge this partial result with the fully visible blocks using their softmax normalization statistics. Boundary arithmetic grows linearly with sequence length, while the quadratic bulk retains the optimized path. The custom preparation path explained above and merging add overhead that needs to be measured.
One thing to note here is that not every scale change alters rounding. Power-of-two shifts can preserve normal FP8 values. Small values near zero are most vulnerable, where a shift can reduce their precision in the subnormal range and round them to zero.
Training faster with less memory
Our kernel uses native MXFP8 for both forward attention products. We add support for training through a BF16 surrogate backward pass using dequantized operands. Our backward pass dequantizes the saved Q, K, and V representations to BF16 and computes attention gradients in BF16. This avoids introducing new quantization scales shared across tokens, preserving causality through the backward pass.
We compare our training recipe on 16 B200 GPUs on Qwen3-4B with 2 other variants:
- [Baseline] Transformer Engine’s BF16 attention
- [Stock MXFP8] Transformer Engine’s cuDNN MXFP8 attention which causes future token leakage in both forward and backward
To keep the comparisons fair, we only change the attention path, while keeping the other parts in BF16 for all the variants.
Our training recipe makes the following improvements:
- It removes future-token leakage from both forward and backward
- At 4K, our implementation is 2.1% slower than BF16. MXFP8 quantization itself adds overhead. At the same time, our preparation and merging steps also add overhead. These overheads are dominant at smaller context lengths and at larger context lengths, these costs get amortized.
- At 32K context length, our recipe delivers 4.9% higher training throughput and 5.2% lower peak memory than BF16 attention baseline. It also delivers 1.8% higher throughput than stock MXFP8 attention while removing the future-token dependency
Qwen3-4B training on 16 B200 GPUs
32K context, throughput
+4.9% against Baseline
32K context, peak memory
-5.2% against Baseline
4K context, throughput
-2.1% against Baseline
4K context, peak memory
+1.2% against Baseline
Qwen3-4B training on 16 B200 GPUs. 32K context, throughput: Baseline 16805, Stock MXFP8 17313, Causal MXFP8 (Sarvam) 17624 (+4.9%). 32K context, peak memory: Baseline 124.9, Stock MXFP8 125.4, Causal MXFP8 (Sarvam) 118.4 (-5.2%). 4K context, throughput: Baseline 33398, Stock MXFP8 33056, Causal MXFP8 (Sarvam) 32702 (-2.1%). 4K context, peak memory: Baseline 110, Stock MXFP8 110.3, Causal MXFP8 (Sarvam) 111.3 (+1.2%).
| Panel | Baseline | Stock MXFP8 | Causal MXFP8 (Sarvam) | Sarvam against Baseline |
|---|---|---|---|---|
| 32K context, throughput | 16,805 | 17,313 | 17,624 | +4.9% |
| 32K context, peak memory | 124.9 | 125.4 | 118.4 | -5.2% |
| 4K context, throughput | 33,398 | 33,056 | 32,702 | -2.1% |
| 4K context, peak memory | 110.0 | 110.3 | 111.3 | +1.2% |
Decoding
We also extend our support of causal MXFP8 attention to inference. In inference, we have two parts - prefill and decoding. Prefill uses the same kernel trick described in previous sections (similar to forward kernels in training).
During decoding, we extend vLLM’s paged KV cache to store keys and values in MXFP8. Each step computes attention over the cached history in MXFP8 and handles the current token’s self-attention separately in BF16. We merge these partial results using their softmax normalization statistics to produce the attention output.
After reading the existing cache, we append the current token’s key and value for subsequent steps. For V, each feature shares a scale across a 32-token block. If the new value exceeds that scale’s range, we increase the scale and rescale the previously stored values for that feature within the open block. These updates affect only subsequent queries and output.
We compare with vLLM’s FP8 KV-cache paths on one B200, using BF16 weights and projections, one request at a time (batch size 1), and 128 generated tokens. Both baselines use FP8 caches with fixed per-tensor KV scales of 1.0; their attention computation is either BF16 or FP8. Ours uses data-dependent MXFP8 block scales.
Single-request decode throughput on one B200
Qwen3-4B
Qwen3-14B
Single-request decode throughput on one B200. Qwen3-4B: 4K context, Baseline 345.7, FP8 attention 331.0, Causal MXFP8 (Sarvam) 363.7 tokens a second (+5.2%). 8K context, Baseline 312.8, FP8 attention 327.3, Causal MXFP8 (Sarvam) 345.5 tokens a second (+10.5%). 16K context, Baseline 298.5, FP8 attention 315.0, Causal MXFP8 (Sarvam) 334.0 tokens a second (+11.9%). 32K context, Baseline 272.1, FP8 attention 300.7, Causal MXFP8 (Sarvam) 312.2 tokens a second (+14.7%). Qwen3-14B: 4K context, Baseline 158.7, FP8 attention 164.1, Causal MXFP8 (Sarvam) 164.9 tokens a second (+3.9%). 8K context, Baseline 158.6, FP8 attention 161.3, Causal MXFP8 (Sarvam) 165.4 tokens a second (+4.3%). 16K context, Baseline 150.9, FP8 attention 158.0, Causal MXFP8 (Sarvam) 164.7 tokens a second (+9.1%). 32K context, Baseline 144.3, FP8 attention 153.3, Causal MXFP8 (Sarvam) 155.6 tokens a second (+7.8%).
| Model | Context | Baseline: BF16 attention, FP8 cache (tok/s) | FP8 attention, FP8 cache (tok/s) | Causal MXFP8 (Sarvam) (tok/s) | Sarvam against Baseline |
|---|---|---|---|---|---|
| Qwen3-4B | 4K | 345.7 | 331.0 | 363.7 | +5.2% |
| Qwen3-4B | 8K | 312.8 | 327.3 | 345.5 | +10.5% |
| Qwen3-4B | 16K | 298.5 | 315.0 | 334.0 | +11.9% |
| Qwen3-4B | 32K | 272.1 | 300.7 | 312.2 | +14.7% |
| Qwen3-14B | 4K | 158.7 | 164.1 | 164.9 | +3.9% |
| Qwen3-14B | 8K | 158.6 | 161.3 | 165.4 | +4.3% |
| Qwen3-14B | 16K | 150.9 | 158.0 | 164.7 | +9.1% |
| Qwen3-14B | 32K | 144.3 | 153.3 | 155.6 | +7.8% |
Across 4K to 32K contexts, our single-request Qwen3-4B decode throughput is 3.8 to 9.9% higher than vLLM’s FP8-attention and FP8-cache path. Qwen3-14B is broadly comparable, with measured gains of 0.5 to 4.2%; only the 16K gain exceeds the ~3% run-to-run variation.
Implications for training and inference
A causal mask protects one matrix. In block-scaled attention the leak comes through the matrix it is multiplied with, by way of a shared scale the mask never touches. Causality has to hold in the quantization that prepares the operands too.
Our kernels close that gap in three places.
- Causal MXFP8 attention for the forward pass and prefill
- A BF16 surrogate backward pass that adds no scale shared across tokens
- An MXFP8 paged KV cache for decoding
Together they keep attention in MXFP8 for long-context training and inference without the leak. At 32K context on Qwen3-4B, training throughput is 4.9% higher than with BF16 attention and peak memory is 5.2% lower.
We have contributed our work in leading open source projects:
Read More
Curious what else we're building? Explore our APIs and start creating.
Curious what else we're building?
Explore our APIs and start creating.


