How do I train and serve MoE models released in MXFP4 (gpt-oss, DeepSeek-V4)?
Solved by experts4bit-qlora · this page in the repository (pinned 605d21e67958, the source of this rendering; latest on main, unpinned; not the source of any fact rendered here)
Install routes
From docs/capabilities.json at the pinned commit.
pip install "experts4bit-qlora[train]"Primary route: minimum/reference training.
Alternatives:
pip install "experts4bit-qlora[train,fast]"— loader plus accelerated grouped-kernel path
Environment (from the capability register; one list for all of these routes, so not every item applies to each): OS: Linux · Python: >=3.11 tested in CI (pyproject says >=3.10; 3.10 is not tested) · Accelerator: NVIDIA CUDA GPU, sm_80 or newer (Triton kernels via grouped-nf4-gemm) · Requires: an expert arena baked with grouped-nf4-gemm (nvme_bake_nf4 for NF4, the MXFP4 relocation bake for native MXFP4); grouped-nf4-gemm>=0.43.0 ([fast] extra; the floor is pyproject.toml's, validated by CI); local NVMe or a fast block device; pinned host RAM for the hot tier; triton>=3.4 (Linux-only distribution)
The loader can decode MXFP4 and re-quantise it to NF4, or load experts for an engine that computes on the released bytes. Loading a model does not establish that every training or residency route supports it. Choose the model and task first.
Model, task and supported entry point
The capability register and its training_support records distinguish these routes:
| Model | Task | Entry point | Status and evidence |
|---|---|---|---|
| gpt-oss | Load a frozen NF4 re-quantisation | load_moe_4bit_streaming, then verify_moe_4bit | Supported load; experts are bare, without ExpertsLoRA, unless E4B_GPTOSS_EXPERT_LORA=1 wraps them on its unfused reference loop (opt-in, unmeasured on hardware). The bare load is not expert training. |
| gpt-oss | Native MXFP4 serving in the paged engine | engines.int4_experts.enable_serve_experts_int4 | Native-byte store; matches its own dequantized reference (e4b.serve.p44.gptoss.store-r12.kl-vs-bf16.2026-09-19). |
| gpt-oss | Bind the native-byte NVMe serving engine | enable_mxfp4_nvme_residency | REFUSED for bias-carrying modules; the generic epilogue is not faithful to this model. |
| gpt-oss | Train experts against an NVMe arena | arena_train=True, enable_nvme_train_residency | REFUSED. No supported arena-training route. See training_support.gpt_oss.nvme_train. |
| gpt-oss | Train native MXFP4 experts outside the arena route | grouped-nf4-gemm's mxfp4_qlora.ExpertsMxfp4LoRA | Experimental, unlicensed. The tp1 run has a canary and provenance check, but no parity pair. |
| DeepSeek-V4 | Load a re-quantised NF4 model | load_moe_4bit_streaming, then verify_moe_4bit | Implemented loading path; check the model-specific scope. |
| DeepSeek-V4 | Serve from released MXFP4 bytes in an arena | enable_mxfp4_nvme_residency after a relocation bake | Experimental capability; preserves native bytes and the model's epilogue. The recipe below uses this model. |
| DeepSeek-V4 | Train against a native-byte arena | arena_train=True, then enable_nvme_train_residency | Experimental; CPU specification tests cover layout/staging/numerics, not real-weight convergence or performance. |
Two fidelity paths — choose before loading
Only the second path keeps the checkpoint's original expert bytes.
- Decode, then re-quantise to NF4. The quantising branch of
load_moe_4bit_streaming(experts4bit_qlora/loader.py) reads the released blocks and scales throughexperts4bit_qlora.formats.mxfp4.dequantize_mxfp4— verified bit-identical to transformers' reference decode intests/test_mxfp4_dequant.py— and then builds the expert stack in the storage you asked for, NF4 by default:GptOssExperts4bit.from_gptoss(..., quant_type=quant_type)for gpt-oss andDeepseekV4Experts4bit.from_deepseek_v4(..., quant_type=quant_type)for DeepSeek-V4, each of which quantises the decoded stack throughExperts4bit.from_float. The resulting base is an NF4 re-quantisation of an exact decode of the release; whether its expert adapters can train depends on the model and path above: the decode is bit-exact, the NF4 that follows it is the quantiser's output, and that — not the release — is the provenance of the served experts. Needs no arena and no kernel package.verify_moe_4bit(model, strict=True)proves the stack is 4-bit, not that it is the released bytes. - Native-byte path — retain the released MXFP4 blocks and scales. For the DeepSeek-V4 arena route, relocate the checkpoint's own blocks and scales verbatim into an arena with
nvme_arena.bake_expert_tensors(hash-preserving; the manifest'sbake_moderecords it) and bind it withenable_mxfp4_nvme_residency(serving throughmxfp4_grouped's native kernels) orenable_nvme_train_residencyon anarena=..., arena_train=Trueload (training against the arena, gradient checkpointing required). The paged engine's native MXFP4 store —enable_serve_experts_int4on gpt-oss, which never re-quantises onto the int4 grid — is the all-VRAM form of the same idea. Here the checkpoint's expert bytes are what computes, and provenance is preserved end to end.
Symptoms
- "gpt-oss MXFP4 experts: training and residency" / "QLoRA on an MXFP4 checkpoint" / "MXFP4 expert inference kernel".
- The checkpoint ships
gate_up_proj_blocks/gate_up_proj_scales(gpt-oss) orI8blocks withF8_E8M0scales (DeepSeek-V4), and a naivefrom_pretrainedmaterialises them to bf16 first. KeyError: 'F8_E8M0'when staging a DeepSeek-V4 arena for training.
Why it happens
MXFP4 (OCP microscaling FP4) stores two e2m1 nibbles per byte in blocks of 32 values sharing one e8m0 power-of-two scale. gpt-oss adds per-expert biases, interleaved gate/up rows and a clamped GLU; DeepSeek-V4 keeps SwiGLU with one-sided and two-sided clamps and stores its dense half as block-scaled FP8 (../DEEPSEEK-V4.md). Re-quantising these experts to a uniform int4 grid fails the quality gate because NF4's levels sit on e2m1's and int4's do not (../SERVING-THROUGHPUT.md).
Which project solves it
experts4bit-qlora owns the model side: formats.mxfp4.dequantize_mxfp4 (verified bit-identical to transformers' reference, tests/test_mxfp4_dequant.py), arch/gptoss.py (biases, de-interleave, clamped GLU, GptOssExperts4bit), arch/deepseek_v4.py (key map, FP8 dense side, _apply_gate epilogue), and the binding engines engines/nvme_experts.py, engines/nvme_train.py and engines/int4_experts.py. grouped-nf4-gemm (GitHub, PyPI) owns the native MXFP4 kernels (mxfp4_grouped, including the decode GEMV), the relocation bake nvme_arena.bake_expert_tensors, and mxfp4_residency. Kernel-level questions belong there; [fast] is the seam.
Install
pip install "experts4bit-qlora[train]" # minimum/reference training: the loader (decode-then-NF4 path)
pip install "experts4bit-qlora[train,fast]" # loader plus the native-byte engines used below
Smallest correct example
Needs: GPU + network + the DeepSeek-V4-Flash snapshot on local disk + local NVMe with room for the arena (147 GB of experts, claim e4b.serve.deepseek-v4).
python -c "
from nvme_arena import bake_expert_tensors
from mxfp4_residency import V4_RESIDENCY_KINDS
bake_expert_tensors('/path/to/DeepSeek-V4-Flash', '/nvme/v4.mxarena',
name_template='layers.{layer}.ffn.experts.{expert}.{kind}',
kinds=V4_RESIDENCY_KINDS)" # relocation: no re-quantisation
Needs: the same GPU, the [train] and [fast] extras, and the arena baked above.
import torch
from experts4bit_qlora import enable_mxfp4_nvme_residency, load_moe_4bit_streaming
model, cfg = load_moe_4bit_streaming("deepseek-ai/DeepSeek-V4-Flash", "cuda", torch.bfloat16,
r=8, alpha=16, quant_type="nf4", arena="/nvme/v4.mxarena")
n = enable_mxfp4_nvme_residency(model, "/nvme/v4.mxarena",
k_slots=cfg.num_experts_per_tok, hot_rows=16)
assert n > 0
DeepSeek-V4 only — experimental arena training: load with arena=..., arena_train=True, then enable_nvme_train_residency(model, arena, hot_rows=<expert count>) with gradient checkpointing enabled (offload-moe-experts-to-cpu-or-nvme.md). The default NF4 loading path needs no arena and does not enable gpt-oss expert training: load_moe_4bit_streaming("openai/gpt-oss-20b", ...) then verify_moe_4bit(model, strict=True).
Expected result
enable_mxfp4_nvme_residency returns the number of MoE modules bound (one per layer); a model loaded with arena= has its experts on meta and cannot run until an engine is bound. enable_nvme_train_residency returns the number of modules moved and refuses an undersized hot_rows. For the NF4 path, verify_moe_4bit(model, strict=True) returns without raising. The CPU spec for the MXFP4 training arena — layout resolution, staging into MXFP4-declared buffers, numerics against an oracle decoded from the source bytes — is tests/test_mxfp4_arena_train.py.
Supported scope
- Families: gpt-oss (per-expert biases, clamped GLU, interleaved rows) and DeepSeek-V4 Flash / Pro (clamped SwiGLU, FP8 dense side).
- Arena provenance: a relocation bake is hash-preserving, so the served bytes are the checkpoint's own; a quantize-at-bake NF4 arena is bit-identical to the quantiser's output, not to the release. The manifest records
bake_mode. - Version floors, all from
pyproject.toml: thefastextra's floor is grouped-nf4-gemm >= 0.43.0 at this commit (validated by CI). Two lower feature floors are recorded in its comment ladder and sit below the current floor: training on an MXFP4 arena landed in grouped-nf4-gemm 0.12.0 (theF8_E8M0scale tag; below itcheck_arena_geometryraisesKeyError), and the MXFP4 grouped kernels' 64-bit expert offset (grouped-nf4-gemm#205) in 0.14.0. - Environment: Linux, NVIDIA CUDA sm_80 or newer, Triton (Linux-only); CI tests Python 3.11.
Limitations
- A uniform int4 grid cannot serve MXFP4 experts. For gpt-oss,
enable_serve_experts_int4never re-quantises onto the int4 grid; it installs the native MXFP4 store served throughmxfp4_grouped's decode GEMV. That store is opt-in and single-stream-oriented (batched rows fall back to NF4 when the stacks are kept viaE4B_INT4_KEEP_NF4=1), and its quality claim is fidelity to the shipped bytes (0.0019 nats/token from their dequantized form,e4b.serve.p44.gptoss.store-r12.kl-vs-bf16.2026-09-19), not downstream quality. enable_fastskips MXFP4-arena modules on purpose; their forward is wired bynvme_experts.enable_mxfp4_nvme_residencyrefusesExpertsLoRA-wrapped modules: under the arena loader the base buffers are onmeta, and binding would discard the adapter. Serve from the arena or train against it, not both on one load.ExpertsLoRAtrains gpt-oss's biased, clamped experts on its unfused reference loop only, opt-in throughE4B_GPTOSS_EXPERT_LORA=1; its cost against a fused route is unmeasured.- DeepSeek-V4's full-width resident load does not fit a small card; use the arena path.
- A bf16 checkpoint's training arena is an NF4 quantise-at-bake (grouped-nf4-gemm's
nvme_bake_nf4,offload-moe-experts-to-cpu-or-nvme.md), not the native-byte path;e4b.open.tr2-repro-gap(reproducing the TR2 training receipt) stays open in the register. - Training on an MXFP4 arena has a CPU spec and a bench directory (
bench/mxfp4-arena-train/) but no entry in the claims register: a capability, not a measured result.
Related
offload-moe-experts-to-cpu-or-nvme.md·serve-large-moe-on-a-consumer-gpu.md·bitsandbytes-moe-load-in-4bit-still-ooms.md·qlora-fused-moe-experts.md../DEEPSEEK-V4.md·../RESIDENCY-ENGINES.md·../SERVING-THROUGHPUT.md·../STATUS.md
Evidence
Register: ../claims.json.
e4b.serve.gptoss.loader-faithful— measured; the numeric receipt is in a private audit tree (evidence_private), the probe script is in-repo: MXFP4 dequant bit-identical to the reference, served expert path faithful to HF's reference math.e4b.serve.deepseek-v4— measured: DeepSeek-V4-Flash loads and generates with its experts served from an on-disk arena.e4b.serve.informed-hot-sets— measured: on V4-Flash's arena, profile-ranked hot sets beat by-index at identical VRAM.e4b.serve.buildout.gptoss.b1.5090.2026-09-04— measured: gpt-oss-20b's licensed stack is NF4 experts plus folds; the native MXFP4 store's row is speed with the quality gate open.- Training on an MXFP4 arena: this page describes a capability; it carries no performance claim.
Common wrong approaches
- Re-quantising an MXFP4 checkpoint to NF4 or int4: a uniform int4 grid cannot hold the e2m1 levels.
- Ranking an exact MXFP4 arm against a noisy NF4 arm by raw-text perplexity on gpt-oss: the noisier arm scores better there.
Source and freshness
This page is a rendering of docs/solutions/mxfp4-moe-training-and-residency.md at commit 605d21e67958 (sha256 1a4bbae245d351bc…). Numbers are never copied here: every measured statement cites a claim ID in docs/claims.json at that commit. Repository-relative links resolve to this site's pages where the document is published and to the pinned commit otherwise.
rendered from experts4bit-qlora 0.58.1 · source: pjordanandrsn/experts4bit-qlora@605d21e67958 · checked 2026-10-25