Repository navigation
feat: add ReplaySSM for GDN and KDA - #5028
Open
RunningLeon wants to merge 12 commits into
Open
RunningLeon wants to merge 12 commits into
RunningLeon wants to merge 12 commits into
Conversation
RunningLeon
requested review from
yidingcheng0206
and
a balanced review from Copilot
October 13, 2026 10:25
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
MTP workspaces scale with persistent prefix-cache slots rather than active batch capacity, risking excessive GPU memory use or OOM.
3 open findings
What changed in this PR
Adds opt-in ReplaySSM support for standard Gated DeltaNet and Qwen3.5 MTP decoding, including cache lifecycle, CUDA graphs, configuration, kernels, tests, and documentation.
Changes:
- Adds standard and MTP ReplaySSM Triton kernels and state-cache schemas.
- Integrates cursor commits, checkpoint flushing, CUDA graphs, configuration, and CLI options.
- Adds GPU/CPU regression tests and bilingual documentation.
| File | Description |
|---|---|
tests/pytorch/spec_decode/test_cudagraph_strategy.py |
Tests graph-stable flush buffers. |
tests/pytorch/nn/test_replayssm_flag_off.py |
Tests disabled-path parity. |
tests/pytorch/kernel/test_gated_delta_replayssm.py |
Tests standard kernels and lifecycle. |
tests/pytorch/kernel/test_gated_delta_replayssm_spec.py |
Tests MTP reconstruction and commits. |
tests/pytorch/engine/test_model_agent.py |
Tests agent integration and checkpoint handling. |
tests/pytorch/engine/test_inputs_maker.py |
Tests flush-mask generation. |
tests/pytorch/engine/test_cache_inputs.py |
Tests mask transfer and stream recording. |
tests/pytorch/config/test_replayssm_config.py |
Tests configuration and cache schemas. |
lmdeploy/pytorch/nn/gated_delta.py |
Defines ReplaySSM state views. |
lmdeploy/pytorch/models/utils/cudagraph.py |
Adds fixed graph flush buffers. |
lmdeploy/pytorch/models/qwen3_next.py |
Integrates ReplaySSM state into Qwen3-Next. |
lmdeploy/pytorch/models/qwen3_5.py |
Integrates ReplaySSM state into Qwen3.5. |
lmdeploy/pytorch/model_inputs.py |
Extends model and step contexts. |
lmdeploy/pytorch/kernels/cuda/gated_delta_replayssm.py |
Implements standard ReplaySSM kernels. |
lmdeploy/pytorch/kernels/cuda/gated_delta_replayssm_spec.py |
Implements MTP ReplaySSM kernels. |
lmdeploy/pytorch/kernels/cuda/gated_delta_replayssm_config.py |
Defines fixed kernel launch configurations. |
lmdeploy/pytorch/kernels/cuda/gated_delta_preprocess.py |
Supports compact key-head preprocessing. |
lmdeploy/pytorch/engine/model_agent/agent.py |
Manages flush and MTP commit lifecycle. |
lmdeploy/pytorch/engine/inputs_maker.py |
Creates checkpoint flush masks. |
lmdeploy/pytorch/engine/executor/base.py |
Adds ReplaySSM memory accounting. |
lmdeploy/pytorch/engine/executor/__init__.py |
Validates supported configurations. |
lmdeploy/pytorch/engine/config_builder.py |
Propagates public settings. |
lmdeploy/pytorch/engine/cache_inputs.py |
Transfers flush masks to devices. |
lmdeploy/pytorch/consts.py |
Defines named cache keys. |
lmdeploy/pytorch/configurations/qwen3_next.py |
Builds ReplaySSM cache schemas. |
lmdeploy/pytorch/configurations/qwen3_5.py |
Enables schemas for Qwen3.5. |
lmdeploy/pytorch/config.py |
Adds ReplaySSM configuration fields. |
lmdeploy/pytorch/backends/gated_delta_rule.py |
Extends preprocessing metadata and API. |
lmdeploy/pytorch/backends/cuda/graph_runner/full_graph.py |
Marks standard ReplaySSM graphs. |
lmdeploy/pytorch/backends/cuda/gated_delta_rule.py |
Dispatches ReplaySSM implementations. |
lmdeploy/messages.py |
Exposes public engine options. |
lmdeploy/cli/utils.py |
Defines ReplaySSM CLI arguments. |
lmdeploy/cli/serve.py |
Connects options to API serving. |
lmdeploy/cli/cli.py |
Exposes options for interactive chat. |
docs/zh_cn/index.rst |
Links Chinese documentation. |
docs/zh_cn/advance/replayssm.md |
Documents ReplaySSM in Chinese. |
docs/en/index.rst |
Links English documentation. |
docs/en/advance/replayssm.md |
Documents ReplaySSM in English. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Implement opt-in ReplaySSM CUDA/Triton feature for LMDeploy PyTorch engine, covering standard Gated DeltaNet decode and Qwen3.5 MTP speculative decode. Stage A (standard decode): - Config flag enable_replayssm (default-off), preallocation checks - Named state-cache allocation and accounting - Triton decode/flush kernels with cursor/acceptance lifecycle - Once-per-model-step cursor advance, CUDA graph compatible - Scheduler and cache lifecycle ownership - Flag-off parity preserved; unsupported configs fail early Stage B (MTP decode): - Raw/transformed rings, FP32 checkpoint policy - Exact closed-loop raw-input fold, IEEE reconstruction - Rejection-owned accepted-input commit on every target rank - Finished-slot cap/discard behavior Tests: 25 ReplaySSM GPU kernel tests, 26 config tests, flag-off parity, graph boundary, MTP postprocess paths, stop-independent rejection commit. Benchmark scripts and results under benchmark/replayssm/. Docs under docs/en/advance/replayssm.md and docs/zh_cn/advance/replayssm.md.
RunningLeon
force-pushed
the
feat/replayssm
branch
from
October 19, 2026 07:46
dd6e099 to
3add36c
Compare
RunningLeon
marked this pull request as ready for review
October 20, 2026 03:21
Keep ReplaySSM KDA setup while adopting upstream executor-owned MTP prefix lookahead. Verify Qwen MTP4 and GLM MTP5 DP4/EP4 with real Mooncake Store.
Retain both ReplaySSM and prefix caching entries in English and Chinese documentation indexes.
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.


Summary
Performance test settings
Fixed capacity aligns nominal token capacity, not physical cache bytes across backends. Automatic allocation may convert state-memory savings into additional KV capacity.
Performance results
Each row compares Replay ON against OFF within the same backend, model and mode.
MTP=OFFdenotes target-only. Throughput is output tokens/s; TTFT and TPOT are means. Memory is the measured whole-server NVML peak per GPU; TP4 uses the mean of the four per-GPU peaks. Negative memory deltas indicate savings.Conclusions
BC-breaking (Optional)
Does the modification introduce changes that break the backward-compatibility of the downstream repositories?
If so, please describe how it breaks the compatibility and how the downstream projects should modify their code to keep compatibility with this PR.
Use cases (Optional)
If this PR introduces a new feature, it is better to list some use cases here, and update the documentation.
Checklist