Skip to content

[Bug]: Kimi K3 / MLA unit tests on SM107: two KDA files skip SM107, a cute_dsl_mla routing case contradicts the perf table, and an indexed-pool decode test compares two code paths bit-exactly #20509

Open

Description

@lucifer1004

System Info

  • TensorRT-LLM main @ e88d19c, PyTorch backend
  • GPU with compute capability 10.7 (SM107). Item 2 is a host-side routing test (it monkeypatches the SM version) and fails independently of the GPU.

Who can help?

Related: #19960 (adds the test_cute_dsl_mla case below and extends Kimi K3 to SM107), #18599 (the (96, 1) entry in the FP8 perf table), #18938 (the KDA decode kernel and dispatch).

Reproduction

Three test-only problems seen when running the Kimi K3 / MLA unit tests on SM107. They are grouped here to keep the noise down. None of them is a product bug as far as I can tell. Each item lists the fix I verified.

1. Two KDA test files skip everything on SM107

tests/unittest/_torch/modules/kimi_kda/test_kda_cache_soundness.py:57 and test_kda_prefill_state_parity.py:40 gate on

torch.cuda.get_device_capability(0) in {(10, 0), (10, 3)}

with reason "Kimi K3 is supported only on Blackwell (SM100/SM103)". The runtime predicate is_kda_optimized_supported() (_torch/modules/kimi_kda/_kda_kernels.py:66) accepts (100, 103, 107), and the neighbouring files (test_kda_decode_op.py, test_kda_prefill_op.py) already gate on it. So on SM107 these two files report 6 and 15 skips and cover nothing.

Fix: gate on is_kda_optimized_supported() like the other files. With (10, 7) added, test_kda_cache_soundness.py gives 5 passed and 1 skipped on SM107; the remaining skip is its own runtime condition, "could not obtain a recycled cu_seqlens tensor ID". test_kda_prefill_state_parity.py gives 15 passed.

Related stale comment: the _has_supported_gpu() comments in test_kda_decode_op.py:33 and test_kda_prefill_op.py:38 still say the predicate "accepts SM100/SM103 only; SM107 takes the FLA fallback".

2. test_cute_dsl_mla.py::test_mla_generation_routes_wide_head_fp8_verify_away_from_trtllm_gen[103-96-1-True-False-cute_dsl_mla] fails independently of the GPU

pytest tests/unittest/_torch/attention/test_cute_dsl_mla.py -k routes_wide_head
E       AssertionError: assert 'trtllm_gen' == 'cute_dsl_mla'

The case (103, 96, 1, True, False, "cute_dsl_mla") ("Single-token H=96 is unchanged (measured perf-table entry)") goes through the FP8 perf gate. _PERF_MIN_BATCH_FP8[(96, 1)] = 8 (attention/backends/fmha/cute_dsl_mla.py:419), but _select_mla_generation_fmha always builds a decode batch of batch_size = 4 (test_cute_dsl_mla.py:148). So the gate rejects CuTe DSL MLA and the selection falls through to the TRTLLM-Gen stub. The code behaves as the table says; the expectation is wrong for batch 4.

Fix: either expect "trtllm_gen" for that case (verified: the parametrization then gives 10/10 passed), or add a batch_size parameter to the helper and assert "cute_dsl_mla" at batch 8, which would test the table entry the comment refers to.

3. test_kda_decode_op.py::test_optimized_decode_updates_indexed_recurrent_state_pool_in_place (all 3 ids) fails on SM107

torch.testing.assert_close(indexed_output, local_output, rtol=0, atol=0)
E       Mismatched elements: 2154 / 21504 (10.0%)
E       Greatest absolute difference: 0.00048828125

The test compares two different code paths bit-exactly:

  • The "local" reference calls _run_production_decode(...) without ssm_state_indices. KimiKDALinearAttention.forward_decode then routes to forward_decode_fallback (ssm_state_indices is None), which runs separate q/k/v/g projections.
  • The indexed call passes ssm_state_indices and takes the optimized path with the fused qkvg projection.

On SM107 the two GEMM shapes round differently, by one bf16 ulp on 10% of the elements. That difference then also shows up in the fp32 recurrent state. Each path is deterministic: two local runs are bit-identical. Running the same core output through _project_output twice is bit-identical too.

Fix: compute the local reference on the same path with dense indices, so that the test checks only the pool addressing:

dense_indices = torch.arange(batch_size, dtype=torch.int32, device="cuda")
local_output, local_cache = _run_production_decode(
    optimized,
    hidden_states,
    copy.deepcopy(initial_cache),
    slot_indices=dense_indices.long(),
    ssm_state_indices=dense_indices,
)

With this, the indexed output and the indexed recurrent state are bit-identical to the reference for many-dense-pool, many-strided-pool and compact-dense-pool. The test then gives 3 passed on SM107. I have not checked whether the two paths happen to agree bit-exactly on SM100/SM103.

Expected behavior

These tests run and pass on SM107 (items 1 and 3), and item 2 passes on any GPU.

Actual behavior

On SM107, item 1 skips everything and item 3 fails as shown above. Item 2 fails independently of the GPU.

Additional notes

All three fixes are test-only. I can put them in one PR.

Activity

  1. added
    Testing
    on Oct 17, 2026
  2. codebreaker77 commented on Oct 18, 2026

    @codebreaker77

    @lucifer1004, I'd like to help with the host-side routing-test part of #20509, alongside your planned SM107 test fixes.

    A focused contribution could parameterize _select_mla_generation_fmha by batch size and cover H=96, single-token FP8 routing at batches 4 and 7 (TRTLLM-Gen fallback) versus 8 and 9 (CuTe DSL), on simulated SM100/SM103. A BF16 control below the threshold would guard against applying the FP8 floor to the other dtype path. This would preserve the existing multi-token/Helix controls and change no routing policy or performance table.

    The routing tests also currently lack pytest.mark.cpu_only; the repository's CPU collection hook ignores unmarked files. I'd mark the existing routing regression and new threshold test individually, so the existing unittest/_torch/attention CPU-list entry collects them without adding duplicate list entries or marking kernel tests as CPU-only.

    I checked these six gate decisions against the unchanged _is_perf_favorable source with real CPU PyTorch. I have not run the full routing tests with normal TensorRT-LLM imports or any SM107 kernels, so I would not claim full validation.

    Are you already implementing this matrix? If not, would a focused test patch for your upcoming PR be useful? I can leave items 1 and 3 with your hardware-validated work and avoid opening a competing fix.

  3. lucifer1004 commented on Oct 19, 2026

    @lucifer1004
    CollaboratorAuthor

    @codebreaker77 thanks for the offer, and sorry for the slow reply.

    Our planned PR already touches item 2, but only minimally: it changes the expectation of the single-token H=96 FP8 case from "cute_dsl_mla" to "trtllm_gen", with a comment saying the helper's batch of 4 is below the (96, 1) FP8 minimum of 8. It does not add a batch-size parameter, a BF16 control or cpu_only markers. The perf table is the reference: _PERF_MIN_BATCH_FP8[(96, 1)] = 8 is a measured entry and the routing code follows it, so the test should match the table, not the other way round. No routing policy or table change is planned.

    The PR is not open yet because I am at the open-PR limit; it will go up as soon as a slot frees. The branch is already public: https://github.com/lucifer1004/TensorRT-LLM/tree/upstream/sm107-test-fixes (single commit 7cc2aaf, based on current main's test file, which has not changed since).

    Your matrix would be a good addition on top of it: a batch_size parameter for _select_mla_generation_fmha, FP8 H=96 single-token at batches 4/7 (TRTLLM-Gen) and 8/9 (CuTe DSL) on simulated SM100/SM103, the BF16 control, and per-test pytest.mark.cpu_only. You are right that the file has no cpu_only marker today, so the CPU stage's collection hook skips it and the routing cases only run in GPU stages. Please take that part. Boundaries:

    • Ours: items 1 (SM107 gates and stale comments in the KDA test files) and 3 (the bit-exact indexed-pool comparison in test_kda_decode_op.py), plus the one-line expectation fix above.
    • Yours: the batch-size parametrization, the threshold and BF16 control cases, and the cpu_only marking of the routing tests in test_cute_dsl_mla.py.

    If you base your change on our branch, the two will not conflict; I'll link our PR here when it is open, and a review of it is welcome too.

  4. codebreaker77 commented on Oct 19, 2026

    @codebreaker77

    @lucifer1004, thanks for spelling out the boundaries. I've taken the routing-test portion and based it directly on your upstream/sm107-test-fixes commit 7cc2aaf202.

    Branch: https://github.com/codebreaker77/TensorRT-LLM/tree/test/20509-mla-routing-thresholds

    Additional commit: codebreaker77@5207097e

    The additional commit only changes test_cute_dsl_mla.py: optional batch_size on the helper (default 4), the 12 FP8 threshold/BF16 control cases on simulated SM100/SM103, and individual cpu_only markers on the existing routing regression and new matrix. Your single-token expectation correction is retained. No routing policy or measured table changes.

    Validation: all 22 routing cases pass in source-isolated CPU checks with real PyTorch. These execute the unchanged routing/support class definitions and repository test functions, bypassing native module initialization; the tests retain their existing AutoTuner/kernel-capability monkeypatches. An intentional local mutation lowering the H96 single-token FP8 floor from 8 to 1 fails the below-threshold cases. The actual CPU collection hook now includes the file, and the existing unittest/_torch/attention CPU-list entry covers it. Applicable formatting/lint checks pass.

    I have not run normal-package collection in a matching TensorRT-LLM build or any GPU kernels. I'll keep this as a dependent branch for now so it doesn't compete with your pending PR. Once your PR is linked, I can prepare the follow-up against it. The additional commit can also be cherry-picked into your branch if that's easier.

  5. lucifer1004 commented on Oct 19, 2026

    @lucifer1004
    CollaboratorAuthor

    @codebreaker77 thanks, this looks good. I read 5207097 on top of 7cc2aaf:

    • The expectations match the current gate: _PERF_MIN_BATCH_FP8[(96, 1)] = 8, so FP8 single-token H=96 goes to TRTLLM-Gen at 4 and 7 and to CuTe DSL at 8 and 9; on BF16/FP16 KV H=96 is in the favorable head-count list with no batch floor, so batch 1 and 4 stay on CuTe DSL. The multi-token carve-outs are untouched by the new cases (seq_len_q=1).
    • The batch_size default keeps the existing regression unchanged, and the single-token correction from 7cc2aaf is kept.
    • One consequence of the cpu_only markers worth stating in the PR text: GPU stages run unit tests with -m "not cpu_only", so the existing routing regression moves from the GPU stages to CPU-Generic-* (through the unittest/_torch/attention entry in l0_cpu.yml). That is what we want for a host-side test, but it means the file's module-level imports (cute_dsl_mla, cute_dsl_utils) and FmhaManager._select_mla now have to work without a GPU in a real build. I'll run the 22 routing cases with a real build, both with no visible GPU under -m cpu_only and on an SM 10.7 GPU, and post the result here.

    Merging: once our PR is open I'll cherry-pick 5207097 into it unchanged, so the commit keeps your authorship and sign-off, and credit you in the description. If you would rather own it as a separate PR on top of ours, that works too; tell me which you prefer. Our PR is still waiting for a slot under the open-PR limit for my account, so it may be a little while.

    One more thing for whichever PR lands the fix: main currently waives test_mla_generation_routes_wide_head_fp8_verify_away_from_trtllm_gen[103-96-1-True-False-cute_dsl_mla] (nvbugs 6948129). After the expectation fix that test id no longer exists, so our PR will remove that waive line in the same change.

  6. codebreaker77 commented on Oct 19, 2026

    @codebreaker77

    @lucifer1004, thanks for reviewing the commit and offering the real-build validation. Let's include this in your PR: please cherry-pick 5207097e unchanged, preserving its authorship and sign-off as you proposed. I'm happy for you to own the PR, and I won't open a separate one for this scope.

    Agreed on documenting the move of the routing regression from GPU stages to CPU-Generic-*; the no-visible-GPU run with normal imports is the validation our isolated checks could not provide. Thanks for covering that and the SM107 run, and for handling the obsolete waiver alongside the expectation fix.

    Please link the PR and validation results here when available. I'm happy to help address any issues with the routing-test contribution during review. No rush on the PR slot, and thanks for including the contribution credit.

  7. lucifer1004 commented on Oct 19, 2026

    @lucifer1004
    CollaboratorAuthor

    @codebreaker77 I ran your 5207097 on top of our branch on SM 10.7, using a build from a recent main. The routing and support sources are identical to current main.

    check result
    CUDA_VISIBLE_DEVICES="" pytest test_cute_dsl_mla.py -m cpu_only 22 passed, 8 deselected, no errors
    collection only (--co) 22 routing cases, no collection errors
    the 22 routing cases on GPU 22 passed
    GPU-stage filter -m "not cpu_only" 8 passed, 22 deselected (the non-routing cases, unchanged)
    original file, for comparison only [103-96-1-True-False-cute_dsl_mla] fails (the case waived on main)

    So the matrix runs without CUDA and moves cleanly from the GPU stage to the CPU stage. One caveat we did not check: in a container with no GPU driver at all, import tensorrt_llm fails to find libcuda.so.1 in our image. This is independent of your change; the CPU stage here only hides the devices. When our PR opens I'll cherry-pick 5207097 as is, keeping your authorship and sign-off, and drop the matching line from waives.txt.

  8. added a commit that references this issue on Oct 22, 2026
  9. lucifer1004 commented on Oct 22, 2026

    @lucifer1004
    CollaboratorAuthor

    @codebreaker77 an update on 5207097: I couldn't cherry-pick it unchanged as I'd said. While our PR was waiting for a slot, #20652 landed on main and fixed the single-token H=96 routing case its own way:

    • the routing helper now takes a required batch_size;
    • the existing parametrized test uses batch 8 for seq_len_q == 1, so that case expects cute_dsl_mla again;
    • there is a new test_mla_generation_single_token_wide_head_fp8_below_perf_floor_falls_through (batch 4, trtllm_gen);
    • the waive is removed.

    So your commit no longer applies to the helper, and our own expectation change for that case is no longer correct on main.

    What the branch has now (upstream/sm107-test-fixes, rebased on main):

    Checked on an SM 10.7 GPU: the routing file has 31 tests, all passing, and -m cpu_only with no visible GPU selects 23, all passing. The PR is still waiting for a slot; I'll link it here once it's open.

  10. codebreaker77 commented on Oct 22, 2026

    @codebreaker77

    @lucifer1004, thanks for adapting the contribution after #20652 landed and for explaining the changes. I reviewed 107494ec: the twelve-case threshold/BF16 matrix is retained, the CPU markers cover the new upstream fallback test, and my authorship and sign-off are preserved.

    The adaptation makes sense with main's required batch_size argument. I compared the threshold test with 5207097e; its parameters, assertions and docstring are unchanged. I have not independently rerun the rebased branch. Thanks for reporting the 31 passing tests on SM107 and the 23 CPU-selected cases with devices hidden.

    I'm happy to continue through your PR as agreed. Please link it here once a slot becomes available; I can help address feedback on the routing tests.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Testing

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions