Add ROCm MXFP4 routed expert kernels - #656
Conversation
Implement resident MXFP4 gate/up and down paths for decode and batched routed MoE on ROCm. Add a synthetic CPU-oracle regression covering full, partial, and large expert tiles, report MXFP4 as a 4-bit routed quant, and make Strix host objects position independent for TheRock linking.
|
I have two strix halos and wanted to run the MXFP4 variant, so spent a decent amount of time working with Codex (Sol 5.6) to get this working. I have more unrelated changes for getting MTP working across the systems and I'd like to see how difficult it would be to enable RDMA over thunderbolt (though that later part involves way more than just this repository). Let me know if you'd like any changes for this PR! |
|
Also note the current numbers are from iommu=pt, I'm testing now with it off, which should produce better numbers. I'm going to be daily driving this on my own hardware for a while, so I'll report back if there are any quality issues. I'm using pi for my harness. |
|
Follow-up to my earlier IOMMU note: These are optimized deployment results, not standalone #656 throughput. The tested build combines the resident ROCm MXFP4 routed-expert kernels from this PR with the restored Q8 prequant decode path from #623. No #623 code is included in this PR. The A/B held the binaries, local-NVMe GGUF, Fedora kernel
All 18 dumped frontier-logit files were byte-identical at each matching context across every repetition and both boot modes, so this affected performance rather than model output. On these systems, |
Coalesce MXFP4 weight reads across wave32 lanes and unpack nibbles with register permutations. Keep the gate/up and down reductions register-resident, route two-to-four-token batches through the direct kernels, and extend the ROCm CPU-oracle coverage across that dispatch boundary.
|
Follow-up on commit
The CPU-oracle test now covers 1, 2, 3, 4, 5, 32, 128, and 512 tokens. All cases passed, with worst observed absolute error of Controlled parent/head results were:
The Q4_K and IOMMU measurements in the PR are additional format/platform context and are not attributed to this commit. |
|
@antirez any chance for a review or comment? Curious to know what you think and if I should spend some more time improving this! Thanks! |
Summary
This is intentionally stacked on
ds4f-mxfp4. It does not include SSD-selected-expert changes, MTP or distributed protocol work, or the Q8 prequant restoration already covered by #623.Correctness
The focused head
7d63867was built and tested independently on both Strix Halo systems,maxandmax2, with Radeon 8060S Graphics / gfx1151:Both full ROCm builds passed. Every synthetic gate/up, SwiGLU, and down result matched the CPU oracle with zero tolerance failures at all eight token counts. Worst observed absolute error was 2.15e-6. Counts 2 through 4 cover the new direct tiny-batch route, while count 5 verifies the transition back to expert-sorted tiles.
The optimization was also checked against the production Flash model. Baseline and optimized first-frontier logits were byte-identical across 129,280 values, including the same argmax.
Default-backend checks passed:
ds4,ds4-server,ds4-bench,ds4-eval, andds4-agentds4-evalextractor self-tests andds4-agenttestsFull-model performance
These are controlled A/B measurements from the production integration tree with the same 0731 MXFP4 model, dual-host 0:21 / 22:output split, resident weights, and runtime configuration. Only the MXFP4 kernel variant or tiny-batch dispatch changed between each before and after point.
A live OpenAI-compatible request after deployment decoded at 14.86 tok/s. The single-token gate kernel uses 52 VGPR / 38 SGPR and the down kernel uses 32 VGPR / 24 SGPR; neither spills or uses private memory. The batched down specialization uses 32 VGPR / 27 SGPR with no spills.
The performance run uses the Q8 prequant path from #623; disabling that path remains substantially slower. This PR does not duplicate #623.
Q4_K comparison on the same PR head
To keep the causal scopes separate, the MXFP4 parent-versus-head A/B above measures this PR. The following compares the Q4_K and MXFP4 routed-expert format paths using the same exact build from head
7d63867.A tensor-level audit of the two 0731 artifacts found identical tensor names and shapes. All 1,199 non-routed tensor payloads were byte-identical; the remaining 129 tensors were the routed-expert weights encoded as Q4_K or MXFP4. All 58 common metadata records were also byte-identical; Q4_K carries four additional imatrix-provenance records.
Performance values are medians of three alternating runs per format with a fixed 4K prefill and 256-token decode, warm resident weights loaded from local SSD, fresh processes and format-specific KV state, the same dual-host
0:21/22:outputsplit, and MTP disabled. Startup time is excluded.A single paired 32K control reproduced the same direction and magnitude: MXFP4 improved prefill by 4.3%, steady decode by 4.7%, and first-token latency by 4.5%. Because this was one pair rather than three alternating pairs, it is treated only as a corroborating long-context check.
These absolute performance values are not directly comparable to the production-integration figures above: this section uses the exact PR-head build and a different fixed-token benchmark shape. It compares format paths and does not attribute the Q4_K-to-MXFP4 difference to this PR.
The 24-case suite is a targeted regression check, not evidence that either format is generally higher quality or that the formats are equivalent. Both passed the same 23 cases, and neither produced a repetition failure.