[gfx1250] Fuse A4W4 stage1 FP4 quantization - #4607
Open
XiaobingSuper wants to merge 5 commits into
Open
Conversation
Write packed MXFP4 payloads and preshuffled E8M0 scales directly from the grouped GEMM1 epilogue, removing the standalone quant launch while preserving BF16 rounding semantics. Co-authored-by: Cursor <cursoragent@cursor.com>
Contributor
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends the gfx1250 FlyDSL grouped TDM GEMM1 epilogue to optionally emit packed MXFP4 (A4W4) payloads plus preshuffled E8M0 scales directly after the activation (SiLU/SwiGLU/SiTUv2), and updates routing + tests to exercise the new fused path.
Changes:
- Add a gfx1250 native BF16→FP4 scaled-pack IR helper and wire it into the GEMM1 fused activation+quant epilogue (
stage1_quant_out=2). - Update gfx1250 grouped MoE routing to use the fused quant epilogue for bias-free, supported tile geometries; preserve fallback for other cases.
- Add pytest coverage for fused A4W4 across activations and scale layouts (
quant_wmma_rep1/4/8 via tile_m overrides).
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| op_tests/test_flydsl_grouped_gemm_gfx1250.py | Adds fused-A4W4 activation and scale-layout test coverage for gfx1250. |
| aiter/ops/flydsl/kernels/quant_utils.py | Introduces v_cvt_scalef32_pk8_fp4_bf16 inline-asm helper for native FP4 packing. |
| aiter/ops/flydsl/kernels/mxfp4_preshuffle_gfx1250_tdm.py | Extends GEMM1 epilogue to support packed FP4 output + direct scale preshuffle. |
| aiter/ops/flydsl/grouped_moe_gfx1250.py | Adjusts routing/allocations so eligible A4W4 bias-free shapes use the fused epilogue. |
| aiter/ops/flydsl/batched_gemm_mxfp4.py | Updates public launcher docs/validation for stage1_quant_out values (now 0/1/2). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+93
to
+101
| if stage1_quant_out not in (0, 1, 2): | ||
| raise ValueError( | ||
| f"stage1_quant_out must be 0 (bf16), 1 (fp8), or 2 (fp4), " | ||
| f"got {stage1_quant_out!r}" | ||
| ) | ||
| if stage1_quant_out and (not stage1_act or quant_scale is None): | ||
| raise ValueError( | ||
| "stage1_quant_out requires an activation epilogue and quant_scale" | ||
| ) |
Compute MX scale from the FP32 activation and exchange packed BF16 words so the native FP4 pack avoids a redundant round trip and half of the cross-lane shuffles. Co-authored-by: Cursor <cursoragent@cursor.com>
Shorten the local amax dependency chain from 16 max operations to four levels before the cross-wave exchange. Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Keep the original serial reduction because paired end-to-end measurements showed no reliable benefit from the balanced form. Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
quant_wmma_rep1, 4, and 8Performance
Kimi-K3 TP4 grouped MoE shape on gfx1250: E=896, topk=16, model_dim=3584, inter_dim=768, SiTUv2, A4W4, default 64/64 tiles. Numbers are end-to-end operator latency, averaged across two independent runs of 20 warmups / 300 iterations each.
Correctness is unchanged across the sweep (
logits_diff3.39e-06 to 3.52e-06,rel_l22.60e-03 to 2.65e-03).Test plan
Made with Cursor