Skip to content

[None][feat] GDN exact-replay decode under FORCE_DETERMINISTIC - #22295

Draft
shikicloud wants to merge 12 commits into
NVIDIA:mainfrom
shikicloud:feat/deterministic-gdn-exact-replay
Draft

shikicloud wants to merge 12 commits into
NVIDIA:mainfrom
shikicloud:feat/deterministic-gdn-exact-replay

Conversation

@shikicloud

@shikicloud shikicloud commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

@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 q and k, v, the log decay g, beta and 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_conv with one token per program (new block_tokens argument, default unchanged). Whole-model runs on Qwen3.6-27B showed that both are needed:

    Kernel choice that broke consistency Why All-parts result
    q/k normalization with 16 tokens per program The reduction of a token's squared norm depends on its row in the block 1.46 instead of 0
    Channel-major convolution It picks between two SiLU forms for a whole warp of tokens 16.9 instead of 0
  • 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 (Qwen4ExpHybridCacheManager is 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):

Step Default Exact replay
Decode, batch 32 0.09 ms 0.96 ms
Decode, batch 128 0.11 ms 1.75 ms
Prefill, 1 x 2048 tokens 0.15 ms 0.83 ms
Prefill, 4 x 2048 tokens 0.28 ms 1.71 ms

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 existing unittest/_torch/modules/mamba entries:

  • the replay equals the default chunked delta rule of a lone sequence bit for bit;
  • single-shot prefill, three-piece resumed prefill and prefix-plus-token-by-token decode give identical outputs, boundary states, partial buffers and counts, for small inputs, for wide inputs that reach the deep-negative SiLU range, and when the slot's buffers start as NaN, Inf or 1e30;
  • with one token per program, a token alone, inside a window and inside a 1024-token prefill gets the same q, k, v, g and beta bits;
  • a mixed batch equals its rows run alone, and a captured decode step replays with new inputs;
  • with a real 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 8070e5d78a and #22294, run together with the other parts of the #20890 split; local runs):

Suite Result
The new file 26 passed
unittest/_torch/modules/mamba 1597 passed, 3 skipped
Mamba cache-manager tests and test_qwen3_next_eager_fusion.py 696 passed

The 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.py from #22296): 3 prompts x prompt lengths 129/513/2049, 128 generated tokens each, 1143 decode tokens per run, FORCE_DETERMINISTIC=1, batch 1, GB200.

Model main All parts of the #20890 split All parts without this PR
Qwen3.6-27B (48 GDN + 16 attention layers with head dimension 256, BF16) 12.67 0 (also with CUDA graphs) 8.69

Measured on main f64ad979fb. On main 8070e5d78a the 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-compatible or api-breaking. For api-breaking, include BREAKING in 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.

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>
…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>

This branch has not been deployed

No deployments
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