Repository navigation
[TRTLLM-16624][fix] Compile the KDA draft-commit kernels when the replay state binds - #22209
Open
zhaoyuanh-nvidia wants to merge 1 commit into
Open
zhaoyuanh-nvidia wants to merge 1 commit into
zhaoyuanh-nvidia wants to merge 1 commit into
Conversation
…lay state binds A KDA replay slot's pending drafts are committed only when its request is suspended, and no warmup forward suspends one. So the first suspend in serving compiled the commit's kernels (the replay-only kda_mtp_decode variant or the draft-records replay, and the conv-window store) while every request in flight waited. Commit zero drafts of slot 0 when the replay state binds, after seeding its replay conv window from the live pool, which compiles the same variants and leaves the slot's states as they were. Add regression tests. Signed-off-by: Zhaoyuan He <195028209+zhaoyuanh-nvidia@users.noreply.github.com>
zhaoyuanh-nvidia
requested review from
2ez4bz,
liji-nv,
ruocheng-nv and
thorjohnsen
November 13, 2026 01:29
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
KDAReplayState.commit_pending_drafts(modules/kimi_kda/cache_manager.py) folds a slot's pending accepted drafts and its conv window into the persistent KDA states. Onlysuspend_requestcalls it (inKimiK3HybridCacheManagerandGlm5NextCacheManager), and no warmup forward suspends a request. So the first suspend in serving JIT-compiled the kernels it launches, inside one scheduler step, while every request in flight waited:kda_mtp_decodeCuTe DSL variant, or_replay_kda_token_records_kernelwhen the verify kernels keep draft records;_store_kda_replay_conv_window_kernel.No compile key of these kernels follows the batch: a commit always launches on one slot over the same per-layer pool views. In the Kimi K3 MXFP4 AgentX runs on GB300,
_store_kda_replay_conv_window_kernelcompiled exactly one variant per node, with the same Triton cache key in every run, and never during startup. At the same moment every rank logged one replay-onlykda_mtp_decodecompile. In a TP8 run with the host KV tier (FP8 KV, 32 sessions), the step that made the first suspend took 6.4 s instead of about 0.15 s. In three earlier runs of that point, the streaming gaps around these compiles were 5.4–29.9 s.This PR:
KDAReplayState.prewarm_commit_kernels, whichbindcalls once the replay views are bound, before any request holds a slot. It seeds slot 0's replay conv window from the live pool (copy_kda_replay_conv_window, as a prefill does), then commits zero drafts of slot 0 on every layer. The commit goes through_commit_drafts, the loopcommit_pending_draftsnow uses, so the views and argument types and therefore the compile keys are the same. Committing zero drafts after the seed leaves slot 0's SSM and conv states bit for bit as they were;do_not_specializewould not help: each kernel compiles once per process, on first use.maindoes not have this suspend-time commit yet, so nomainPR is needed. The fix goes with the feature branch.Test Coverage
test_v2_kda_replay_suspend_compiles_no_commit_kernel(replay caches and draft records) builds a V2 manager at Kimi K3's per-rank KDA shapes, forgets the process's earlier compiles of the commit kernels, suspends a request with two drafts pending, and asserts the suspend compiled nothing. Without the source change both cases fail: the suspend compiles 2 kernels. With it, they pass, and bind compiled 2.test_v2_kda_replay_commit_prewarm_leaves_the_slot_states(both modes) fills slot 0's SSM and conv states and its replay buffers with random values, runs the prewarm, and checks the states are bit-identical and the slot's pending-draft count is untouched.test_mamba_cache_manager.py,test_mamba_model_managers.py,test_mixed_precision_kv_cache.py,test_kimi_kda_fused_verify_parity.py,test_kda_mtp_decode_cute_parity.py, the K3 KDA modeling_v2 tests,test_modeling_v2_claims.py,test_glm_kpool.py,test_glm5_next_contracts.pyandtest_kda_mamba_transfer.py. With the fix, 1,287 passed and 6 skipped; at the base, 1,283 passed with the same 6 skips. The difference is the 4 new cases. Pre-commit's ruff, ruff-format and codespell checks pass._store_kda_replay_conv_window_kernelcompiles after startup: 2 → 0. Both nodes now compile it during startup, under the same Triton cache key the earlier runs compiled mid-serving. Every rank compiles the replay-onlykda_mtp_decodevariant during startup instead of at the first suspend._rms_norm_gated_fwd_multirow_kernelcompiles, fixed separately. The baseline's two steps of 6.5 s and 7.6 s at its first suspend are gone.commit_pending_drafts(not part of this PR) logged one suspend-time commit on every rank, with 15–16 requests in flight. It compiled nothing; the steps around it took 0.12–0.64 s, as usual at that load, where the baseline's first suspend took 6.4 s. The rerun had no late Triton compiles at all, 4,749 tok/s/GPU, acceptance length 3.44 and 0 errors, and reached healthy in 721 s.PR Checklist
feat/helix-aggthat suspends requests compiles no_store_kda_replay_conv_window_kernelor replay-onlykda_mtp_decodevariant after startup.