Skip to content

[BugFix][MRv2] Bound pure decode memory profiling by decode capacity - #20244

Open
rikakuhi wants to merge 2 commits into
vllm-project:mainfrom
rikakuhi:fix/pd-decode-profile-token-capacity
Open

rikakuhi wants to merge 2 commits into
vllm-project:mainfrom
rikakuhi:fix/pd-decode-profile-token-capacity

Conversation

@rikakuhi

@rikakuhi rikakuhi commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

What this PR does / why we need it?

MRv2's initial memory profile uses max_num_batched_tokens, even on a pure decode KV consumer with recompute_scheduler_enable=true. Decode buffers can be smaller than that prefill budget. For example, DeepSeek V4.1 Flash with 64 sequences, five speculative tokens and a 1024-token scheduler budget has a 384-token MegaMoE symmetric buffer, but the standard profile forwards 1024 tokens and fails its capacity check.

Bound these initial memory dummy runs with the existing get_potential_max_tokens() capacity, request limit and scheduler budget, and pass uniform_decode=True with complete decode queries. The example profiles 64 requests of six tokens (384 tokens). An insufficient capacity for even one query raises a clear error.

This uses the existing Ascend _dummy_run extension point to cover both MC2 reservation and the upstream memory profile. It does not mutate scheduler limits or add state. Prefill, colocated serving, consumers without recompute scheduling, and normal graph capture retain their existing behavior. The new arithmetic runs only during initial decode memory profiling, outside the serving hot path.

This addresses the profiling batch/capacity mismatch separately from the target/drafter symmetric-storage sharing fix in #20234.

Does this PR introduce any user-facing change?

Yes. Pure decode MRv2 services no longer profile a prefill-sized batch against decode-sized buffers when recompute scheduling is enabled. No new configuration is required. A release note fragment is included.

How was this patch tested?

  • Added 17 regression and boundary cases in tests/ut/worker/test_model_runner_v2.py. They check the 1024/384 MegaMoE scenario, both profiling forwards, complete-query rounding, runtime limits, excluded dummy runs and forward failures.
  • CPU unit tests for the MRv2 model runner, Ascend forward context and MoE communication method passed with the paired vLLM main revision c410543d9ffff03f5f6c4a8c0ae1d3ad082c4a15 (499 passed, 1 skipped). All 17 new cases also passed with vLLM 0.33.0. NPU operations were mocked.
  • Range pre-commit, bash format.sh ci, and git diff --check passed.
  • NPU startup, PD inference and memory use remain to be validated on A5 with DeepSeek V4.1 Flash, DSpark, MegaMoE, recompute scheduling, 64 sequences, 5 speculative tokens and a 1024-token scheduler budget.

Checklist

Testing

  • Boundary / edge-case coverage: Added complete-query rounding, scheduler/capacity/request bounds and minimum-query cases.

  • Regression test: Added the reported 1024-token profile versus 384-token buffer scenario.

  • Error / failure path coverage: Added insufficient-capacity and parent-forward failure cases.

  • Meaningful & reliable tests: Assert forwarded batch shapes and unchanged runner budgets.

  • Performance impact: NPU memory profiling and PD inference validation remain pending with the reporter; no serving hot-path changes.

  • vLLM main: vllm-project/vllm@c410543

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a memory profiling mismatch in MRv2 where the initial dummy run incorrectly used prefill-sized token budgets for pure decode scenarios. By bounding the profiling tokens to the actual decode capacity, the system avoids unnecessary capacity check failures while maintaining existing behavior for other execution paths.

Highlights

  • Memory Profiling Fix: Constrained initial memory profiling to respect decode-specific buffer capacities, preventing failures in pure decode scenarios where the prefill-sized budget was previously used.
  • Regression Testing: Added 18 comprehensive test cases to cover boundary conditions, capacity limits, and error paths for decode memory profiling, ensuring robust validation of the new constraints.
New Features

🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@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 introduces changes to bound pure decode memory profiling by the actual decode capacity when the recompute scheduler is enabled. In model_runner.py, the _dummy_run method is updated to calculate profile_max_tokens based on the minimum of available tokens, the scheduler budget, and the potential maximum tokens, ensuring complete decode queries are profiled. Comprehensive unit tests have been added in test_model_runner_v2.py to validate these changes under various scenarios. The review feedback correctly identifies that the PR title violates the repository style guide and suggests renaming it to [MRv2][BugFix] Bound pure decode memory profiling by decode capacity along with providing a structured PR summary.

Comment thread vllm_ascend/worker/v2/model_runner.py Outdated
"""Balanced dummy routing for adaptive-verification profiling; EPLB
steps via ``step_eplb_after`` (#17233). The lmhead TP join lives in the
``execute_model`` tail — joining after ``super()._dummy_run`` deadlocks."""
if is_profile and skip_attn and not profile_cpp and is_pd_decode_recompute_scheduler_enabled(self.vllm_config):

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.

high

The PR Title does not follow the format specified in the Repository Style Guide. The current title is [BugFix][MRv2] Bound pure decode memory profiling by decode capacity, but the correct format is [Branch][Module][Action] Pull Request Title. Since the base branch is main, the branch prefix can be omitted, making the correct title [MRv2][BugFix] Bound pure decode memory profiling by decode capacity.\n\nPlease update the PR Title and Summary as suggested below:\n\nSuggested PR Title:\n\nmarkdown\n[MRv2][BugFix] Bound pure decode memory profiling by decode capacity\n\n\nSuggested PR Summary:\n\nmarkdown\n### What this PR does / why we need it?\n\nMRv2's initial memory profile uses `max_num_batched_tokens`, even on a pure decode KV consumer with `recompute_scheduler_enable=true`. Decode buffers can be smaller than that prefill budget. For example, DeepSeek V4.1 Flash with 64 sequences, five speculative tokens and a 1024-token scheduler budget has a 384-token MegaMoE symmetric buffer, but the standard profile forwards 1024 tokens and fails its capacity check.\n\nBound these initial memory dummy runs with the existing `get_potential_max_tokens()` capacity, request limit and scheduler budget, and pass `uniform_decode=True` with complete decode queries. The example profiles 64 requests of six tokens (384 tokens). An insufficient capacity for even one query raises a clear error.\n\nThis uses the existing Ascend `_dummy_run` extension point to cover both MC2 reservation and the upstream memory profile. It does not mutate scheduler limits or add state. Prefill, colocated serving, consumers without recompute scheduling, normal graph capture and CPP profiling retain their existing behavior. The new arithmetic runs only during initial decode memory profiling, outside the serving hot path.\n\nThis addresses the profiling batch/capacity mismatch separately from the target/drafter symmetric-storage sharing fix in #20234.\n\n### Does this PR introduce _any_ user-facing change?\n\nYes. Pure decode MRv2 services no longer profile a prefill-sized batch against decode-sized buffers when recompute scheduling is enabled. No new configuration is required. A release note fragment is included.\n\n### How was this patch tested?\n\n- Added 18 parameterized regression/boundary cases in `tests/ut/worker/test_model_runner_v2.py`: the 1024/384 MegaMoE failure, both profile forwards, uniform query alignment, capacity/request/scheduler bounds, single-query and non-speculative batches, excluded execution paths, and forward failures without changing runner limits. The integrated regression exercises a capacity-checking parent forward that rejects the original 1024-token batch.\n- `pre-commit run ruff-check --files vllm_ascend/worker/v2/model_runner.py tests/ut/worker/test_model_runner_v2.py --hook-stage manual`: passed.\n- Corresponding `ruff-format` hook and `git diff --check`: passed.\n- Full range pre-commit and `bash format.sh ci` were attempted; completion was blocked while initializing the actionlint hook environment. Full lint remains for CI.\n- **UTs and NPU/E2E tests were not run, at the request of the reporter, who will validate on A5 with DeepSeek V4.1 Flash, DSpark, MegaMoE and recompute scheduling enabled.** The intended hardware check is successful startup with `max_num_seqs=64`, `num_speculative_tokens=5`, `max_num_batched_tokens=1024`, followed by PD inference and memory-use checks. Static checks do not establish NPU correctness.\n

References
  1. The PR Title must follow the format [Branch][Module][Action] Pull Request Title. The current title [BugFix][MRv2] Bound pure decode memory profiling by decode capacity has the module and action swapped. It should be [MRv2][BugFix] Bound pure decode memory profiling by decode capacity. (link)

@github-actions

Copy link
Copy Markdown
Contributor

👋 Hi! Thank you for contributing to the vLLM Ascend project. The following points will speed up your PR merge:‌‌

  • A PR should do only one thing, smaller PRs enable faster reviews.
  • Every PR should include unit tests and end-to-end tests ‌to ensure it works and is not broken by other future PRs.
  • Write the commit message by fulfilling the PR description to help reviewer and future developers understand.

If CI fails, you can run linting and testing checks locally according Contributing and Testing.


Tip

💡 Consider Linking a Related Issue or RFC

Your PR title contains the [BugFix] tag, indicating a bug fix or new feature.

Linking a related issue or RFC in the PR description is strongly encouraged — it gives reviewers helpful context and speeds up the review. You can use any of these keywords:

  • Fixes #<issue_number>
  • Closes #<issue_number>
  • Resolves #<issue_number>
  • Refs #<rfc_or_issue_number> (for RFCs)

🙏 Thanks for helping us keep the project well-organized!

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has conflicts, please resolve those before we can evaluate the pull request.

7 similar comments
@github-actions

Copy link
Copy Markdown
Contributor

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has conflicts, please resolve those before we can evaluate the pull request.

Signed-off-by: rikakuhi <942697235@qq.com>
Signed-off-by: rikakuhi <942697235@qq.com>
"""Balanced dummy routing for adaptive-verification profiling; EPLB
steps via ``step_eplb_after`` (#17233). The lmhead TP join lives in the
``execute_model`` tail — joining after ``super()._dummy_run`` deadlocks."""
if is_profile and skip_attn and is_pd_decode_recompute_scheduler_enabled(self.vllm_config):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This appears to be an issue caused by operator restrictions, and these codes serve as a workaround for the problem. It is best to add a TODO comment before this code segment, specifying the root cause of the problem, the workaround, and the plan for resolution.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants