Repository navigation
feat(xla): keep the quantized MoE expert bank packed on device - #3588
Conversation
An MLX affine-quantized MoE checkpoint used to dequantize its whole expert bank to f32 at load, so Nemotron-3-Nano-30B-A3B 4-bit needed 117.6 GiB (111 GiB of experts) and could not load on GB10. The bank now stays packed (u32 weights plus f16 or bf16 scales and biases) and is dequantized in the graph. - `Config::packed_experts` is set once by both IREE loaders (`iree_packed_experts::resolve_packed_experts`) and read by the emitter and `weights::weight_specs`, so each expert projection's spec becomes the packed, scales, biases triple in place. On by default except on metal (#613); `MLXCEL_XLA_QUANT_EXPERTS=dequant` restores the f32 bank, whose graphs stay byte-identical to an unquantized checkpoint's. - Decode graphs (single, uniform batch, ragged) gather only the top-k selected experts and dequantize those rows. Prefill runs the masked-dense combine in expert chunks sized by `MLXCEL_XLA_MOE_PREFILL_CHUNK` (512 MiB transient budget). No graph uses a scatter. - Routing moves to `moe_routing.rs` and returns the per-pick expert ids. - The grouped sigmoid router's first-index argmax now reduces the non-negative reversed rank with a maximum. The pinned IREE CUDA compiler pads a signed i32 minimum reduction with -1 once a row reaches 32 lanes, so on main every Nemotron-H router with 32 or more experts picked expert -1 on CUDA (a dropped pick on the dense path, an out-of-bounds gather here). This changes the emitted sigmoid-router graph for every config; no registered golden used it. New fixtures `qwen2-moe-packed-tiny` and `nemotron-h-packed-tiny` freeze the packed graphs, and `spike/openxla/packed_moe_fixture.py` builds 4-bit Jamba and Nemotron-H MoE checkpoints with an exact-dequant HF oracle. Refs #3585
Adds the #3585 section to the SSM findings: the 4-bit Jamba and Nemotron-H MoE fixtures pass every gate on CUDA with the bank packed and dequantized, Nemotron-3-Nano-30B-A3B 4-bit loads in 23.8 GB and passes the serve gate, its token gate against mlxcel's MLX oracle diverges at index 5 on an exact bf16 tie in the oracle, no production module contains a scatter, and decode throughput is bound by the unfused dequant-then-matmul. Refs #3585
Records the 30B CLI run with the default request-sized capacity, attributes the prefill time to the masked-dense form over all experts and every static position rather than to the missing fusion, corrects the per-prefill figure to about 17.5 s, and adds the multi-chunk prefill fixture gate. Refs #3585
gfx1151 (ROCm/HIP) validation at
|
| Model | Mode | structural | token-exact | serve ref-exact | B=1 tok/s | B=4 tok/s |
|---|---|---|---|---|---|---|
| jamba-moe-q4 | packed (default) | PASS | PASS | PASS | 2347.2 | 2281.7 |
| jamba-moe-q4 | QUANT_EXPERTS=dequant |
PASS | PASS | PASS | 2481.7 | 2392.8 |
| jamba-moe-q4 | MOE_PREFILL_CHUNK=3 |
FAIL (see below) | PASS | PASS | 2318.0 | 2699.1 |
| nemotron_h-moe-q4 | packed (default) | PASS | PASS | PASS | 2687.6 | 3017.8 |
| nemotron_h-moe-q4 | QUANT_EXPERTS=dequant |
PASS | PASS | PASS | 3199.7 | 2748.5 |
| nemotron_h-moe-q4 | MOE_PREFILL_CHUNK=3 |
FAIL (see below) | PASS | PASS | 2801.4 | 2672.6 |
| jamba-moe-tiny (f32) | regression | PASS | PASS | PASS | 2731.4 | 2540.8 |
| AI21-Jamba-Reasoning-3B | regression | PASS | PASS | PASS | 6.93 | 5.19 |
I checked that the modes actually diverge. The packed cache MLIR carries ui32 expert parameters (61 for jamba, 37 for nemotron_h), and the dequant MLIR has none. Under chunk=3, the jamba prefill has 45 dot_general against 37 with the default chunk (4 experts, so 2 chunks instead of 1), and decode is byte-identical. Jamba 3B matches my #3448 run (6.92 / 5.16 tok/s).
Chunk=3 structural failure: the byte-exact pre-gate inherits MLXCEL_XLA_MOE_PREFILL_CHUNK. With the env set, registered_fixtures_are_byte_exact and emit_all_reproduces_registered_goldens fail on qwen2-moe-packed-tiny/prefill.mlir, because the goldens are emitted with the default chunk. MLXCEL_XLA_QUANT_EXPERTS=dequant does not leak this way. This is a test-isolation gap, not a numeric divergence: rerunning with --skip-structural passes both execution gates (rows above). It could be fixed by having the structural tests clear the env, or by having validate_arch unset it for the pre-gate.
Scatter: packed nemotron_h rerun with an iree-compile wrapper adding --iree-hal-dump-executable-sources-to: 196 dumped executable sources (decode_step and prefill), 0 iree_linalg_ext.scatter. Same gate results. Caveat: modules with the same name (for example decode and decode_ragged_logits_b4) write into one directory, so a later compile can overwrite an earlier file of the same name.
Logs: acceptance/pr3588/9f4576f8c1f1b807a00d4c2065b063e40c07a8d0/ on the ROCm host (va-*.log, rust-*.log, summary.tsv, scatter-count.txt).
#3588 added `MLXCEL_DUMP_PACKED_EXPERTS` and `MLXCEL_MOE_DISPATCH` to the opt-in `#[ignore]` MoE probe dump test in `mlxcel-xla/src/emitter/mod.rs` without listing them, so the `env var docs` job and the Python tooling test `test_repository_passes` fail on main (abd81b0) and on every PR CI run merged against it. Both are read only by that fixture-authoring test, so they join the existing group with `MLXCEL_DUMP_OUT` and `MLXCEL_MOE_N` instead of the user-facing page. `check_env_var_docs.py` and its unit tests pass locally.
Closes #3585. Refs #3350.
An MLX affine-quantized MoE checkpoint used to dequantize its whole expert bank to f32 at load, so Nemotron-3-Nano-30B-A3B 4-bit needed 117.6 GiB and could not load on GB10. The bank now stays packed (
ui32plus f16/bf16 scales and biases) and is dequantized in the graph; the 30B loads in 23.8 GB.Design
Config::packed_experts, resolved once by both IREE loaders and read by the emitter andweights::weight_specs, so each expert projection's spec becomes the packed, scales, biases triple in place.MLXCEL_XLA_QUANT_EXPERTS=dequantrestores the f32 bank, whose graphs stay byte-identical to an unquantized checkpoint's (unit test). A checkpoint whose expert tensors are notU32with uniform f16/bf16 metadata warns and dequantizes at load.cuda,hip,local-task; never onmetal(bug(xla): packed int8 (MLXCEL_XLA_QUANT=packed) prefill invoke faults on metal-spirv #613). Default-on because the large quantized MoE checkpoints (this 30B, Qwen3-30B-A3B, Mixtral, Phi-3.5-MoE) cannot load with the f32 bank on GB10. Any quantized MoE that fit before now takes the packed path too, and may be slower there (the 4-bit Nemotron-H fixture decodes at 800 vs 1034 tok/s B=1);dequantis the opt-out.hipstays unvalidated until the ROCm host reports.MLXCEL_XLA_MOE_PREFILL_CHUNK, 512 MiB budget) because a gather prefill at capacity 256 would dequantize about 61 GB per layer. No graph uses a scatter.minimumreduction, which this IREE CUDA build pads with-1once a row reaches 32 lanes (minimal repro:[1,w]rows5,6,...reduce to 5 at w=16 and -1 at w=32/64/128). On main every Nemotron-H router with 32 or more experts picked expert -1 on CUDA. It now reduces the non-negative reversed rank withmaximum. No registered golden contained the old form.Validation (GB10, CUDA)
spike/openxla/packed_moe_fixture.py, HF fp32 oracle over the exact dequantized weights): structural, token-exact and serve gates pass with the bank packed and withdequant, on CUDA andlocal-task, and withMLXCEL_XLA_MOE_PREFILL_CHUNK=3(multi-chunk prefill). jamba-moe-tiny and Jamba-3B unchanged.-D warnings(--features iree) and fmt pass. Details:spike/openxla/FINDINGS_ssm.md.