Skip to main content
A common failure mode in MoE RL is precision drift between training and inference. Pipelines that train in BF16 and serve in FP8 accumulate per-layer numerical disagreement, which compounds into divergent log-probabilities and gradients pointing in unintended directions. Miles supports a unified low-precision path where rollout and training share the same quantization logic on the forward pass. The same path is wired up for three formats today — block-wise FP8, MXFP8, and NVFP4 — plus the lower-friction “BF16 train + FP8 inference” mode that’s useful when standing up a new model architecture.

Choose a precision

MXFP4 is not a standalone choice: rollout uses it only for the routed experts of releases that ship them in MXFP4 (mode 5).

Rollout × training compatibility

Each row is a rollout (inference) precision; each column is the trainer’s forward precision. ✅ = supported; ✗ = not supported. The reference script (scripts/run_qwen3_30b_a3b.py) allows only one rollout precision and one training precision at a time. Use paired rollout and training flags for the end-to-end MXFP8 and NVFP4 recipes below. MXFP4 rollout keeps the weights other than the routed experts in block-wise FP8.

Unified training recipe

The precision contract covers checkpoint conversion, the trainer forward pass, SGLang rollout, and live weight export. High-precision tensor exceptions must match across all four stages.

Modes

1. BF16 train + FP8 inference

The lowest-friction path. SGLang loads FP8 weights while the trainer keeps a BF16 torch_dist checkpoint. There is precision drift between the two paths; on MoE workloads, pair this with R3 (and optionally TIS).
Reference recipe: examples/infra_features/low_precision/run-qwen3-4b-fp8.sh — single-node Qwen3-4B. It serves an FP8 checkpoint to SGLang and trains from a BF16 torch_dist checkpoint; it sets no --fp8-recipe, so the trainer forward stays BF16.

2. Unified block-wise FP8 (DeepSeek-style)

Rollout and training share the same block-wise FP8 quantization. This is the recipe to use on Hopper, and the layout DeepSeek ships its FP8 checkpoints in. Block layout is 128×128 with FP32 scales.
NVTE_FP8_BLOCK_SCALING_FP32_SCALES is set for you in the actor env (miles/ray/train/actor_factory.py), defaulting by hardware: 1 on Hopper, and 0 on Blackwell, where TransformerEngine emulates the block-wise recipe with MXFP8 and needs power-of-two scales. Override it only if you know you want the non-default for your GPU. For models that already ship 128×128 block-wise FP8 weights (DeepSeek-V3.2, Qwen/Qwen3-30B-A3B-FP8), point --hf-checkpoint at the block-wise FP8 directory and let SGLang autodetect. Otherwise convert with tools/convert_hf_to_fp8.py. For MoE workloads, also consider --use-rollout-routing-replay (R3). The canonical recipe leaves it commented out by default but the flag is available. Reference recipe: examples/infra_features/low_precision/run-qwen3-30b-a3b-fp8-two-nodes.sh — two-node Qwen3-30B-A3B.

3. Unified MXFP8 (Blackwell)

MXFP8 uses one-dimensional microscaling blocks: 32 consecutive E4M3 values share one UE8M0 scale. The end-to-end recipe uses MXFP8 for rollout, forward propagation, weight-gradient GEMMs, and data-gradient GEMMs while preserving configured tensors in BF16. End-to-end MXFP8 RL recipe Hardware: B200, B300, GB200, or GB300. The Qwen3-30B-A3B launcher prepares the MXFP8 Hugging Face checkpoint and configures both sides of the RL loop:
The training path uses:
SGLang selects the MoE and dense linear GEMM backends independently. Common MXFP8 choices are: Choose the pair that matches the model, parallel layout, and installed SGLang stack. Convert a checkpoint outside the launcher with:
The converter records a 1x32 weight block and UE8M0 scale layout. It excludes norms, embeddings, routers, and configured high-precision tensors. Low-precision parameter gather is not enabled in the reference recipe, so a higher-precision master weight copy remains present during training.

4. NVFP4 (Blackwell)

NVFP4 stores E2M1 values in 16-value blocks with an E4M3 scale for each block and an outer FP32 scale. The Miles reference recipe combines NVFP4 and BF16 through tensor-level precision configuration. Activation scaling is computed per token. Gate and up projections are quantized together so the fused rollout GEMM uses the same outer weight scale. The trainer, checkpoint converter, and rollout kernels must use the same scaling contract. Hardware: B200, B300, GB200, or GB300. Run the Qwen3-30B-A3B reference recipe with paired rollout and training flags:
The launcher selects per-token activation scaling, disables the incompatible 2D quantization, RHT, and stochastic-rounding paths, and loads the matching tensor-level precision configuration. NVFP4 applies only to the routed-expert FC1 and FC2 GEMMs; shared experts and all other unmatched tensors stay in BF16 across checkpoint conversion, training, and live weight export. Rollout uses a BF16 KV cache. The training path uses:
Note the --fp4- prefix: NVFP4 has its own format and recipe flags rather than reusing the --fp8- pair. The launcher also adds --optimizer-cpu-offload --overlap-cpu-optimizer-d2h-h2d --use-precision-aware-optimizer. The base NVFP4 recipe uses high-precision backward: the forward pass uses NVFP4 while the BF16 backward GEMMs consume the original BF16 operands. NVFP4 with high-precision backward The base recipe settings used by the launcher are:
Convert a checkpoint outside the launcher with the same NVTE_* recipe environment:
Checkpoint conversion and live weight export quantize only routed experts in the main language decoder. MTP weights (including appended decoder layers), vision/audio components, shared experts, and dense layers keep their source precision. The HF converter uses the language num_hidden_layers from text_config when present, otherwise the top-level config, and recognizes model.layers, language_model.model.layers, model.language_model.layers, and language_model.layers. First/last-layer BF16 controls apply to those language layers. Unsupported namespaces remain unquantized. Training-time precision is still controlled separately by --te-precision-config-file.

Advanced: dequantized backward

Dequantized backward keeps the backward GEMMs in BF16 but uses BF16 dequantizations of the NVFP4 operands produced during the forward pass. See the humans& discussion of gradient stability for the motivation and ablations. NVFP4 with dequantized backward Select this mode in the environment used to launch the job:

Advanced: four-over-six

Four Over Six: More Accurate NVFP4 Quantization with Adaptive Block Scaling optionally chooses, for each NVFP4 block, whether mapping the largest FP4 magnitude to 4 or 6 produces less quantization error. See the humans& four-over-six analysis for the RL recipe discussion. An example setting is:

5. MXFP4 routed experts (Blackwell)

DeepSeek-V4 and Kimi K3 release their routed experts in MXFP4 — E2M1 values in 32-value blocks with one UE8M0 scale per block — and keep their other weights in higher precision. Both reach these weights through MXFP4 quantization-aware training (QAT) in post-training (DeepSeek-V4, Kimi K3). Miles implements this for DeepSeek-V4 by changing only the routed experts on top of FP8 training and rollout. In rollout, the routed experts run MXFP4 weights × MXFP8 activations (W4A8), as in the release. Three DeepSeek-V4 configurations change one thing at a time: The first and last align the routed experts between training and rollout. The second serves the MXFP4 experts without QAT, so the routed experts carry a train–rollout mismatch, as in mode 1. In all three, the other layers use the MXFP8 recipe in training and block-wise FP8 in rollout. MXFP4 QAT. Training has no MXFP4 GEMM. On the first microbatch of each forward-backward pass, the trainer rounds the routed-expert BF16 weights onto the MXFP4 grid in place, with the block layout and rounding of the rollout encoder (round to nearest, ties to even). MXFP4 and MXFP8 share the 1×32 block, so the MXFP8 GEMMs receive the rounded weights unchanged, which are the weights rollout serves. The optimizer updates the fp32 master weights and overwrites the BF16 weights after every step, so the weight gradient reaches the master weights unchanged, as with a straight-through estimator, and no rounded copy is kept. Master weights and optimizer state keep their precision, and nothing outside the routed-expert weights is rounded to MXFP4. Routed-expert MXFP4 QAT on the MXFP8 recipe The MXFP8 recipe also matches the 1×32 activation scaling of the W4A8 rollout kernel, so both GEMM operands agree with rollout. Hardware: Blackwell. QAT also requires initializing the trainer from the Hugging Face checkpoint (--init-model-source hf).
On top of the MXFP8 training path of mode 3, this passes:
On the rollout side, the launcher sets SGLANG_DSV4_FP4_EXPERTS=1 and the flashinfer_mxfp4 MoE runner. Without --colocate, MXFP4 routed experts also need --update-weight-transfer-mode broadcast_packed, which sends their UE8M0 scales as bytes. --routed-expert-qat supports DeepSeek-V4 through the Megatron-Bridge provider. It requires --bf16 or --fp16 with fp32 master weights and a Megatron-LM whose TransformerConfig has the moe_expert_fake_quant field. It does not support Megatron FSDP, the Transformer Engine op fuser, or CUDA graphs. See Training and rollout precision for the option values and their constraints.

Fine-grained BF16 exceptions

Miles supports per-layer precision configuration across checkpoint conversion, Megatron training, SGLang rollout, and live weight export. Use equivalent Hugging Face and Megatron name matchers for exceptions beyond a recipe’s default scope. NVFP4 checkpoint conversion and live export exclude shared experts, MTP, and non-language components automatically. Common additional exceptions include final transformer layers and MLA projections whose contraction axis does not match a one-dimensional scaling layout.

Stochastic rounding of BF16 weights

At RL learning rates, many updates to the FP32 master weights are smaller than half a BF16 spacing, so rounding the masters to nearest leaves those BF16 weights unchanged (arXiv:2611.13545). Setting OPEN_TRAINING_BF16_STOCHASTIC_ROUNDING_FLAG=1 in the trainer environment (for example --train-env-vars '{"OPEN_TRAINING_BF16_STOCHASTIC_ROUNDING_FLAG": "1"}') rounds the masters into the BF16 weights stochastically after every optimizer step; rollout and training both use the rounded weights. It applies to --bf16 training with the distributed optimizer, on the GPU or with --optimizer-cpu-offload. Miles refuses --use-precision-aware-optimizer without --optimizer-cpu-offload at startup, since TE FusedAdam then keeps the master weights and casts them itself. The random bits are Transformer Engine’s NVFP4 stochastic-rounding generator (Philox4x32-10) and depend only on the seed, the optimizer step, and the parameter shard, so --rematerialize-param-from-master-weight and resumed runs rebuild the same weights. See miles/kernels/quant/stochastic_round.py and miles/utils/bf16_stochastic_rounding.py.

Hardware support

When BF16 is enough

  • Dense models below ~30 B.
  • A100 hardware (no FP8 GEMM).
  • AMD MI300X / MI325X (no FP8 block-wise path).
  • Bring-up of a new model architecture, where clean BF16 numerics simplify debugging.

Further reading