Skip to content

[Cherry-pick to release/v0.5.12] [Fix] DSV4 cached_loc invalidated when SWA mapping is rebuilt (#25889) - #26079

Merged
Kangyan-Zhou merged 1 commit into
release/v0.5.12from
cherry-pick/888a8794e-to-v0.5.12-0a216ed2
May 22, 2026
Merged

Kangyan-Zhou merged 1 commit into
release/v0.5.12from
cherry-pick/888a8794e-to-v0.5.12-0a216ed2

Conversation

@Kangyan-Zhou

@Kangyan-Zhou Kangyan-Zhou commented May 22, 2026 •

Copy link
Copy Markdown
Collaborator

Cherry-pick of commit 888a8794ef3d689c4cb9417639d3fcfcee23f0be to release/v0.5.12.

Source PR: #25889 (#25889)
Source commit: 888a8794ef3d689c4cb9417639d3fcfcee23f0be
Original title: [Fix] DSV4 cached_loc invalidated when SWA mapping is rebuilt


This PR was automatically created by the cherry-pick workflow.


CI States

Latest PR Test (Base): ❌ Missing run-ci label -- add it to run CI tests.
Latest PR Test (Extra): ❌ Blocked -- run-ci is required first.

Co-authored-by: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request fixes a critical bug in the DeepSeekV4 memory pool where the SWA location cache was not invalidated when a new index mapping was registered. This stale cache could lead to incorrect memory writes or out-of-bounds access crashes. The fix introduces an invalidate_loc_cache method and ensures the cache is cleared during mapping registration. Several regression tests were added to cover the bug scenario, end-to-end behavior, and potential crashes. Review feedback suggests improving maintainability by calling the new invalidation method within register_mapping and adding a docstring to the public method for better documentation.


def register_mapping(self, full_to_swa_index_mapping: torch.Tensor):
self.full_to_swa_index_mapping = full_to_swa_index_mapping
self.cached_loc = None # mapping replaced; discard any cached translation

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To avoid logic duplication and improve maintainability, consider calling invalidate_loc_cache() here instead of directly setting self.cached_loc = None.

Suggested change
self.cached_loc = None # mapping replaced; discard any cached translation
self.invalidate_loc_cache() # mapping replaced; discard any cached translation

Comment on lines +489 to +490
def invalidate_loc_cache(self) -> None:
self.cached_loc = None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Add a docstring to explain the purpose of this new public method. Additionally, consider adding this method to the BaseSWAKVPool abstract base class to provide a consistent interface for invalidating SWA-related caches across different pool implementations.

Suggested change
def invalidate_loc_cache(self) -> None:
self.cached_loc = None
def invalidate_loc_cache(self) -> None:
"""Invalidate the cached SWA location translation."""
self.cached_loc = None

@Kangyan-Zhou
Kangyan-Zhou merged commit fd10d3e into release/v0.5.12 May 22, 2026
4 checks passed
@Kangyan-Zhou
Kangyan-Zhou deleted the cherry-pick/888a8794e-to-v0.5.12-0a216ed2 branch May 22, 2026 08:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cherry-pick deepseek hicache Hierarchical Caching for SGLang

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants