Skip to content

[WIP] test(kernel): verify kernel selection cross-platform and drop expected_kernel_name#659

Open
antiagainst wants to merge 4 commits into
mainfrom
lei/kernel-selection-golden
Open

[WIP] test(kernel): verify kernel selection cross-platform and drop expected_kernel_name#659
antiagainst wants to merge 4 commits into
mainfrom
lei/kernel-selection-golden

Conversation

@antiagainst

Copy link
Copy Markdown
Member

expected_kernel_name was an early-enablement safeguard: call sites
hard-coded the expected kernel and test_runtime_callsite_selection.py
checked those literals against fixture platforms. Move the expectations into
the kernel package's golden selection tests and remove the mechanism.

  • Run test_kernel_api_selection.py golden cases on every host via
    Platform.override with fixture platforms, instead of only on matching
    GPUs. New b300_platform fixture activates the never-executed
    blackwell-non-sm100 cases; missing optional backends skip.
  • Declare max_arch_version on FA3/FA4 registrations. Their import guards
    hid overly-broad capabilities, which cross-platform selection exposed
    (FA3 outranked flashinfer_trtllm_* on B300). No change on real hosts.
  • Drop test_runtime_callsite_selection.py; its coverage is subsumed by the
    golden cases, including a new triton_mm_mxfp4 dense GEMM case.
  • Drop expected_kernel_name from select_kernel, mm, and call sites.
    Explicit pins keep using override=; debugging keeps
    TOKENSPEED_KERNEL_VERBOSE / explain_selection.

FA3 registers only on Hopper hosts and FA4 only on SM100 hosts, but their
declared capabilities had no max_arch_version, so the specs claimed to
support every newer NVIDIA arch. Real hosts never noticed because the
import guard hides the spec, but any selection run against a platform
other than the host (Platform.override, cross-platform golden tests)
would let FA3/FA4 outrank kernels that actually support that arch.
Declare the ceilings the import guards already imply so capability
filtering is truthful on its own.

Signed-off-by: Lei Zhang <antiagainst@gmail.com>
@antiagainst antiagainst requested review from a team as code owners July 13, 2026 03:44
Each golden case previously ran only when the host GPU matched its arch
predicate, so an NVIDIA CI machine never checked the AMD golden
selections and vice versa. Run every case on every host by injecting the
case's target platform with Platform.override (the pattern the cdna4
attn_merge_state test already used), parametrized over conftest fixture
platforms mapped from the case's arch tag. A kernel whose registration
is import-guarded on a missing optional backend package skips; a host
that matches the case natively still hard-fails if the kernel is not
registered, preserving the old guarantee on matching CI.

Also add a b300 (sm103) fixture so the blackwell-sm103 cases actually
run (renamed from blackwell-non-sm100: B300 is the only non-sm100
Blackwell part, and it is what the fixture tests), add an mxfp4 dense
GEMM golden case (triton_mm_mxfp4 on cdna4) matching the runtime
Mxfp4LinearMethod call, and skip the argmax cases without CUDA since
argmax only dispatches through selection for CUDA tensors.

Signed-off-by: Lei Zhang <antiagainst@gmail.com>
The AST scanner keyed on expected_kernel_name literals at runtime call
sites, and its hand-maintained MoE entries duplicated trait combinations
that the runtime now builds through tokenspeed_kernel.moe_plan. Every
selection it asserted is covered by the cross-platform golden cases in
test_kernel_api_selection.py, which exercise the public APIs end to end
(signature and trait construction included) instead of calling
select_kernel directly:

- gemm.mm nvfp4 (cublaslt_mm_nvfp4): blackwell-plus golden case
- gemm.mm mxfp4 (triton_mm_mxfp4): cdna4 golden case
- the six MoE apply trait combos: the corresponding moe_plan/moe_apply
  golden cases

Signed-off-by: Lei Zhang <antiagainst@gmail.com>
The hint only logged a warning when auto-selection disagreed with a
name hard-coded at the call site, and it pointed runtime code in the
wrong direction: call sites should rely on kernel auto-selection, with
per-arch expectations recorded once in the golden selection tests and
explicit pins going through the override mechanism. Debugging needs are
covered by TOKENSPEED_KERNEL_VERBOSE and explain_selection. Remove the
parameter from select_kernel and mm, the two runtime dense call sites
(nvfp4 keeps override for its sanctioned kernel pin), and the nvfp4
fused-GEMM numerics test.

Signed-off-by: Lei Zhang <antiagainst@gmail.com>
@antiagainst antiagainst force-pushed the lei/kernel-selection-golden branch from c039609 to edbd606 Compare July 13, 2026 03:58

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: edbd606d48

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +1495 to +1503
if expected_spec is None:
# Registrations are import-guarded on optional backend packages, so a
# missing spec is only a failure when this host should run the case
# natively.
assert not case.matches(host_platform), (
f"{case.expected!r} is not registered on "
f"{host_platform.device_name} ({host_platform.arch_version})"
)
pytest.skip(f"{case.expected!r} is not registered (optional backend missing)")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Reload registrations under the target platform

On non-native CI hosts, this skip path hides the new cross-platform golden cases instead of exercising them. The autouse _kernel_registry fixture reloads registration modules before this test calls Platform.override(platform), and several in-tree kernels are registered only when current_platform() matches the real host architecture; for example, an H100 host never registers FA4/B200 kernels, so expected_spec is None and the B200 case is skipped because case.matches(host_platform) is false. To get the intended fixture-platform coverage, reload the registrations after overriding to the target platform (or only skip truly missing optional backend packages).

Useful? React with 👍 / 👎.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant