Turn on FP8 training¶
FP8 trades some loss-curve noise for a throughput win on Hopper-class GPUs. On this codebase, enabling it is a one-line config change — the interesting questions are whether you should, how to verify it actually ran, and how to read the failure modes. The subsystem reference at Distributed § FP8 covers the internals; this page is the researcher-facing decision and workflow.
Decide whether FP8 is worth it¶
If… |
FP8 is likely to help |
|---|---|
You’re on H100 / H200 |
yes |
You’re on A100 / V100 or older |
no ( |
Model is dense (no MoE) or MoE with heavy attention |
yes |
Model is tiny (dim < ~1024) |
marginal |
You need TP ( |
blocked — see below |
You need the absolute-best eval loss at small step counts |
maybe not — see Accuracy tradeoff |
Where the gain comes from on Hopper: the FSDP2 all-gather moves half
the bytes, and the converted matmuls run as FP8 GEMMs, whose peak is
twice the bf16 peak. How much of that reaches end-to-end throughput
depends on the model and batch shape, so compare tok/s against a bf16
run of the same config; the logged MFU uses the bf16 peak for both
(MFU § FP8 caveat). No FP8
throughput measurement has been published for this repo yet;
Reference § Benchmarks covers bf16 runs
only.
Turn it on¶
One field in [train]:
[train]
mixed_precision = "fp8"
That’s the whole surface. build_model picks it up via
TrainConfig.is_fp8,
build_parallel_model calls apply_float8(model) after TP/EP and
before AC/FSDP2, and the master weights stay bf16, or fp32 with
fp32_master_weights = true (FP8 is a compute dtype only). No per-layer knobs.
Reference config¶
configs/train/7b_16gpu_fp8.toml
is the 7B Llama-3 FP8 recipe for 16 GPUs (4 nodes of 4):
[train]
mixed_precision = "fp8"
batch_size = 8 # larger M-dim → better TC saturation
grad_accum_steps = 2 # keep effective batch matched
activation_checkpointing = "full" # full AC; selective OOMs at bs=8
compile_model = true # torch.compile pairs well with FP8
[distributed]
dp_shard = -1 # FSDP over all 16 ranks
# tp is absent → defaults to 1 (TP is not allowed with FP8)
The config header has the tuning rationale: doubling batch_size to
saturate the M-dimension of the Float8 GEMM is what actually extracts
the FP8 speedup, and full AC is needed at that batch size or MLP
activations OOM.
Compatibility matrix¶
Pairing |
Works? |
Notes |
|---|---|---|
FP8 + FSDP2 |
yes |
Primary path. |
FP8 + TP |
no |
Config validation rejects this; see |
FP8 + EP |
yes |
Experts and the router are excluded from FP8 conversion; attention and dense blocks still use FP8. |
FP8 + |
yes |
Recommended combination. |
FP8 + PP |
yes |
PP stages compose with FP8 the same way as bf16. |
The TP block is explicit and hard:
FP8 + Tensor Parallelism is not yet supported (torchao Float8Linear
does not compose with DTensor sharding). Use FP8 with FSDP only, or
TP without FP8.
Verify it’s actually running¶
FP8 failures are silent by default — a misconfigured run still trains in bf16 and produces sensible loss curves. Check the rank-0 log at startup:
Applied Float8 training: recipe=TENSORWISE, fsdp_float8_all_gather=True, converted 225 of 225 Linear layers
Optimizer groups: ...
Model: ...
The Applied Float8 training line (from
apply_float8)
is the confirmation, and its count says how many Linear layers run in
FP8 (225 of 225 for 7b_16gpu_fp8.toml). If it’s missing,
mixed_precision didn’t resolve to "fp8". A layer with a dimension
that is not a multiple of 16 stays in bf16, and a warning right after
names it (under pipeline parallelism, the line and the warning cover
rank 0’s stage only). For configs/train/hf_wikitext.toml, whose GPT-2
vocabulary has 50257 tokens:
Applied Float8 training: recipe=TENSORWISE, fsdp_float8_all_gather=True, converted 56 of 57 Linear layers
Float8 kept 1 Linear layer(s) in high precision because torch._scaled_mm needs both dimensions divisible by 16: output_head.proj (50257x512) x1
For a deeper check, profile one step:
[profiling]
enable = true
start_step = 10
end_step = 12
trace_dir = "profiler_traces/fp8_check"
The summary table should list kernels whose names contain scaled_mm
(the FP8 GEMM) rather than only gemm / cutlass_bf16. See
Debug § Shape 4
for how to read the summary.
What gets converted, what doesn’t¶
Pulled from the filter in
apply_float8:
Converted: attention (
q/k/v/o_proj), dense MLP (gate/up/down_proj), finaloutput_head.proj.Excluded: routed MoE experts (
experts.*) because they usetorch._grouped_mmand bypassFloat8Linear.forward; the shared expert (shared_expert.*), a plainLinearcall, by convention to match them; the MoE router because its output dim is small and not compute-bound; embeddings and norms because they aren’tnn.Linear.Kept in bf16: a layer from the converted list whose
in_featuresorout_featuresis not a multiple of 16, whichtorch._scaled_mmrejects. The startup warning names each one with its shape.
For an MoE model this means attention, dense-block MLPs and the output head are FP8, but the routed and shared experts run in bf16, so FP8 speeds up only the FLOPs outside the experts (see MoE FP8).
Accuracy tradeoff¶
Tensorwise FP8 has a measurable early-step loss-curve divergence from bf16 — usually within noise by step ~1000 but visible before. Three operating patterns:
All-FP8. Cheapest. Accept the early-step noise. Fine for most long runs.
bf16 warmup → FP8 body. Start with
mixed_precision = "bf16"for the LR warmup phase, resume withmixed_precision = "fp8"for the bulk of training. Not automated — you checkpoint and relaunch with the new flag.FP8 body → bf16 cooldown. Only worth it when you need the last fraction of loss improvement for a final eval.
The codebase doesn’t automate any of these — they’re all checkpoint-and-relaunch patterns.
Troubleshooting¶
“Applied Float8 training” missing from log, training still runs.
mixed_precision is wrong. Check
config.train.mixed_precision == "fp8" (not "FP8" or "float8").
The Literal[...] type in the dataclass lets only four values through.
Float8 kept N Linear layer(s) in high precision warning. The
named layers have a dimension that is not a multiple of 16, so they
train in bf16 while the rest of the model runs in FP8. To run them in
FP8 as well, make the dimension a multiple of 16: pad vocab_size
(50272 instead of GPT-2’s 50257), raise n_kv_heads so that
n_kv_heads * head_dim is a multiple of 16, or pick an
ffn_hidden_dim that is.
ValueError: train.mixed_precision='fp8' needs model.dim divisible by 16.
Every projection and the output head has model.dim on one side, so
with this dim no layer could run in FP8. Use a dim that is a
multiple of 16, or train in bf16.
ValueError: train.mixed_precision='fp8' needs train.batch_size * train.seq_len divisible by 16.
The FP8 weight gradient multiplies over the micro-batch’s tokens, so
the first backward would fail. Pick a batch_size or seq_len that
makes the product a multiple of 16; a seq_len that is one works with
any batch_size. VLM runs skip this check because their token counts
depend on the data; there the symptom is an error in the first backward
such as Expected trailing dimension of mat1 to be divisible by 16 but got mat1 shape: (<out_features>x<tokens>). A packed VLM run
(data.pack_sequences = true) is refused with FP8 when JobConfig is
built.
ValueError: Float8 converted 0 of N Linear layers. Every Linear
is either excluded by name or has a dimension that is not a multiple of
16, so the run would train entirely in bf16. The message names the
layers the shape check kept; make those dimensions multiples of 16, or
train in bf16.
ValueError: FP8 + Tensor Parallelism is not yet supported. The
config validator ran. Either set distributed.tp = 1 (and let FSDP
handle sharding) or drop mixed_precision = "fp8".
RuntimeError: torch._scaled_mm is only supported on CUDA devices with compute capability >= 9.0 or 8.9 in the first step.
The GPU is older than FP8 support (an A100 or older). FP8 does not fall
back to bf16 matmuls there; train with mixed_precision = "bf16" on
this cluster.
aten.is_pinned DTensor error at model build. apply_float8 was
called on a model with tensor-parallel weights outside the config path;
the config check rejects FP8 with tp > 1. Build with tp = 1, or
train without FP8.
Loss diverges in the first ~50 steps. Expected early-step noise
is subtle; an actual divergence usually means the LR is set for
bf16-master-weight assumptions but FP8 is amplifying gradient noise.
Start with a smaller lr or a longer scheduler.warmup_steps and
check train/grad_norm — see
Debug § Shape 1.
OOM on the first FP8 step but not on bf16. FP8 all-gather saves
bandwidth but not memory; matmul temporaries for _scaled_mm are
slightly larger than bf16 matmul. Drop batch_size or switch to
activation_checkpointing = "full".
See also¶
Distributed § FP8 — full reference on what
apply_float8does, the E4M3/E5M2 math, and master weight handling.Distributed § FSDP2 § Mixed precision policy — how FSDP2 sees FP8 (as bf16 with attached scale tensors).
Architecture § Parallelism order — why FP8 runs between EP and AC.
Configuration § Validation rules — the
FP8 + TPcheck.Debug training regressions — the profiler workflow to verify FP8 kernels are firing.
configs/train/7b_16gpu_fp8.toml— the reference recipe this page points at.