perf(flydsl): fuse Kimi-K3 MLA output gate on gfx950 - #4497
JohnQinAMD wants to merge 5 commits into
Conversation
Add the exact gfx950 batch-one BF16 specialization with graph-safe output reuse and focused dispatch, numerical, and replay coverage. Unsupported contracts remain owned by the framework fallback. Assisted-by: OpenAI Codex Signed-off-by: Yanyuan Qin <yanyuan.qin@amd.com>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
|
There was a problem hiding this comment.
🟡 Not ready to approve
The new FlyDSL kernel imports vendored-removed FlyDSL modules and the tests need tighter gating and a reference that matches the intended BF16 rounding boundaries.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.
Pull request overview
Adds a gfx950-only BF16 FlyDSL kernel and Python wrapper for the Kimi-K3 full-MLA output gate (gate projection + stable sigmoid + attention multiply), plus targeted unit tests to validate dispatch, graph replay, and out= aliasing behavior.
Changes:
- Introduces a fixed-shape gfx950 BF16 FlyDSL kernel implementing projection + sigmoid + multiply in one launch.
- Adds a narrow Python dispatch/launcher (
supports_*+kimi_k3_mla_gate) that raisesNotImplementedErroroutside the supported envelope. - Adds focused FlyDSL tests for dispatch, accuracy,
out=reuse/aliasing, CUDA graph replay, and rejection paths.
File summaries
| File | Description |
|---|---|
| op_tests/flydsl_tests/test_kimi_k3_mla_gate_epilogue.py | Adds gfx950-focused tests for the new MLA gate specialization (dispatch/accuracy/graph/out=). |
| aiter/ops/flydsl/kimi_k3_mla_gate.py | Adds the narrow dispatch predicate and launcher wrapper for the fused MLA gate epilogue kernel. |
| aiter/ops/flydsl/kernels/kimi_k3_mla_gate_epilogue_gfx950.py | Implements the gfx950 BF16 FlyDSL kernel for the fused gate projection + sigmoid + attention multiply. |
Review details
Suppressed comments (2)
op_tests/flydsl_tests/test_kimi_k3_mla_gate_epilogue.py:70
- Same FP32-only reference issue as the primary accuracy test: the kernel rounds projection and sigmoid to BF16 before multiplying, but the reference rounds only once at the end, so it may not catch BF16 boundary mismatches.
reference = (
torch.sigmoid(hidden.float() @ weight.float().T) * attention_input.float()
).to(torch.bfloat16)
op_tests/flydsl_tests/test_kimi_k3_mla_gate_epilogue.py:98
- Same FP32-only reference issue in the graph replay test: reference should mirror the kernel's BF16 rounding boundaries (projection->bf16, sigmoid->bf16) to make the test able to falsify BF16 rounding regressions.
reference = (
torch.sigmoid(hidden.float() @ weight.float().T) * attention.float()
).to(torch.bfloat16)
- Files reviewed: 3/3 changed files
- Comments generated: 3
- Review effort level: Lite
We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.
Signed-off-by: Yanyuan Qin <yanyuan.qin@amd.com>
Signed-off-by: Yanyuan Qin <yanyuan.qin@amd.com>
Signed-off-by: Yanyuan Qin <yanyuan.qin@amd.com>
940feb7 to
e39c71d
Compare
op_tests/op_benchmarks/flydsl/ does not exist on main, no CI job references it, and none of the 84 existing flydsl kernel modules ship a companion benchmark. The script is kept out of tree; measured numbers go in the PR description instead. Signed-off-by: Yanyuan Qin <yanyuan.qin@amd.com>
Purpose
Add a fixed-shape gfx950 FlyDSL Kimi-K3 MLA decode epilogue. It fuses the BF16
[1,7168] x [1536,7168]projection, BF16 materialization, sigmoid, andelementwise multiply with the
[1,1536]attention output. Accumulation isFP32; the returned boundary remains BF16.
The wrapper fails closed outside the exact device, shape, dtype, and stride
contract.
Test plan
replay, and invalid contracts against the production PyTorch boundary.
286.26 MB.
Test results
MI355X/gfx950, TP8 batch-one decode, BF16 input/weight/attention/output; 21
alternating paired trials:
git diff --check, and DCO checks passed.Overlap and limits
vllm-project/vllm#50664 owns serving dispatch. No model-level accuracy change
is expected because the production BF16 materialization is preserved; no
endpoint gain is attributed to this primitive alone.
Tool assistance
OpenAI Codex assisted with implementation, tests, benchmarking, and drafting
this description.