Repository navigation
[CK] [JIT] [Bugfix] Give every GPU_ARCHS arch its own ck2stages MoE kernel table - #7589
aarushjain29 wants to merge 9 commits into
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
WAITING ON AUTHORPR Self-ReviewRevision Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision. Questions to answer in the PR description
Edit the Missing or invalid answers
Shadow mode reports what would block but keeps the status successful. Set |
There was a problem hiding this comment.
🟡 Changes recommended
Mixed native/named architecture lists leave native unresolved, causing BF16 builds targeting gfx942 to generate nonmatching branches and exclude table-exclusive instances from device compilation.
1 open issue
What changed in this PR
This PR addresses #5766 by generating architecture-specific kernel tables for CK two-stage MoE modules, so multi-architecture builds select the running GPU’s table rather than the last GPU_ARCHS entry.
Changes:
- Resolve and validate all requested build architectures while preserving default single-architecture behavior.
- Generate the union of kernel instances with device-compilation guards and architecture-aware heuristic dispatch.
- Add CPU-only tests for table membership, dispatch branches, shared tables, and architecture parsing.
| File | Description |
|---|---|
tests/test_moe_ck2stages_multiarch_codegen.py |
Adds regression tests for single- and multi-architecture code generation. |
csrc/ck_gemm_moe_2stages_codegen/gen_instances.py |
Generates per-architecture tables, guarded instances, and runtime dispatch branches. |
csrc/ck_gemm_moe_2stages_codegen/gemm_moe_ck2stages_common.py |
Parses build architectures and supports explicit architecture selection for kernel lists. |
Review effort: Balanced
8adc8c1 to
2305d19
Compare
There was a problem hiding this comment.
🔵 Needs a closer look
The architecture-specific device guards and dispatch still need full multi-architecture build and gfx950 runtime validation, which remain unverified and cannot be exercised in this review environment.
No open issues 🎉
2 resolved since last review
Review effort: Balanced
|
I tested this PR at 79c5623 on MI300X (gfx942), together with #7243. #7243 makes unshuffled non-fp4 MoE calls use the prebuilt
I did not test on gfx950. This PR unblocks #7243. Thanks for the fix. |
ChuanLi1101
left a comment
There was a problem hiding this comment.
Direction looks correct: multi-arch GPU_ARCHS=gfx942;gfx950 must not ship only the last arch's ck2stages tables (matches #5766). Please confirm a real multi-arch prebuild + MI300X run for the previously rejected shapes (e.g. a16w16 inter_dim 320/704). Codegen/CPU tests are good; runtime on both archs is the remaining gate. Approving so CI can proceed.
|
Thanks @ChuanLi1101. Multi-arch prebuild + MI300X results for the previously rejected shapes: Setup. This PR at 79c5623 (CK 96afae1), installed in the vLLM CI image on MI300X (gfx942). I prebuilt every ck2stages module the wheel ships (the 22
fp8 per_tensor 320 is outside gfx942's own table, so it fails the same way natively. This PR replaces the gfx950-only check with gfx942's own answer. Controls (a16w16 384/512, fp8 per_tensor and per_token 384/512, per_token 320) run in both. |
|
@aarushjain29 this now conflicts with #7019 in two hunks of Could you squash and rebase with it? It's easier than a per-commit rebase. After that:
I added |
|
The MI300X numbers cover the shapes I was worried about: a16w16 This still conflicts with main. Please take the |
|
#8353 does not depend on this PR and should not wait for it. #8353 only widens the CK MoE lookup so a This PR remains the fix for #5766 (per-arch tables and runtime arch dispatch, Qwen |
There was a problem hiding this comment.
🔵 Needs a closer look
The multi-architecture guards and runtime table dispatch remain unverified on gfx950 and in a full multi-architecture prebuild, and GPU validation is unavailable in this review environment.
No open issues 🎉
1 resolved since last review
Review effort: Balanced
A module with several kernel tables builds each table's kernels only for that table's archs, but the lookup by name returned any listed kernel without checking the device. On gfx942 with GPU_ARCHS="gfx942;gfx950", a kernelName from gfx950's table (as Copilot pointed out for BF16 stage 2's 256x128x128x64_1x4_TypeCast_v1) has no gfx942 device code: HIP could not find the kernel symbol and aborted the process. Main built it for both. Each lookup entry now lists the archs its instance is built for, from the same decision as the instance's arch guard (empty when built for all of the module's archs, as in every single-table module). moe_dispatch() handles a kernel the device's arch lacks like an unknown name: an error under require_exact, else a warning and the device's heuristic kernel. Signed-off-by: aarushjain29 <[email protected]>
There was a problem hiding this comment.
🔵 Needs a closer look
Multi-architecture guards and runtime dispatch require human review because gfx950 runtime behavior and a full multi-architecture prebuilt-wheel build remain unverified in this source-only environment.
Review effort: Balanced
… code for An FP4 instance is wrapped in #ifndef __gfx942__, so it has no gfx942 device code even when both of a module's tables list it. Its lookup entry claimed every arch of the module, so moe_dispatch() still returned it by name on a gfx942 device. The lookup's arch list came from the arch guard alone and missed this wrapper. Take the arch list from everything that leaves device code out: the arch guard and the FP4 wrapper. In a gfx942;gfx950 module an FP4 kernel is now listed for gfx950 only, so the name is rejected on gfx942 like any kernel the device lacks (an error under require_exact, else a warning and the heuristic kernel). This is a lookup-consistency fix. FP4 has no gfx942 hardware path, and the gfx942 heuristic table still returns FP4 kernels there, as before. The lookup test now compares every lookup entry's arch list with the device code the instance file leaves in, and covers FP4. Across the 25 ck2stages prebuild variants (765 instances), the lists and the device code mismatched for 38 instances (all FP4) before and for none now. Signed-off-by: aarushjain29 <[email protected]>
Fixed in 3fbae8e (lookup entries now list the archs each instance is built for, and moe_dispatch() checks the device arch first). Extended to FP4 in ab14b6b. Verified on MI300X with GPU_ARCHS=gfx942;gfx950: a gfx950-only name warns and falls back to the heuristic, where it aborted before |
…gfx942 The multi-arch codegen tests run on the CPU and never launch a kernel, so nothing checked that a kernel named for an arch the device lacks is refused at run time. Before 3fbae8e, asking a gfx942 device for a kernel only gfx950's table has (as Copilot pointed out for BF16 stage 2's 256x128x128x64_1x4_TypeCast_v1) made HIP abort the process with "Cannot find Symbol". Run BF16 stage 2 on a gfx942 device with a gfx950-only kernel name, for each block_m the gfx950 table has such a kernel for. The names come from the codegen tables. The call runs in a child process, since the failure aborts it, and must exit cleanly, log that the kernel was refused, and match an fp32 reference. The test skips off gfx942. It shows the abort only with a module that carries the gfx950 table, such as a prebuilt gfx942;gfx950 wheel. On a gfx942-only build the name is unknown and it checks the same fallback. On MI300X, with BF16 stage-2 modules built for GPU_ARCHS="gfx942;gfx950" (CK f93c029e0): 5 passed here, and 4 of the 5 failed with the abort at 5e0bb41. Signed-off-by: aarushjain29 <[email protected]>
…back on gfx942" Drop the GPU test added in c6813a3 to keep this PR to the production change and its CPU codegen tests. Signed-off-by: aarushjain29 <[email protected]>
There was a problem hiding this comment.
🔵 Needs a closer look
Coordinated device-code guard and dispatch changes require human review because gfx950 runtime execution and the full multi-architecture prebuilt-wheel build remain unverified.
No open issues 🎉
1 resolved since last review
Review effort: Balanced
|
Still need a gfx950 run on the same multi-arch wheel. The named-fallback GPU test was dropped, so only CPU codegen covers that path. Please set Reviewed revision to a71466b. |
|
@valar-cop review |
valar-cop
left a comment
There was a problem hiding this comment.
some changes needed..
gfx950 runtime results on the same GPU_ARCHS="gfx942;gfx950" wheel? heuristic dispatch and tuned-name path
ci green.
| @@ -0,0 +1,203 @@ | |||
| # SPDX-License-Identifier: MIT | |||
There was a problem hiding this comment.
no ci job runs this test.. move to op_tests/ or add it to split_tests.sh next to test_moev2_*.py?

Summary
A CK 2-stage MoE (
moe_ck2stages) module built for severalGPU_ARCHSnow carries the kernel table of each arch, and dispatches on the arch of the device it runs on. Fixes #5766.Motivation
get_gemm{1,2}_kernels_listchooses one kernel table fromget_gfx(), which takes the lastGPU_ARCHSentry. vLLM builds AITER withPREBUILD_KERNELS=1 GPU_ARCHS="gfx942;gfx950", so every prebuilt and JIT ck2stages module carries the gfx950 a16w16 and a8w8 tables, compiled for gfx942 as well. On MI300X:inter_dim=320and704:device_gemm with the specified compilation parameters does not support this GEMM problem.inter_dim=320: the gfx950-only checkgfx950 a8w8 stage2 requires inter_dim to be a multiple of 128.cu_num304/228/80) ofaiter/configs/**/*fmoe*.csv, 997 are not in a maingfx942;gfx950build.inter_dim=384works only by accident. It works on gfx942 since [CK] Use K=128 for gfx950 fp8 stage2 when 256 does not divide inter_dim #6736 only because [CK] Use K=128 for gfx950 fp8 stage2 when 256 does not divide inter_dim #6736 added K=128 instances to the gfx950 table, which gfx942 happens to use.In generated code: on main,
gen_instances.pywithGPU_ARCHS="gfx942;gfx950"writes exactly the same files as withGPU_ARCHS=gfx950, for every module checked, including the build-all module.Changes
gemm_moe_ck2stages_common.py:get_gemm{1,2}_kernels_listtake an optionalarch, defaulting toget_gfx(), sogemm_moe_tune.pyis unchanged.get_gemm_kernel_tables(): the table of each arch inget_gfx_list(), which is the listaiter/jit/core.pypasses to hipcc as--offload-arch. Archs whose tag is the same share one table.get_gfx_list()keeps anativeentry of a list such asnative;gfx950as is, while hipcc builds it for this machine's GPU.get_gemm_kernel_tables()resolves it withget_gfx_runtime().gen_instances.py:generate_instance_and_lookUpTable()gets the tables and writes each one withgenerate_table(), which is the previous body.#if !defined(__HIP_DEVICE_COMPILE__) || defined(__gfxNNN__), so the other archs' device code leaves it out. This is how the FP4 instances already use#ifndef __gfx942__.GPU_ARCHS. Unchanged files keep their mtime, so ninja doesn't recompile them.if (gfx == "gfxNNN").gemm_moe_ck2stages.cu: the heuristic dispatch functions take the device arch as their first parameter.moe_dispatchpassesget_device_gfx()(gemm_dispatch_utils.h, fix(ck_gemm): fix multi-arch build targeting and kernel dispatch across all CK GEMM modules #2645), after the tuned-kernel lookup.ck_moe_stage2gets the device guardck_moe_stage1has, so both stages dispatch and launch on the device of their tensors.tests/test_moe_ck2stages_multiarch_codegen.py: CPU-only tests of the generated code; see Testing.Effect on generated code and build cost:
std::string_view gfxparameter in the two dispatch signatures. Instances and lookup tables are byte-identical to main. Checked for gfx942 and gfx950 on the build-all module, f8 per_token, b16, f8 per_1x128 and fp4x2.Performance (if applicable)
Not applicable. Each arch runs the kernels a single-arch build for it runs.
Testing
Documentation
The user and performance guides need no change: how
GPU_ARCHSis set and used is unchanged, and this fixes what a multi-arch build generates.Dependencies
Breaking Changes
None. The generated
moe_stage{1,2}_heuristic_dispatchfunctions take the device arch as a new first parameter. They are generated per module and called only fromgemm_moe_ck2stages.cu, which this PR updates.Related
PR #7243 reuses
preshuffle_onmodules for unshuffled callers, and waits on this fix because a multi-archpreshuffle_onmodule carried the gfx950 table on gfx942. vLLM's AMD CI works around #5766 in vllm-project/vllm#60633, #62032 and #62161.AI assistance was used to write this change and run the validation. Every line was reviewed by the submitter.
PR Self-Review
Reviewed revision
79c5623
Behavior and intent
With
GPU_ARCHSnaming several archs, a ck2stages module carried only the last arch's kernel table and dispatched every device through it. gfx942 devices ingfx942;gfx950builds therefore rejected shapes and missed tuned kernels that the gfx942 table supports. The module now carries each arch's table, compiled only for that arch, and picks the table by the device's arch at dispatch. In builds for one arch, only the dispatch signature changes, gaining the device arch.Validation and unverified scope
MI300X (gfx942)
Environment: vLLM CI image
rocm/vllm-dev:build-01a1ad48-0b39-414c-8f09-f018d1ab4dec(aiter v0.1.28.post1, whoseck_gemm_moe_2stages_codegenequals main's). I rebuilt the f8 per_token, f8 per_tensor and b16preshuffle_onmulWeightStage2modules through JIT two ways:GPU_ARCHSunset, giving gfx942 code only.GPU_ARCHS="gfx942;gfx950", giving gfx942 and gfx950 code objects. The test runs themselves hadGPU_ARCHSunset.Each case is one
fused_moecall: 16 tokens (block_m32), E=128, topk=8, model_dim=2048, shuffled weights. Results are compared by cosine against an fp32 reference on the same dequantized weights.gfx942;gfx950, main codegen)gfx942;gfx950does not support this GEMM problem)gfx950 a8w8 stage2 requires inter_dim to be a multiple of 128does not support this GEMM problem)All 13 cases give the same outcome on the native and this PR's builds, and the same cosine where they run.
AITER's own gfx942 regressions,
op_tests/test_moe_a16w16_default_dispatch.py -k "test_a16w16_ck_default_alignment or test_qwen_mtp_tp2_ep1_default_dispatch"(the file at v0.1.28.post1, matching the installed aiter), run in the same image withGPU_ARCHSunset:gfx942;gfx950b16 module, main codegen): 11 failed, 32 passed.inter_dim320 and 448 fail at everyblock_m.test_qwen_mtp_tp2_ep1_default_dispatchcases fail.GPU_ARCHS="gfx942;gfx950"(both carry gfx942 and gfx950 code objects): 43 passed.With
GPU_ARCHS="native;gfx950", the b16 module has dispatch branches and instance guards for gfx942 and gfx950. Before thenativefix, it had them fornativeand gfx950. The b16 module JIT-built that way carries gfx942 and gfx950 code objects and runs a16w16inter_dim320, 384, 448 and 704 at cosine 1.0000.With the stage2 device guard, the b16 module rebuilt with
GPU_ARCHS="gfx942;gfx950"runs a16w16inter_dim320 and 704 at cosine 1.0000 with the tensors on the current device (cuda:0) and on another one (cuda:1, current devicecuda:0).CPU
python3 -m pytest -q tests/test_moe_ck2stages_multiarch_codegen.py: 5 passed.gfx942;gfx950module carries the union of the two tables, guards every instance to the archs whose table has it, and runs each arch's single-arch dispatch under that arch's branch.nativelist entry gets the build GPU's table.gfx942;gfx950directory for gfx90a gives the instances of a fresh gfx90a build, and files whose contents didn't change keep their mtime. With instance files skipped when they exist, as before, that test fails on a stale guard.get_gfx_list()[-1:]), the two multi-arch cases fail.GPU_ARCHS=gfx942,gfx950,gfx942;gfx950andgfx950;gfx942, with the build-all module and four single modules. Single-arch output differs from main only in the dispatch signature line. Multi-arch output differs only as described in Changes.gfx942;gfx950build-all module.ruff check(0.16.0) andblack --checkpass on the changed files.Unverified
PREBUILD_KERNELS=1 GPU_ARCHS="gfx942;gfx950"wheel build: only the four modules above (f8 per_token, f8 per_tensor, b16, f16) were compiled. The build-all module was generated and checked, not compiled.csrc/ck_tile_gemm_moe_2stageshas its own kernel lists and is not changed here.PR-specific question
Boundaries.
get_gfx_list(),get_gemm{1,2}_kernels_listpicks the a16w16 or a8w8 table by arch: gfx950 has its own tables, every other arch uses the default ones.block_mandinter_dim.Invariants.
if (gfx == "<arch>"), andgfxisget_device_gfx()of the current device. Both stages set the current device to their tensors' device first, and launch there.TORCH_CHECKin the heuristic, CK's argument check).cu_num, which differs between gfx942 (304/228/80) and gfx950 (256/128), so one arch's tuned kernel is not selected on the other.Changed op tests
None. The new test,
tests/test_moe_ck2stages_multiarch_codegen.py, is a CPU-only test of the generated ck2stages sources. No other test checks them.