Skip to content

[None][feat] modeling_v2 catalog: Kimi K3's generic-path entries and sm_100 cells - #19834

Closed
vsabavat wants to merge 11 commits into
NVIDIA:mainfrom
vsabavat:k3-up/u4-g5-generic
Closed

vsabavat wants to merge 11 commits into
NVIDIA:mainfrom
vsabavat:k3-up/u4-g5-generic

Conversation

@vsabavat

@vsabavat vsabavat commented Oct 3, 2026

Copy link
Copy Markdown
Collaborator

Description

Depends on #19826 (Kimi K3 KDA prefill: K1 warps finish reading sPartialLast before the next chunk), whose fix the
ssm/kda_prefill entry runs on. This branch is on its published head; review the last 4 commits.

Kimi K3's prefill, its mixed steps and its decode steps above the K3 decode kernels' bounds run the built-in Kimi K3
model. This PR gives the ops of that path's KDA prefill, routed MoE, MLP activation and MLA context catalog entries,
or Kimi K3 cells in the entries they already have, at the TP16 / TP4 per-rank shapes on sm_100:

  • New entries (contract, wrapper, GPU test):
    • ssm/ (KDA prefill, in the order the layer calls them): causal_conv1d_fwd (the packed q | k | v convolution
      over the cache manager's conv pool), kda_post_conv (L2 norm of q / k and the token-major relayout),
      kda_prefill (the CuTe DSL chunked delta rule over the fp32 V-first state pool, from four 64-token chunks up)
      and chunk_kda (FLA's chunked KDA, which the layer runs below four chunks);
    • norm/rms_norm_gated_token_major (the KDA output's gated norm);
    • activation/situ_and_mul (Kimi K3's SiTU MLP activation);
    • moe/kimi_k3_noaux_tc_mxfp8_quant (routing of 896 experts to 16 and the routed experts' MXFP8 input in one
      launch).
  • Kimi K3 cells on seven shared entries: thop_attention (MLA context over the bf16 latent pool, page 64, heads
    6 / 12 / 24 / 96, the NoPE table), mla_rope_generation, mla_rope_append_paged_kv_assign_q,
    load_paged_kv_cache_for_mla (bf16, page 64, identity rope), noaux_tc_op (896 experts, top 16),
    mxfp8_quantize (K 3584) and the MXFP8 x MXFP4 MoE runner (SiTU, top 16, the 224-expert window at 448).
  • A test fix: on sm_100 the MoE runner's FC1 epilogue requantizes on the round-up scale, as on sm_103. The test
    recorded the OCP scale for sm_100, so 10 of its 18 cells failed there. The identity-down-projection probe now
    matches round-up bit for bit and refutes OCP, and all cells pass at the original tolerances.

Not covered here: MLA generation through thop_attention, which the path runs for decode steps above the fused
kernels' bounds. On sm_100 its trtllm-gen generation kernel for Kimi K3's shapes
(...HQk576HV512HVPerCta128PagedKvDenseP64VarSeqQ8Kv256StaticSwapsAbForGen) currently fails NVRTC compilation, so
its Kimi K3 cell follows separately.

kda_prefill and causal_conv1d_fwd write the cache manager's pools. Their contracts have a ## State section:
the pool, the call-order invariant, and a negative control. One finding is written into kda_prefill's contract
and pinned by a test: the returned o is a view of the runner's scratch for the batch's shape, which the next call
with the same shape key overwrites (the op's fake registration describes a fresh tensor). Kimi K3's layer consumes
o at once.

Design choices

ask choice
A1 stateful ops The two pool-writing entries carry a ## State section (the pool, which slots a call writes, call order, a negative control). They need no state object: the pools are the cache manager's, and the op schemas mark them written (Tensor! / mutates_args).
A3 sm_100 The entries and cells carry sm_100 receipts and skip off sm_100. A shared entry keeps its sm_103 receipt for the cells that predate this PR; CI's l0_b300 run re-certifies those, since the Kimi K3 cells skip there. An entry whose other cells fail on sm_100 at main (thop_attention, mxfp8_quantize, noaux_tc_op) gets no sm_100 key; its contract says why. The tests are listed in l0_b200.yml (only the Kimi K3 cells of those three files).
A5 generic path These entries cover the ops of the generic path's KDA prefill, routing, MLP activation and MLA context. A target drops a call from UNCERTIFIED_GENERIC_CALLS once it calls the entries.
A6 shared contracts The Kimi K3 cells go into the existing contracts, each noted there. KDA gets the new category ssm/. New entries: moe/kimi_k3_noaux_tc_mxfp8_quant, activation/situ_and_mul.

Test Coverage

  • New entries' tests (tests/unittest/_torch/modeling_v2/{ssm,norm,activation,moe}/), each through the catalog
    wrapper at Kimi K3's per-rank shapes (TP16 and TP4):

    • KDA prefill: the conv over a padded pool, the post-conv normalization, the CuTe DSL chunked delta rule and FLA's
      chunk_kda against an fp64 token-by-token reference (ssm/_kda_reference.py), fresh sequences and continuations
      over scattered slots, a chunked continuation against one call plus its negative control, slots other than the
      batch's left bit-unchanged, the conv under CUDA-graph replay, and the rejected inputs;
    • the gated norm, SiTU and the fused routing + MXFP8 input against torch references (the gated norm and the fused
      routing also under CUDA-graph replay), the latter bit for bit against noaux_tc_op + mxfp8_quantize (one bf16
      ulp on the weights).
  • Kimi K3 cells in seven shared entries' tests, skipped off sm_100.

  • On GB200 (sm_100), main's own build plus this branch's Python:

    file passed
    ssm/test_modeling_v2_causal_conv1d_fwd.py 7 / 7
    ssm/test_modeling_v2_kda_post_conv.py 5 / 5
    ssm/test_modeling_v2_kda_prefill.py 5 / 5
    ssm/test_modeling_v2_chunk_kda.py 5 / 5
    norm/test_modeling_v2_rms_norm_gated_token_major.py 6 / 6
    activation/test_modeling_v2_situ_and_mul.py 6 / 6
    moe/test_modeling_v2_kimi_k3_noaux_tc_mxfp8_quant.py 6 / 6
    moe/test_modeling_v2_mxe4m3_mxe2m1_block_scale_moe_runner.py 19 / 19
    attention/test_modeling_v2_mla_rope_generation.py 16 / 16
    attention/test_modeling_v2_mla_rope_append_paged_kv_assign_q.py 7 / 7
    attention/test_modeling_v2_load_paged_kv_cache_for_mla.py 11 / 11
    attention/test_modeling_v2_thop_attention.py::test_kimi_k3_mla_context_bf16_page64 1 / 1
    moe/test_modeling_v2_noaux_tc_op.py::test_kimi_k3_config 1 / 1
    quantization/test_modeling_v2_mxfp8_quantize.py::test_kimi_k3_routed_hidden 1 / 1

    No test skips on sm_100. The rest of the last three files fails on sm_100 at main without this PR as well (their
    contracts say why); l0_b200.yml lists only their Kimi K3 cells.

PR Checklist

Please review the following before submitting your PR:

  • PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.

  • PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.

  • Test cases are provided for new code paths (see test instructions)

  • If PR introduces API changes, an appropriate PR label is added - either api-compatible or api-breaking. For api-breaking, include BREAKING in the PR title. (Catalog entries and tests only.)

  • Any new dependencies have been scanned for license and vulnerabilities (No new dependencies; chunk_kda wraps flash-linear-attention, already in requirements-dev.txt and imported by Kimi K3's layer.)

  • CODEOWNERS updated if ownership changes (No ownership change.)

  • Documentation updated as needed (The contracts are the documentation.)

  • Update tava architecture diagram if there is a significant design change in PR. (No architecture change.)

  • The reviewers assigned automatically/manually are appropriate for the PR. (To check once the PR is open.)

  • Please check this after reviewing the above items as appropriate for this PR.

GitHub Bot Help

To see a list of available CI bot commands, please comment /bot help.

…next chunk

fused_kernel123's K1 warps read their scanned prefix row and the chunk
total from sPartialLast after the scan barrier, and the next chunk's
partial sums overwrite sPartialLast before any K1 barrier (racecheck:
write at fused_k123.py:1268 against reads at :1293 / :1299). A K1 warp
that reached its reads late used the next chunk's sums: with one K1 warp
stalled 20 us after the scan barrier, every case of
test_fused_prefill_beta_sigmoid_matches_unfused_kernel changed (output
max |d| up to 7e14). One K1 barrier after the reads orders them; outputs
are bit-identical to before.

test_fused_prefill_does_not_depend_on_k1_warp_timing runs a copy of the
kernel with that stall and requires the unpatched kernel's bits; it
fails without the barrier.

Signed-off-by: Vasanth Sabavat <[email protected]>
…he round-up scale

test_intermediate_is_mxfp8_quantized reads the MXFP8 x MXFP4 runner's FC1
intermediate out through an identity down projection. On sm_100 it now
matches the round-up scale, ceil(log2(amax / 448)), bit for bit, and refutes
the OCP scale, floor(log2(amax)) - 8, that _SCALE_RECIPE_BY_SM recorded for
sm_100. Under the OCP reference 10 of the 18 cells fail on sm_100 (relative
RMS ~5.5 ulp against a 4 ulp gate, or max abs ~0.07 against 0.031); under the
round-up one all pass at the original tolerances. Record the round-up scale for sm_100, as the test's
message prescribes, and update the contract's recipe text and the README.

Signed-off-by: Vasanth Sabavat <[email protected]>
Kimi K3's prefill, mixed and wide steps run the built-in model, whose
KDA prefill, routing and MLP activation ops had no catalog entry. Add them,
each a contract, a wrapper and a GPU test at Kimi K3's shapes:

- ssm/ (KDA prefill): causal_conv1d_fwd (the packed q | k | v convolution
  over the cache manager's conv pool), kda_post_conv (L2 norm and token-major
  relayout), kda_prefill (the CuTe DSL chunked delta rule over the fp32
  V-first state pool, from four 64-token chunks up) and chunk_kda (FLA's
  chunked KDA, the layer's path below four chunks);
- norm/rms_norm_gated_token_major (the KDA output gate norm);
- activation/situ_and_mul (Kimi K3's SiTU MLP activation);
- moe/kimi_k3_noaux_tc_mxfp8_quant (routing and MXFP8 input quantization of
  the routed experts in one launch).

The pool-writing entries carry a State section. Their tests skip off sm_100;
receipts follow.

Signed-off-by: Vasanth Sabavat <[email protected]>
…entries

Kimi K3's generic path calls seven existing entries at shapes their tests
did not cover. Add a Kimi K3 cell to each, skipped off sm_100:
thop_attention (MLA context over the bf16 latent pool, page 64, heads
6 / 12 / 24 / 96, the NoPE table), mla_rope_generation,
mla_rope_append_paged_kv_assign_q and load_paged_kv_cache_for_mla (bf16, page
64, identity rope), noaux_tc_op (896 experts, top 16), mxfp8_quantize
(K 3584) and the MXFP8 x MXFP4 MoE runner (SiTU, top 16, the 224-expert window
at 448). Each contract notes the cell; the runner's contract gains act_type 3
(SiTU) and Kimi K3's sizes.

Certifying them showed that mxfp8_quantize and noaux_tc_op accept an empty
batch but launch an empty grid (invokeMxFP8Quantization's cudaLaunchKernelEx
return goes unchecked), so cudaErrorInvalidValue stays pending and the next
CUDA launch check in the process raises it: on sm_100 that is why
test_input_not_mutated* fails after the zero-row case and passes alone. Both
contracts now say so.

Signed-off-by: Vasanth Sabavat <[email protected]>
…0 entries

Receipts on GB200 (sm_100), from one run of every test file of this PR at
its previous commit, on main's own build with this branch's Python:
situ_and_mul 6, kimi_k3_noaux_tc_mxfp8_quant 6, rms_norm_gated_token_major 6,
causal_conv1d_fwd 7, kda_post_conv 5, kda_prefill 5 and chunk_kda 5 tests
passed; of the shared entries, the MXFP8 x MXFP4 MoE runner 19,
mla_rope_generation 16, mla_rope_append_paged_kv_assign_q 7 and
load_paged_kv_cache_for_mla 11. No test skipped.

thop_attention, mxfp8_quantize and noaux_tc_op get no sm_100 key: their Kimi
K3 cells pass, but other cells of those files fail on sm_100 for reasons the
contracts state (runtime compilation of XQA / trtllm-gen generation kernels;
the pending launch error after an empty batch). The new entries' tests and the
Kimi K3 cells join l0_b200's pre-merge list, only the cells for those three
files.

Signed-off-by: Vasanth Sabavat <[email protected]>
trtllm::kda_prefill returned a view of a buffer it reuses: the output
was one of the intermediate tensors _get_buffers caches per input shape,
so every call with the same shapes wrote the same storage, and a
caller's output changed under it at the next such call. The op's fake
declares a new tensor (v.new_empty(v.shape)), so nothing orders the
readers of one call's output before the next call.

Allocate the output on every call, with the varlen path's one chunk of
slack past the last token like the cached buffers, and wrap it for K4
there; the cache no longer holds it.

Test: a second call with the same shapes and other inputs must leave the
first call's output unchanged (varlen, and one padded equal-length row).

Signed-off-by: Vasanth Sabavat <[email protected]>
…ensor on every call)

The ssm/kda_prefill entry's test pins the op's output as a new tensor on every
call, which NVIDIA#19835 makes true. NVIDIA#19826 (this branch's base) and NVIDIA#19835 touch
different code in test_kda_prefill_op.py and otherwise disjoint files.

Signed-off-by: Vasanth Sabavat <[email protected]>
…every call

With NVIDIA#19835 merged, trtllm::kda_prefill returns a new output on every call
instead of a view of its cached scratch. test_output_is_runner_scratch
becomes test_output_is_a_new_tensor: later calls, with the same shapes or
others, share no storage with an earlier output and leave it unchanged. The
continuation test drops the copies it needed before. The contract, the
wrapper's docstring and the index summary no longer describe the scratch
view; the module-level cache of compiled kernels and intermediates stays the
entry's A1 gap.

Signed-off-by: Vasanth Sabavat <[email protected]>
@svc-trtllm-gh-bot svc-trtllm-gh-bot added the Community want to contribute PRs initiated from Community label Oct 3, 2026
Kimi K3's MLA decode steps above the fused decode kernels' bounds run
the generic path's MLA generation through this entry: latent MQA over
the bf16 pool, page 64, one query row per request without speculation
and 8 with DSpark (bottom-right causal), at 6 heads per rank (TP16
attention, both Kimi K3 targets) and 96 (one rank). The new cell checks
two steps over histories of one exact page and of 31 tokens against the
fp32 latent-MQA reference, within the bf16 band, and that the pool is
only read. It is listed in l0_b200.yml and skips off SM 10.0.

At 24 heads per rank (TP4), the trtllm-gen FMHA kernel selection raises
"Internal error numHeadsQ=24, numHeadsPerCta=16, numCtasForAllHeads=1"
for these calls; the contract records it.

Signed-off-by: Vasanth Sabavat <[email protected]>
The whole test file, both Kimi K3 cells included, passes on sm_100:
49 / 49 on main's build in the release container and 49 / 49 on main
built inside CI's image. The contract gains the sm_100 receipt; the
sm_103 receipt predates the two Kimi K3 cells and covers the other 47.

Signed-off-by: Vasanth Sabavat <[email protected]>
…re's outputs

test_cuda_graph_replay captured the op at 1, 8 and 64 tokens in one
loop and rebound `outs` inside the next torch.cuda.graph(...), so the
previous capture's outputs were freed inside another capture. Under
cudaMallocAsync that is a captured free of the earlier graph's memory:
"Attempting uncaptured free of a captured allocation", then "invalid
argument" at graph.replay(). The loop now frees them at the end of each
iteration.

Test only: the op is not involved, and with the caching allocator, as
in CI, the test passed before and after.

Signed-off-by: Vasanth Sabavat <[email protected]>
@vsabavat

vsabavat commented Oct 8, 2026

Copy link
Copy Markdown
Collaborator Author

Superseded by the consolidated draft PR: #19990. Source commits and follow-ups are retained; prior reviews remain historical evidence, not approval of the replacement heads.

@vsabavat vsabavat closed this Oct 8, 2026
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.

3 participants