Repository navigation
[MoE] Skip unused intermediate allocation for fused stage-1 quantization - #7172
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
READY FOR HUMAN REVIEWPR Self-ReviewRevision Author self-review accepted. Readiness report: Author answers
Show the author's self-review answersBehavior and intentValidation and unverified scopePR-specific questionChanged op testsPR state
Copilot findings
Code and op-test hygiene
Required CI
Shadow mode reports what would block but keeps the status successful. Set |
|
All checks on the current head are green, including the Aiter Test Gate. @yifehuan could you take a look when you have a moment? Thank you! |
|
@yifehuan the self-review bot now reports this pull request as ready for human review: the author answers are accepted and Black, Ruff, the repository dependency check and the Aiter Test Gate passed on this head. I added the missing statement of what is unverified to the description; the code is unchanged. The change is three lines in |
|
@zufayu as the contact for |
|
@yzhou103 could you take a look at this one when you have a moment? It is a three-line change in |
|
@yifehuan this one had been sitting on a base from October and its CI records were gone, so there was nothing left for anyone to approve. I merged current main ( What it does: when stage 1 fuses quantization it returns its own output, and At the new head, on an MI355X, I ran the MoE op test on 16 tuned DeepSeek-V4 rows whose stage-1 kernel fuses quantization. It passes exactly as on main, and 1,118 of the 1,791 |
|
@yifehuan thanks for the approval and for the re-run. It is green now: all eight standard shards and the gate have passed, as have Checks, Triton Test and OPUS Test. Could you help merge it? |
Summary
Skip the unused
a2allocation infused_moe_2stageswhen stage 1 fuses quantization. The caller already passesNonein this case and takes the intermediate from stage 1's return value.Motivation
The discarded BF16 buffer is 36 MiB for M8192, top-6, I384. Removing it reduced PyTorch graph-reserved memory by 36 MiB in all four measured prefill pairs.
Changes
metadata.fuse_quantto the existing allocation-skip condition.a2directly to stage 1; its value is now alreadyNonefor fused quantization.Performance (if applicable)
MI350X/gfx950; PyTorch 2.11.0+rocm7.2; HIP 7.2.26015; native allocator. Prefill: M8192/H7168/I384/E384/topk6, FP8×FP4, BF16 output, per-1×32 quantization, SiLU limit10, INTERLEAVE/GUGU, Opus fused-quant dispatch. Control: M16/H896/I384/E8/topk2, per-tensor FP8×FP8, BF16 output, SiLU, SEPARATED, nonfused CK dispatch.
Each case used four fresh-process pairs in AB/BA/BA/AB order, seed0, 101 samples per process. Allocation is the primary result.
These numbers are from the first revision of this branch (
c23d41447); they were not repeated after main was merged on 24 November. The reserved-memory difference remained through replay. These are allocator observations under the recorded conditions; they do not measure total HBM traffic. Timing drift prevents a speedup conclusion.Exact scripts, source/configuration pins, run commands, raw measurements, and detailed limitations.
Testing
python3 op_tests/test_moe_2stage.py --no-legacy --csv-filter flydsl_mxmoe_g1_a8w4_64x256x256_fp8out_xcd2 opus_moe1_afp8_wfp4_bf16_t64x384_gs_qgb3_aff64_k1lead_fp8passes, as it does on main6a0a23ff3. Those are 16 tuned DeepSeek-V4 rows whose stage-1 kernel fuses quantization (prefill sizes of 2048 to 16384 tokens, among them 8192 tokens with hidden 7168, intermediate 384, 384 experts and top-6, the shape measured under Performance), plus the fixed checks of the file. In each of the two runs 1,118 of the 1,791 calls offused_moe_2stageshad fused quantization (128 with an FP8 and 990 with an FP4 intermediate), which is the branch this change touches. Every module was built from the tree's sources.git diff --checkpassed. The merge changes no line of this pull request.In the first-revision experiment all checked outputs were finite. Both arms reported the same reference mismatch fractions (
checkAllclose): 0.7746445 for prefill and 0.0626395 for control, withlogits_diff3.6646665e-4 and 4.3923888e-6 respectively. The upstream strict test rejects NaNs and rejects a nonzero mismatch fraction only whenlogits_diff > 0.01; both cases pass that rule. The correctness evidence is the per-arm finite-output and strict-oracle checks described here; it establishes acceptance under that rule rather than paired tensor equality.Documentation
Dependencies
Breaking Changes
None.
PR Self-Review
Reviewed revision
dda83547277355204e990bb56ddd2ea71e645095Behavior and intent
The same fused-quant predicate moves from the call argument to allocation. No intervening code uses
a2; stage-1 output ownership and returned-output handling are preserved.Validation and unverified scope
On 24 November main
6a0a23ff3was merged into this branch. It was 596 commits behind, 33 of them inaiter/fused_moe.py; the merge is clean and the two hunks are unchanged. I read the merged function again: between the allocation and the stage-1 call nothing usesa2; stage 1 gets the same argument as before in both cases,Nonewith fused quantization and the buffer otherwise; anda2is then assigned from what stage 1 returns. At this revision and on that main, on an MI355X,python3 op_tests/test_moe_2stage.py --no-legacy --csv-filter flydsl_mxmoe_g1_a8w4_64x256x256_fp8out_xcd2 opus_moe1_afp8_wfp4_bf16_t64x384_gs_qgb3_aff64_k1lead_fp8passes with every module built from the tree's sources; 1,118 of the 1,791 calls offused_moe_2stagesin each run had fused quantization.The allocation experiment under Performance measured
6fe1bfc8…with standard CK96afae1d…plus this allocation patch, on an MI350X, in the specified prefill and nonfused-control cases; exact identities and commands are in the companion. It was not repeated at this revision. Decode was excluded before that experiment because an earlier baseline dispatch attempt failed.Unverified: the allocation numbers at this revision; decode shapes; MI250X/MI300X; any speed effect (timing drift between the paired processes was larger than a possible gain, so none is claimed); upstream CI at this revision.
PR-specific question
The critical boundary is stage-1 output ownership. Both source versions pass
Nonewhenmetadata.fuse_quantis truthy. Recorded dispatch checks show fused quantization in prefill and unchanged allocation in the nonfused control; both pass the unchanged strict oracle.Changed op tests
None. Existing native oracle and contract checks were used unchanged.