This document is relevant for: Trn3
Deep dive: MXFP8 weight all-gather with prequantized weight shards#
MXFP8 training normally all-gathers a bf16 weight and then quantizes it inside the GEMM, every step, on every rank. Weight prequantization reverses that order: each rank quantizes only its own shard, so the all-gather moves MXFP8 and the quantization work is divided across the data-parallel group.
Fig. 8 The reordering. Both paths feed the same matmul the same bytes; they differ in whether the quantize happens before or after the all-gather, and therefore in what travels on the wire.#
Before you start#
You must be familiar with the following:
Microscaling (MX) quantization. MXFP8 stores fp8 data plus one 8-bit scale per 32 elements along the matmul contraction axis. See the MX sections of the Trainium 3 architecture guide and MXFP matrix multiplication with NKI.
FSDP weight all-gather. Under FSDP each rank holds one slice of a weight and the slices are all-gathered into the whole matrix before the matmul, then discarded. See SimpleFSDP training.
Note
Throughout this topic, baseline MXFP8 means the non-prequantized path: with
prequantize_weights unset, MXFP8LinearConverter takes its fused path and each linear
becomes a NeuronMXFP8FusedLinear whose forward runs the Neuron fused op. That is the path
the measurements below compare against. Weight prequantization, which swaps in
NeuronMXFP8Linear instead, is an opt-in alternative to it, not a replacement.
Performance with and without weight prequantization#
The table below pairs each dense MXFP8 recipe against itself: identical model, parallelism, batch and activation-checkpointing settings, MXFP8 NKI kernels on both sides, differing only in whether the weight shards are prequantized before the all-gather.
Model |
Parallelism |
Baseline MXFP8 |
Prequantized |
Change |
|---|---|---|---|---|
Qwen3-32B, full AC |
TP4 x FSDP16 |
14.32% |
16.42% |
+14.7% |
Qwen3-14B, full AC |
TP4 x FSDP16 |
12.42% |
13.90% |
+11.9% |
Llama3-8B, selective AC |
TP4 x FSDP16 |
17.62% |
19.40% |
+10.1% |
Qwen3-4B, selective AC |
TP4 x FSDP16 |
12.35% |
12.78% |
+3.5% |
Qwen3-1.7B, full AC |
TP1 x FSDP64 |
11.69% |
11.64% |
-0.4% |
Across the run’s ten paired dense recipes, the median change is +5.9% relative MFU, with a range of -0.6% to +14.7%. Prequantization saves two things. First, each weight gather moves one byte of fp8 plus one 8-bit scale per 32 elements, so 1 + 1/32 = about 1.03 bytes per element instead of 2. Second, each rank quantizes only its own shard rather than the whole gathered weight. Neither saving touches the matmuls, so on Qwen3-1.7B, where the weight gather is a small share of the step, there is no gain to recover.
How the weight is encoded#
MX block scaling groups elements along the contraction axis, and transposing the weight moves that
axis. The forward pass (fprop) reads the weight transposed; the pass that computes the gradient
with respect to the input (dgrad) reads it as stored:
fprop out = x @ W.T contracts in_features -> blocks along "in"
dgrad grad_x = grad_out @ W contracts out_features -> blocks along "out"
One packing cannot serve both, so each weight is encoded twice.
Fig. 9 A local shard [O, I] feeds two encodings, each with its contraction dimension leading.#
The /4 and *4 are the hardware 4x interleave along the contraction axis, unrelated to the
MX block size of 32.
Warning
The two encodings are not transposes of each other. The tempting optimization is to quantize
once and transpose, but no transpose converts [I/4, O*4] into [O/4, I*4]. There are two
genuine quantize calls per linear per step.
A row’s position in the packed buffer depends only on its offset along the contraction axis. So when every rank’s shard is 32-aligned along that axis, the per-rank encodings concatenate into exactly the encoding of the whole gathered tensor, and the prequantized forward is bit-identical to baseline MXFP8 rather than an approximation of it.
Under full AC the backward needs the weight for both the recomputed forward and dgrad. The baseline gathers one bf16 copy, 2 bytes per element, that both read, while prequantization gathers both encodings at about 1.03 bytes each. The backward weight all-gather therefore gets no data reduction, and the saving is forward-only.
When the weight is quantized#
Both encodings must exist when their matmul runs. prequantize_weights enables the path and
selects when they are produced:
Value |
When each encoding is produced |
|---|---|
|
Once per optimizer step, from the local shard, then stored on the module. |
|
Immediately before the all-gather that consumes it. |
Fig. 10 What each option keeps between uses. after_optimizer frees only the gathered copy;
before_gather frees the shard encoding too.#
Both produce the same encodings and move the same bytes through the same collectives, so the
collective saving is the same. after_optimizer keeps both encodings resident for as long as the
model is loaded, 2 * (1 + 1/32) = 2.0625 bytes per weight element per rank. before_gather
frees each encoding with the matmul that read it and rebuilds it on the next use, so under full
activation checkpointing the recomputed forward adds a third quantize call per linear per step.
1D dynamic FSDP: choosing each weight’s shard axis#
Each weight is read once transposed and once as stored, so its shard must be a multiple of 32 along both dimensions. Dimension 0 does not always qualify. Qwen3-32B at TP4 x FSDP16, hidden size 5120, sharded on dimension 0:
Weight |
TP |
Original (out, in) |
After TP4 |
After FSDP16 |
fwd K |
bwd K |
fwd %32 |
bwd %32 |
|---|---|---|---|---|---|---|---|---|
|
col |
(10240, 5120) |
(2560, 5120) |
(160, 5120) |
5120 |
160 |
ok |
ok |
|
row |
(5120, 8192) |
(5120, 2048) |
(320, 2048) |
2048 |
320 |
ok |
ok |
|
col |
(25600, 5120) |
(6400, 5120) |
(400, 5120) |
5120 |
400 |
ok |
fails |
|
col |
(25600, 5120) |
(6400, 5120) |
(400, 5120) |
5120 |
400 |
ok |
fails |
|
row |
(5120, 25600) |
(5120, 6400) |
(320, 6400) |
6400 |
320 |
ok |
ok |
fwd K is the forward contraction length (the shard’s in) and bwd K the dgrad
contraction length (its out). The MLP weights w1 and w3 fail on the backward axis:
400 % 32 = 16. Dimension 0 is unusable for them.
1D dynamic FSDP makes the shard axis a per-parameter choice over a single data-parallel axis.
NeuronMXFP8Linear declares
dp_shard_dim_multiple_of: int = MIN_K # MIN_K = 32
which opts the module out of dim-0 sharding and lets SimpleFSDP choose the dimension.
A dimension qualifies when it is divisible by the FSDP degree times 32, here 16 x 32 = 512. Among
qualifying dimensions SimpleFSDP prefers the one tensor parallel did not split. w1 and w3
therefore shard on dimension 1, giving a local shard of (6400, 320) with contraction lengths
320 and 6400. wqkv moves to dimension 1 for the same reason; wo and w2 keep dimension 0.
Note
A prequantized run and a non-prequantized run of the same model shard differently, so seeded initialization gives them different weights. Compare their loss curves only from a shared checkpoint.
Configuration limits#
SimpleFSDP only. Other data-parallel configurations are future work.
Sharded tensors must be 32-aligned in both contraction dimensions. 1D dynamic FSDP is what holds this on real shapes. Requiring the alignment only on the gathered weight, rather than on every rank’s shard, is future work.
The NKI lowering only, at 1x32, with DMA transpose. Any other
backend_optionsraises. Of the NKI options onlyfused_backwardandlogical_layoutapply. The MLIR lowering is not supported.Dense attention and feed-forward linears, and the routed experts of Qwen3 and DeepSeek-V3. Linear subclasses that set
quantizable_matmulare rejected. GPT-OSS is not supported: its routed experts have no prequantized path and its attention output projection is one of those rejected subclasses. Expert-parallel (neuron_ep) experts are converted to MXFP8 but not prequantized.