Skip to content

[CK] [JIT] [Bugfix] Give every GPU_ARCHS arch its own ck2stages MoE kernel table - #7589

Open
aarushjain29 wants to merge 9 commits into
ROCm:mainfrom
aarushjain29:fix/moe-ck2stages-per-arch-tables
Open

aarushjain29 wants to merge 9 commits into
ROCm:mainfrom
aarushjain29:fix/moe-ck2stages-per-arch-tables

Conversation

@aarushjain29

@aarushjain29 aarushjain29 commented Nov 6, 2026 •

Copy link
Copy Markdown

Summary

A CK 2-stage MoE (moe_ck2stages) module built for several GPU_ARCHS now 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_list chooses one kernel table from get_gfx(), which takes the last GPU_ARCHS entry. vLLM builds AITER with PREBUILD_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:

  • Supported shapes are rejected. Shapes the gfx942 table covers fail. With the prebuilt v0.1.28.post1 modules:
    • a16w16 inter_dim=320 and 704: device_gemm with the specified compilation parameters does not support this GEMM problem.
    • fp8 per-tensor inter_dim=320: the gfx950-only check gfx950 a8w8 stage2 requires inter_dim to be a multiple of 128.
  • Tuned configs don't resolve. gfx942 tuned kernel names are missing from the module's lookup, so those configs fall back to the heuristic. Of the 1715 ck2stages kernel names in the gfx942 rows (cu_num 304/228/80) of aiter/configs/**/*fmoe*.csv, 997 are not in a main gfx942;gfx950 build.
  • fp8 inter_dim=384 works 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.py with GPU_ARCHS="gfx942;gfx950" writes exactly the same files as with GPU_ARCHS=gfx950, for every module checked, including the build-all module.

Changes

  • gemm_moe_ck2stages_common.py:
    • get_gemm{1,2}_kernels_list take an optional arch, defaulting to get_gfx(), so gemm_moe_tune.py is unchanged.
    • New get_gemm_kernel_tables(): the table of each arch in get_gfx_list(), which is the list aiter/jit/core.py passes to hipcc as --offload-arch. Archs whose tag is the same share one table.
    • get_gfx_list() keeps a native entry of a list such as native;gfx950 as is, while hipcc builds it for this machine's GPU. get_gemm_kernel_tables() resolves it with get_gfx_runtime().
  • gen_instances.py:
    • generate_instance_and_lookUpTable() gets the tables and writes each one with generate_table(), which is the previous body.
    • An instance that only some archs' tables use is wrapped in #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__.
    • An instance file is rewritten when its contents change, instead of being skipped because it exists. JIT builds regenerate a module in the directory of its last build, and the guard depends on GPU_ARCHS. Unchanged files keep their mtime, so ninja doesn't recompile them.
    • When a module has more than one table, each table's heuristic block runs under if (gfx == "gfxNNN").
  • gemm_moe_ck2stages.cu: the heuristic dispatch functions take the device arch as their first parameter. moe_dispatch passes get_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_stage2 gets the device guard ck_moe_stage1 has, 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:

  • Single-arch builds: the only change is the new std::string_view gfx parameter 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.
  • Multi-arch builds of tables that don't vary by arch (blockscale, a8w4, fp4): output is identical to a single-arch build.
  • Multi-arch builds of a16w16 and a8w8: these now compile gfx942's own tables. For the build-all module, instance files go from 924 to 1990 and device compilations from 1848 to 2336 (1.26×). That's the device code a single-arch build compiles for each arch. JIT build time for one module on a 224-core host:
    • f8 per_token: 120 s, against 117 s for a native gfx942 build.
    • b16: 144 s, against 104 s.

Performance (if applicable)

Not applicable. Each arch runs the kernels a single-arch build for it runs.

Testing

  • Unit tests added or updated
  • Performance benchmarks run
  • Tested on MI250X
  • Tested on MI300X

Documentation

  • Docstrings updated
  • User guide updated
  • Performance guide updated
  • No documentation change is needed, with the reason stated below

The user and performance guides need no change: how GPU_ARCHS is set and used is unchanged, and this fixes what a multi-arch build generates.

Dependencies

  • No new third-party dependencies added
  • New dependencies are listed and justified below

Breaking Changes

None. The generated moe_stage{1,2}_heuristic_dispatch functions take the device arch as a new first parameter. They are generated per module and called only from gemm_moe_ck2stages.cu, which this PR updates.

Related

PR #7243 reuses preshuffle_on modules for unshuffled callers, and waits on this fix because a multi-arch preshuffle_on module 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_ARCHS naming several archs, a ck2stages module carried only the last arch's kernel table and dispatched every device through it. gfx942 devices in gfx942;gfx950 builds 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, whose ck_gemm_moe_2stages_codegen equals main's). I rebuilt the f8 per_token, f8 per_tensor and b16 preshuffle_on mulWeightStage2 modules through JIT two ways:

  • native: main's codegen with GPU_ARCHS unset, giving gfx942 code only.
  • this PR: this PR's codegen with GPU_ARCHS="gfx942;gfx950", giving gfx942 and gfx950 code objects. The test runs themselves had GPU_ARCHS unset.

Each case is one fused_moe call: 16 tokens (block_m 32), E=128, topk=8, model_dim=2048, shuffled weights. Results are compared by cosine against an fp32 reference on the same dequantized weights.

Case Prebuilt v0.1.28.post1 (gfx942;gfx950, main codegen) Native gfx942 This PR, gfx942;gfx950
a16w16, inter_dim 320 rejected (does not support this GEMM problem) 1.0000 1.0000
a16w16, inter_dim 704 rejected 1.0000 1.0000
a16w16, inter_dim 448 not run 1.0000 1.0000
a16w16, inter_dim 384 / 512 1.0000 / 1.0000 1.0000 / 1.0000 1.0000 / 1.0000
fp8 per_token, inter_dim 384 / 512 0.9990 / 0.9989 0.9990 / 0.9989 0.9990 / 0.9989
fp8 per_tensor, inter_dim 384 / 512 0.9989 / 0.9989 0.9989 / 0.9989 0.9989 / 0.9989
fp8 per_tensor, inter_dim 320 gfx950 a8w8 stage2 requires inter_dim to be a multiple of 128 rejected (does not support this GEMM problem) rejected (same)
fp8 per_tensor, inter_dim 448 / 704 not run rejected / rejected rejected / rejected

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 with GPU_ARCHS unset:

  • Image as is (prebuilt gfx942;gfx950 b16 module, main codegen): 11 failed, 32 passed.
    • bf16 inter_dim 320 and 448 fail at every block_m.
    • All three test_qwen_mtp_tp2_ep1_default_dispatch cases fail.
    • fp16 passes only because its module is not prebuilt, so it is JIT-built for the native gfx942 arch.
  • This PR's codegen, with the b16 and f16 modules rebuilt with 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 the native fix, it had them for native and gfx950. The b16 module JIT-built that way carries gfx942 and gfx950 code objects and runs a16w16 inter_dim 320, 384, 448 and 704 at cosine 1.0000.

With the stage2 device guard, the b16 module rebuilt with GPU_ARCHS="gfx942;gfx950" runs a16w16 inter_dim 320 and 704 at cosine 1.0000 with the tensors on the current device (cuda:0) and on another one (cuda:1, current device cuda:0).

CPU

  • python3 -m pytest -q tests/test_moe_ck2stages_multiarch_codegen.py: 5 passed.
    • They check that a gfx942;gfx950 module 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.
    • They also check that a table every arch shares is generated exactly as for one arch, and that a native list entry gets the build GPU's table.
    • Regenerating a gfx942;gfx950 directory 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.
    • With the codegen reverted to the last arch's table only (get_gfx_list()[-1:]), the two multi-arch cases fail.
  • In the same image, I generated main's and this PR's code for GPU_ARCHS = gfx942, gfx950, gfx942;gfx950 and gfx950;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.
  • Every gfx942 tuned ck2stages kernel name (1715 of 1715) is in this PR's gfx942;gfx950 build-all module.
  • ruff check (0.16.0) and black --check pass on the changed files.

Unverified

  • gfx950 at runtime with a multi-arch module: there's no MI355 here. The gfx950 code object is built, and the tests check that the gfx950 dispatch branch is exactly the gfx950 single-arch dispatch.
  • A full 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.
  • MI250X was not tested. gfx90a uses the same table as gfx942, so a build for both generates a single table, as before.
  • Performance benchmarks were not run: no kernel changes, and each arch runs its own table's kernels, as in a build for that arch alone.
  • csrc/ck_tile_gemm_moe_2stages has its own kernel lists and is not changed here.

PR-specific question

Boundaries.

  • The change selects kernel tables, not kernels. For each arch in get_gfx_list(), get_gemm{1,2}_kernels_list picks the a16w16 or a8w8 table by arch: gfx950 has its own tables, every other arch uses the default ones.
  • dtype and quant type select the table family exactly as before. Tables for blockscale, a8w4 and fp4 do not depend on the arch.
  • Within a table, shapes are routed as before: by the tuned kernel name, or by the unchanged heuristic on block_m and inter_dim.

Invariants.

  • A device only runs its own arch's table. Each table's heuristic block runs under if (gfx == "<arch>"), and gfx is get_device_gfx() of the current device. Both stages set the current device to their tensors' device first, and launch there.
  • An instance is compiled into the device code of exactly the archs whose table has it. So a heuristic block cannot pick a kernel that the running arch's code object lacks.
  • Shapes a table does not support are still rejected by that table's existing checks (TORCH_CHECK in the heuristic, CK's argument check).
  • Tuned names resolve through the lookup of every table. Tuned configs are keyed by 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.

@aarushjain29
aarushjain29 requested review from a team and a balanced review from Copilot November 6, 2026 18:37
@aarushjain29
aarushjain29 marked this pull request as draft November 6, 2026 18:38
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
ci:windows Windows JIT op smoke test on the gfx1201 ROCm runner
ci:multi-gpu Aiter multi-GPU tests on the 8-GPU runner
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 7589 --add-label <label>

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to stop the title rewrites; labels stay in sync either way.

@aiter-bot

aiter-bot commented Nov 6, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision a71466b792c6 · mode shadow

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

  1. What behavior does this PR change, and why is the existing behavior insufficient?
  2. What did you validate, and what remains unverified? Include commands, hardware/configuration and results.
  3. Which architecture, dtype and shape boundaries select the changed kernel path, and what invariant prevents unsupported inputs from reaching it?
  4. For every changed op_tests/ file, what behavior does it cover and why is it not redundant? Write None if no op test changed.

Edit the PR Self-Review section in the PR description. Include the current revision SHA; this comment refreshes automatically.

Missing or invalid answers

  • FAIL — Reviewed revision must contain at least the first 7 characters of the current head SHA

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

@aarushjain29
aarushjain29 force-pushed the fix/moe-ck2stages-per-arch-tables branch from 8adc8c1 to 2305d19 Compare November 6, 2026 19:36
@aarushjain29
aarushjain29 requested a balanced review from Copilot November 6, 2026 19:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Stale generated architecture guards can exclude required kernels, while stage2’s missing device guard can select dispatch heuristics for the wrong GPU.

2 open issues
1 resolved since last review

Review effort: Balanced

@aarushjain29
aarushjain29 marked this pull request as ready for review November 6, 2026 20:25
Copilot AI balanced review requested due to automatic review settings November 6, 2026 20:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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

@aarushjain29 aarushjain29 changed the title [CK] [Bugfix] Give every GPU_ARCHS arch its own ck2stages MoE kernel … [CK] [Bugfix] Give every GPU_ARCHS arch its own ck2stages MoE kernel table Nov 6, 2026
@AndreasKaratzas

Copy link
Copy Markdown
Contributor

I tested this PR at 79c5623 on MI300X (gfx942), together with #7243. #7243 makes unshuffled non-fp4 MoE calls use the prebuilt preshuffle_on ck2stages modules. Build: GPU_ARCHS="gfx942;gfx950". Case: unshuffled fp8 per_tensor stage2, block_m=32, inter_dim=192.

Branch Result
#7243 gfx950 a8w8 stage2 requires inter_dim to be a multiple of 128, got 192
#7243 on this PR pass

I did not test on gfx950. This PR unblocks #7243. Thanks for the fix.

ChuanLi1101
ChuanLi1101 previously approved these changes Nov 9, 2026

@ChuanLi1101 ChuanLi1101 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@aarushjain29

Copy link
Copy Markdown
Author

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 moe_recipes variants) with GPU_ARCHS="gfx942;gfx950", using a script that runs setup.py's PREBUILD_KERNELS=1 code for them (same build_module arguments, -DPREBUILD_KERNELS=1). All 22 carry gfx942 and gfx950 code objects. Tests ran with GPU_ARCHS unset, and none of the 22 was rebuilt during them. "Before" is the same image's v0.1.28.post1 modules, also prebuilt for gfx942;gfx950. Each case is one fused_moe call, 16 tokens, E=128, topk=8, model_dim=2048, compared by cosine with an fp32 reference.

Shape Before (v0.1.28.post1) This PR
a16w16, inter_dim 320 rejected (does not support this GEMM problem) 1.0000
a16w16, inter_dim 448 rejected (same) 1.0000
a16w16, inter_dim 704 rejected (same) 1.0000
fp8 per_tensor, inter_dim 320 gfx950 a8w8 stage2 requires inter_dim to be a multiple of 128 rejected by CK (does not support this GEMM problem), as in a native gfx942 build
op_tests/test_moe_a16w16_default_dispatch.py -k "test_a16w16_ck_default_alignment or test_qwen_mtp_tp2_ep1_default_dispatch", the 23 bf16 cases 11 failed, 12 passed 23 passed

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.

@AndreasKaratzas AndreasKaratzas added the ci:mi300x Run MI300X standard and OPUS CI on PRs label Nov 15, 2026
@AndreasKaratzas

Copy link
Copy Markdown
Contributor

@aarushjain29 this now conflicts with #7019 in two hunks of gen_instances.py. I resolved it on current main and I'll share the diff with you. It keeps your helpers and write_if_changed, takes main's runtime_swiglu_limit signature, and adds RuntimeSwigluLimit=str(self.runtime_swiglu_limit and kernel.stage == 1).lower() to your STG_INSTANCE_IMPL.format(...). Your codegen test passes on it (5/5).

Could you squash and rebase with it? It's easier than a per-commit rebase. After that:

I added ci:mi300x, so CI builds the gfx942;gfx950 wheel and runs the MI300X shards. Without it, CI only builds gfx950 now.

@ChuanLi1101

Copy link
Copy Markdown
Contributor

The MI300X numbers cover the shapes I was worried about: a16w16 inter_dim 320/448/704 pass, and fp8 per-tensor 320 fails the same way as a native gfx942 build.

This still conflicts with main. Please take the gen_instances.py resolution Andreas posted, squash and rebase, reply on the Copilot threads, and re-run the MI300X cases. I can approve after that.

@jatseng-ai

Copy link
Copy Markdown
Contributor

#8353 does not depend on this PR and should not wait for it.

#8353 only widens the CK MoE lookup so a GPU_ARCHS=gfx942;gfx950 wheel contains the gfx942 instance names the #7361 tuned clamp rows already select (MulABScale, including M=16), with __gfx942__ guards. Heuristic dispatch stays on last-entry get_gfx().

This PR remains the fix for #5766 (per-arch tables and runtime arch dispatch, Qwen inter_dim 384, and the rest). Different bug, overlapping generator. #8353 should land on its own.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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

Copilot AI balanced review requested due to automatic review settings December 1, 2026 05:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

An explicit BF16 stage-2 instance name bypasses architecture checks on gfx942, allowing selection of an instance compiled only for gfx950 and lacking gfx942 device code.

1 open issue

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings December 1, 2026 14:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Named kernel lookup bypasses architecture checks, allowing a device to select a kernel whose implementation was excluded from its code object.

1 open issue

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]>
Copilot AI balanced review requested due to automatic review settings December 1, 2026 18:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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.

1 open issue

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]>
Copilot AI balanced review requested due to automatic review settings December 1, 2026 22:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Coupled multi-architecture guards and runtime dispatch changes require human review because gfx950 execution and the complete multi-architecture prebuilt wheel remain unverified.

1 open issue

Review effort: Balanced

@aarushjain29

Copy link
Copy Markdown
Author

🔵 Needs a closer look

Coupled multi-architecture guards and runtime dispatch changes require human review because gfx950 execution and the complete multi-architecture prebuilt wheel remain unverified.

1 open issue

Review effort: Balanced

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]>
Copilot AI balanced review requested due to automatic review settings December 2, 2026 18:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human review is needed because supplied validation does not cover gfx950 runtime dispatch or a full multi-architecture PREBUILD_KERNELS wheel build.

1 open issue

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings December 2, 2026 20:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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

@aarushjain29
aarushjain29 requested a review from zoe-cop December 2, 2026 20:46
@ChuanLi1101

Copy link
Copy Markdown
Contributor

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.

@yzhou103

yzhou103 commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

@valar-cop review

@valar-cop valar-cop left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no ci job runs this test.. move to op_tests/ or add it to split_tests.sh next to test_moev2_*.py?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:mi300x Run MI300X standard and OPUS CI on PRs CK JIT

Projects

None yet

9 participants