Repository navigation
[None][feat] GDN exact-replay decode under FORCE_DETERMINISTIC - #22295
Draft
shikicloud wants to merge 12 commits into
Draft
shikicloud wants to merge 12 commits into
shikicloud wants to merge 12 commits into
Conversation
Signed-off-by: Shiki Wu <shikiw@nvidia.com>
…t kwargs Signed-off-by: Shiki Wu <shikiw@nvidia.com>
…thub.com/NVIDIA/TensorRT-LLM into feat/deterministic-ssm-replay Signed-off-by: Shiki Wu <shikiw@nvidia.com>
…te slot Signed-off-by: Shiki Wu <shikiw@nvidia.com>
Signed-off-by: Shiki Wu <shikiw@nvidia.com>
…thub.com/NVIDIA/TensorRT-LLM into feat/deterministic-ssm-replay Signed-off-by: Shiki Wu <shikiw@nvidia.com>
… step Signed-off-by: Shiki Wu <shikiw@nvidia.com>
…gdn-exact-replay Signed-off-by: Shiki Wu <shikiw@nvidia.com>
Signed-off-by: Shiki Wu <shikiw@nvidia.com>
1 task done
…al chunk Signed-off-by: Shiki Wu <shikiw@nvidia.com>
…gdn-exact-replay Signed-off-by: Shiki Wu <shikiw@nvidia.com>
…chunk Signed-off-by: Shiki Wu <shikiw@nvidia.com>
1 task done
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.
@coderabbitai summary
Description
Problem. GDN (Qwen3.5 / Qwen3-Next gated delta net) prefill runs the chunked delta rule and decode runs the single-token recurrent update. Both evaluate the same recurrence with different arithmetic, so a token's output differs in the last bits between prefill and decode.
Change. When
FORCE_DETERMINISTIC=1, the chunked delta rule (chunk size 64) is the only arithmetic and decode replays it. The design is the one of #22294 (see the diagram there): a slot holds the FP32 state at the last chunk boundary plus the inputs of the tokens after it.Slot buffers. The normalized
qandk,v, the log decayg,betaand a token count (GDNExactReplayState) are buffers of the recurrent-state slot, so a suspend and resume, a slot move or a snapshot carries them. Everything after the partial chunk is kept zero: the chunk rule reads whole buffer rows, and a newly acquired slot holds arbitrary bytes.Prefill runs one sequence at a time on a chunk grid that starts at its boundary; a resumed prefill re-feeds the buffered partial chunk. Decode runs one dense batch of one chunk per row and stays CUDA-graph capturable.
One kernel per row before the delta rule. Every row goes through the token-major prefill convolution (decode rows as one-token sequences) and through
fused_gdn_post_convwith one token per program (newblock_tokensargument, default unchanged). Whole-model runs on Qwen3.6-27B showed that both are needed:Tiles. The two autotuned chunk kernels are pinned to one configuration each (
pin_gdn_autotune_configs).Preconditions. SM100/SM103,
mamba_ssm_cache_dtype=float32, no speculative decoding, no disaggregated serving,Qwen35HybridCacheManager(Qwen4ExpHybridCacheManageris not covered). If one fails, the cache manager logs the reason once and keeps the default kernels. With the state bound, the prefill CUDA graph is not used and in-forward snapshots are off, so a snapshot point ends a context chunk.Cost per GDN layer on GB200 (Qwen3-Next geometry at TP1: 16 key heads x 128, 32 value heads x 128, BF16 activations, FP32 state, pinned tiles, main
8070e5d78a):The default prefill is the FlashInfer kernel; the replay uses the Triton chunk kernels, one call per sequence. Each slot carries 1.02 MiB of buffers per layer, against 2 MiB of FP32 state. A kernel that computes only the needed row is the follow-up for decode performance.
Depends on #22294, which adds the replay-row bookkeeping this reuses. The branch is stacked on it, so until #22294 merges the diff also shows its changes. Related to #19501.
Test Coverage
New
tests/unittest/_torch/modules/mamba/test_gdn_exact_replay.py(26 cases), collected by the existingunittest/_torch/modules/mambaentries:q,k,v,gandbetabits;Qwen35HybridCacheManager: the buffers are part of the slot and of its byte count, disaggregated serving keeps the default kernels, and a request that resumes from another request's snapshot keeps the bits of a single-shot prefill across a suspend and resume of its cache.Results (GB200, merged with main
8070e5d78aand #22294, run together with the other parts of the #20890 split; local runs):unittest/_torch/modules/mambatest_qwen3_next_eager_fusion.pyThe four wide-input cases fail when the rows go through the channel-major convolution.
Whole model. Largest |Δlogprob| between each decode token and a full-prefill score of the same tokens (
examples/llm-api/llm_prefill_decode_consistency.pyfrom #22296): 3 prompts x prompt lengths 129/513/2049, 128 generated tokens each, 1143 decode tokens per run,FORCE_DETERMINISTIC=1, batch 1, GB200.Measured on main
f64ad979fb. On main8070e5d78athe all-parts result is still 0; main alone varies between runs there (8.33, 7.30 and 1.00 in three runs).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-compatibleorapi-breaking. Forapi-breaking, includeBREAKINGin the PR title.Any new dependencies have been scanned for license and vulnerabilities
CODEOWNERS updated if ownership changes
Documentation updated as needed
Update tava architecture diagram if there is a significant design change in PR.
The reviewers assigned automatically/manually are appropriate for the PR.
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.