Remove state init#4604
Open
grimoire wants to merge 3 commits into
Open
Conversation
Collaborator
grimoire
commented
May 20, 2026
- fill conv state in model when forward
- update gate to ignore init state of gdr
- remove init cache, it take too much times
- l2 norm before repeat interleave
Contributor
There was a problem hiding this comment.
Pull request overview
This PR removes explicit state-cache initialization for the GatedDelta/SSM path by making the model handle “init state” behavior during forward, and optimizes the kv head replication path by applying Q/K L2-normalization before repeat_interleave to reduce overhead.
Changes:
- Add init-state metadata (
is_init,is_init_token) toGatedDeltaMeta, zero conv initial states on init, and mask GDR gate for init tokens. - Move
kv_ratioreplication logic intoGatedDelta(and add a helper that normalizes before replication). - Remove
StateCacheEngine.init_cachesand its call site during model forward.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| lmdeploy/pytorch/nn/gated_delta.py | Adds init-token handling and moves kv replication + (optional) Q/K L2-norm before replication into the GatedDelta wrapper. |
| lmdeploy/pytorch/models/qwen3_5.py | Stops repeating Q/K in the model and passes kv_ratio into GatedDelta. |
| lmdeploy/pytorch/engine/model_agent/agent.py | Removes the state cache initialization call during forward. |
| lmdeploy/pytorch/engine/cache_engine.py | Removes StateCacheEngine.init_caches implementation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
RunningLeon
reviewed
May 22, 2026
|
|
||
| self.is_init = None | ||
| self.is_init_token = None | ||
| if not self.is_decoding: |
Collaborator
There was a problem hiding this comment.
will it work for dp>1?
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.