Repository navigation
Conversation
4074b46 to
dd3c6cd
Compare
|
@yuychang FYI: we have |
…rb on FP8 kernels on ROCm - Merge the Quark per-channel FP8 [q,k,v,g | f_a | b] KDA in-projection into one FP8 linear for decode - Pad the merged output to a multiple of 64 so it keeps AITER's preshuffled FP8 GEMM - Serve the Quark FP8 f_b from a BF16 copy so it uses the tiny GEMM and the fused KDA decode - Take the single in-proj GEMM path whenever the merged layer exists, not only when _bfa_w is set - Requantize the Quark per-channel FP8 kv_b to per-tensor FP8 so the MLA absorb BMMs run AITER a8w8 - Gate the absorb requantization behind SGLANG_ROCM_K3_MLA_ABSORB_FP8, on by default - Read SGLANG_ROCM_K3_KDA_FUSED_BACKEND through envs instead of os.environ
|
@HubertLu Thanks for the information. I checked whether
The flag also works only at the shared layer boundary ( The AITER options K3 needs are in ROCm/aiter#6270. I added that dependency to the description. You're right that |
- Let Quark W8A8 FP8 take a per-token (fp8, scale) tuple from any AITER producer, not only small-M FP8. - Unpack an (fp8, per-token scale) tuple in apply_fp8_linear on ROCm for linears that pass it straight through. - Add ROCm probes for linears that take group-128 or PTPC FP8 tuples without re-quantization. - Add the PTPC FP8 AITER GEMM wrapper with packing, per-channel detection and numerical tests. - Write PTPC GEMM out= via aiter's gemm_a8w8_bpreshuffle_out (ROCm/aiter#6437), or copy on builds lacking it.
- Add BM=16 kernels that fuse radix-4 routing, sorting and MXFP8 quantization. - Include correctness tests and the decode sort toggle.
- Add the gfx950 FlyDSL MLA output-gate epilogue and its AITER adapter. - Add a JIT kernel that applies the MLA output gate and quantizes the result to FP8. - Add an AITER adapter that writes the MLA query and latent KV cache in one launch. - Register SGLANG_ROCM_K3_FLYDSL_SOURCE in Envs and keep SGLANG_K3_FLYDSL_SOURCE as a deprecated alias. - Add EnvStrWithAlias for string variables that are renamed. - Add numerical tests against the unfused reference. - Vendor the FlyDSL vector shim in kernels/jit/utils, since AITER no longer ships aiter.ops.flydsl.kernels.vector.
- Add the gfx950 FlyDSL group-64 KDA input projection and its AITER adapter. - Add an AITER adapter for packed MXFP4 latent down and up projections. - Add numerical tests for the group-64 projection against the BF16 reference.
- Add gfx950 FlyDSL tri and dual projection kernels for the MoE front before routing. - Add a cooperative kernel that returns the shared expert already activated. - Add an FP8 shared-expert down projection kernel. - Add a latent tail kernel that fuses residual add, RMSNorm and FP8 quantization. - Add AITER adapters, a row-wise FP8 weight helper, numerical tests and a benchmark. - Check router top-k against FP32 within BF16 rounding, since near-tied logits can swap.
@yuychang Thank you for looking into the difference. Yes, let's keep the maintainability of all the variants reasonable. |
- Call the MLA, KDA and MoE fused kernels from kimi_k3_rocm_*.py behind per-operator env switches. - Keep the ROCm bodies in kimi_k3_rocm_*.py; kimi_k3.py only gains short _is_hip hooks. - Run the ROCm fused MoE front through forward_fused_rocm so the CUDA path is unchanged. - Read the ROCm decode attention input as FP8 through the stage boundary's quant_format. - Let an attention-residual bank read fuse its norm with the requested quantization where it can skip the norm. - Add hip_fused_ar_rmsnorm on AITER custom all-reduce with a measured token cap. - Split oversized [latent | shared] MoE all-reduces so each slice fits quick reduce. - Add PTPC FP8 decode projections, online FP8 loading and shared-expert caches. - Use zero positions for the Triton MLA identity-RoPE fallback so it never reads past the one-row tables. - Keep the MORI combine output when the zero-copy MoE buffer is published. - Set an opt-in SGLang M16384 BF16 GEMM profile for AITER while the Kimi-K3 model is built. - Write Quark MXFP4 shared-expert projections into caller buffers from kimi_k3_rocm_moe.py. - Disable symmetric memory under graph capture from an arg hook that only runs on HIP. - Rename SGLANG_AITER_K3_OPT to SGLANG_ROCM_K3_AITER_OPT and keep the old name as a deprecated alias. - Add runtime tests, all-reduce benchmarks and the env variable reference.
0acafe4 to
867d695
Compare
|
@HubertLu Follow-up after rebasing onto the stage-boundary refactor (#42894, #42898, #42936):
Updated A/B and GSM8K results are in the description. The PR is ready for review. |
Motivation
This PR connects the kernels from the previous PRs to the Kimi-K3 model on ROCm, and adds the all-reduce fusions and FP8 decode projections that use them.
Modifications
kimi_k3_rocm_*.pymodules. Each path has its own env switch and falls back to the existing code when the shape or hardware does not match.kimi_k3.pyonly gains short_is_hiphooks. The CUDA paths do not change.quant_format="fp8"or"fp8_per_token", the existing boundary option, so the input norm runs fused with the FP8 quant in upstream's own kernels.AttnBankState(shared) gains quantized attention reads: the bank aggregates without the out-norm, then runs that format's norm+quant kernel. Where the aggregation cannot skip the norm, or the read is gathered afterwards, it reads plainly.AttnResidual.aggregates_unnormedreports which applies.hip_fused_ar_rmsnormon AITER custom all-reduce, with a token cap from measurements.[latent | shared]all-reduce into two when it is larger than the quick-reduce buffer.outputwhen the zero-copy MoE buffer is published (moe_runner/aiter.py).bench_one_batch.AttnResidual.forwardtakeout_norm=None.SGLANG_AITER_K3_OPTtoSGLANG_ROCM_K3_AITER_OPT; the old name still works with a deprecation warning.SGLANG_ROCM_FUSED_AR_RMSNORM,_MAX_TOKENSSGLANG_ROCM_K3_SPLIT_OVERSIZED_MOE_ARSGLANG_ROCM_K3_ATTN_RES_TUNED_LAUNCHSGLANG_ROCM_K3_AITER_OPT(wasSGLANG_AITER_K3_OPT)SGLANG_ROCM_K3_AITER_TUNED_MOE_FRONT,SGLANG_ROCM_K3_MOE_LATENT_MXFP4,SGLANG_ROCM_K3_MOE_LATENT_FP8,SGLANG_ROCM_K3_PTPC_FP8,SGLANG_ROCM_K3_PTPC_FP8_SHARED_DOWN,SGLANG_ROCM_K3_ONLINE_FP8_*,SGLANG_ROCM_K3_AITER_M16384_PROFILEThe three flags that default to on only apply on ROCm.
Shared (non-K3) files:
arg_groups/pipeline.py,arg_groups/resolution_hooks.py,attn_residual.py,attn_res_hip.py,layer_boundary/residual/attn_bank.py,aiter_mla_gluon.py,moe_runner/aiter.py,mxfp4.py,quark_w4a4_mxfp4_moe.py,forward_mla_rocm.py,layers/communication/hip_*.py.Changes since the last revision
mainafter the stage-boundary refactor of Kimi-K3 ([Refactor] Run Kimi K3 through stage boundaries #42894, [Refactor] Run Kimi K3's fused collectives through stage boundaries #42898, [Refactor] Remove Kimi K3's own layer communication and let the consumer set an FFN's exit #42936). The decoder-layer hooks no longer exist upstream, so the ROCm FP8 attention-input fusion now goes through the boundary'squant_formatinstead (see above), and its K3-local copies of the norm+quant kernels are gone.hip_ar_residual(SGLANG_ROCM_AR_RESIDUAL). K3 already folds the residual add intoattn_res_hip, so the fused AR+add was 0.7% to 1.1% slower in TPOT at c1/c2 and neutral at c4/c8, and its call site is gone upstream.gemm_afp4wfp4_pre_quantreduces with atomic adds and only zeroesyit allocates itself, so writing into anew_emptybuffer corrupted the shared-expert output: GSM8K fell from 0.929 to 0.90. Running the linears normally and copying is also 0.3% to 1.2% faster than zeroing the buffer first.use_sigmoid=True, the keyword in AITER after [HIP] Optional sigmoid on gated_rmsnorm_fp8_per_token_quant ROCm/aiter#5392.AITER dependency
hip_fused_ar_rmsnormcallscustom_fused_ar_rms(..., residual_out=, out=, num_norm_rows=, skip_residual=), which ROCm/aiter#6270 adds. Without it the module returnsNoneand the model uses plain all-reduce; nothing fails, so check the AITER version when you measure that path.It does not use
--enable-aiter-allreduce-fusion. That flag fuses all-reduce + residual add + RMSNorm at the shared layer boundary. Kimi-K3's MoE all-reduce is AR + RMSNorm on the latent rows only, with no residual, which the flag's kernel cannot do until ROCm/aiter#6270.Accuracy Tests
GSM8K, 5-shot, 1319 questions. Base is #43129 (kernels present, not called). Each run used a fresh server.
GSM8K varies by about 0.013 between runs of the same code on this setup, so the PR is at parity. Both arms occasionally emit garbled text for a few adjacent questions that ran in the same batch (4 to 8 answers on base, 13 to 17 on this PR, out of 1319). The shared-expert bug fixed in this revision garbled 62 to 67 answers throughout a run.
Speed Tests and Profiling
Result: TPOT is 4.8% to 8.4% lower, TTFT about 7% lower, and throughput 5.6% to 9.1% higher at every concurrency. Base is #43129 (kernels present, not called). This PR uses the recipe's env switches.
MI355X x8, TP8,
/data/models/Kimi-K3-Quark-MXFP4-AttnFP8, AITERe8f486b55(upstream AITERmainplus the Kimi-K3 changes in the draft AITER PRs, including ROCm/aiter#6270). Kimi-K3 8K/1K recipe: random 8192 in / 1024 out, 4 waves per concurrency,--disable-radix-cache, 16K chunked prefill, FP8 KV cache, AITER prefill and decode attention, TP8 without DCP8. Each arm used a fresh server. Base TPOT varied by at most 0.7% over three runs.The previous revision of this description reported up to -19% TPOT against an older base, and was measured before the shared-expert fix above. These numbers replace it.
Tests (MI355X):
test_attn_bank_quant_read.py(6, new),test_kimi_k3_kda_inproj_merge.py,test_mla_bf16_absorb_weight.py,test_hip_k3_moe_pair_ar.py,test_kimi_k3_rocm_bootstrap.py,test_latent_mxfp4_aiter_hip.py,test_hip_fused_ar_rmsnorm.py: 36 passed.test/registered/unit/layer_boundary/has the same 17 failures on this ROCm machine with and without this PR (CUDA-only kernels, and stubs without.weightreaching the ROCm attention-residual kernel).Checklist
Review and Merge Process
/tag-and-rerun-ci,/tag-run-ci-label,/rerun-failed-ci🤖 Generated with Claude Code
CI States
Latest PR Test (Base): ⏳ Run #38501310209
Latest PR Test (Extra): ⏳ Run #38501310140
Latest PR Test (AMD ROCm 10): ⏳ Run #38501310249