Publish Mamba state at aligned chunk endpoints - #38
Open
lmcafee-nvidia wants to merge 4 commits into
Open
Conversation
Signed-off-by: Lawrence McAfee <lmcafee@nvidia.com>
Signed-off-by: Lawrence McAfee <lmcafee@nvidia.com> # Conflicts: # examples/inference/advanced/gpt_dynamic_inference.py # tests/test_utils/recipes/h100/prefix-cache-stress.yaml
Signed-off-by: Lawrence McAfee <lmcafee@nvidia.com>
Signed-off-by: Lawrence McAfee <lmcafee@nvidia.com>
lmcafee-nvidia
marked this pull request as ready for review
August 14, 2026 23:04
lmcafee-nvidia
requested review from
santhnm2
and removed request for
santhnm2
August 14, 2026 23:04
Owner
Author
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.
What does this PR do?
This PR publishes reusable Mamba state whenever a cacheable prefill chunk ends exactly on a KV-block boundary, including when more prompt chunks remain. The previous direct-publication path covered only the final prompt boundary, while intermediate extraction cannot represent a state whose offset is the end of the current chunk. The PR also avoids staging Mamba state when a request has no usable prefix hashes, because such state can never be found by a later request.
Example failure scenario(s)
Scenario 1 (aligned boundary)
Scenario 2 (request opts out)
How was this bug discovered?
A hybrid chunk test processed a non-final chunk ending exactly on a block boundary, then submitted a follower request with the same prefix. The follower matched the KV blocks but did not restore the saved Mamba state; the expected result was exact restoration at that reusable boundary. The oracle was the allocator's publication/restoration state together with the restored Mamba tensors. A separate cache-disabled check observed durable slot use even though no prefix hashes existed, where the expected slot count was unchanged.
Dependency and scope
Depends on NVIDIA#6418. This fork PR remains based on the corresponding
prefix-cache-core-stressbranch.Relative to that base, the PR changes only:
megatron/core/inference/contexts/dynamic_context.pymegatron/core/inference/contexts/mamba_slot_allocator.pytests/unit_tests/inference/contexts/test_dynamic_prefix_caching.py(+85unit-test lines)It adds no functional tests, recipes, or unrelated production changes; comprehensive pairwise coverage remains in GPU unit tests.
Validation
15519939at exact SHA3acfb17acc: all three focused tests passed on every one of 8 ranks (24rank-local passes):git diff --check fork/prefix-cache-core-stress..HEAD