Repository navigation
Inference: Reduce mamba scratch space size by an order of magnitude. - #5863
sidsingh-nvidia merged 13 commits into
Conversation
|
This PR has been automatically converted to draft because all PRs must start as drafts. When you are ready for review, click Ready for Review to begin the review process. This will:
See the contribution guide for more details. |
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
|
/claude strict-review |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/29983603449 |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/29989588761 |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/30002440463 |
What does this PR do?
When prefix caching is used, inference extracts mamba states into an intermediate scratch space before committing them to the dedicated prefix buffer. This scratch space is currently sized to hold 3 * MAX_REQUESTS mamba states, assuming a worst case where each request produces up to three states.
However, this is a significant overallocation. In a given engine step, we can only create max_tokens//block_size mamba states in the worst case. This is much smaller than the previous bound. For example, with max_requests=100, max_tokens=2048, and block_size=256: 3 * MAX_REQUESTS gives 300 scratch slots, while max_tokens//block_size gives only 8 - a ~37× reduction.
This PR tightens the upper bound to a function of max_tokens instead. This frees GPU memory that was previously reserved for scratch space, allowing more durable prefix cache slots to be allocated and thereby increasing the number of prefix caches that can be held in GPU memory.
Issue tracking
For PRs from open-source community contributors:
Linked issue:
Contribution process
Pre-checks
Code review
Feel free to message or comment @NVIDIA/mcore-oncall to help accelerate your merge into main. The less complex your PR is, the faster it will be approved and merged!
All PRs start as draft. If you open a non-draft PR, it will be automatically converted to draft.
Step 1: Mark PR as "Ready for Review"
.github/CODEOWNERS.Final Review might get declined if these requirements are not fulfilled.
Step 2: Final Review
For PRs that change
megatron/core, once all expert reviewers have approved, theFinal Reviewlabel is applied automatically and final reviewers are assigned.For PRs outside
megatron/core, this step is skipped.Step 3: Approved
Once all required reviewers have approved, the
Approvedlabel is applied automatically.Merge
Any member of mcore-engineers will be able to merge your PR.