Skip to content

Conversation

@zouyida2052
Copy link
Contributor

@zouyida2052 zouyida2052 commented Oct 31, 2025

What this PR does / why we need it?

correct bug to fix the value of max_num_tokens

Does this PR introduce any user-facing change?

no

How was this patch tested?

Signed-off-by: zouyida2052 <zouyida2002@gmail.com>
@github-actions
Copy link

👋 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.

Copy link
Contributor

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

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 calculation of max_num_tokens within the NPUTorchairModelRunner. The original code incorrectly used the tensor parallel size, which resulted in a wrong capacity calculation for mc2_tokens_capacity. This could lead to incorrect behavior or performance issues, especially for MoE models. The proposed change correctly computes max_num_tokens using the maximum number of requests and the decode query length, aligning with the intended logic and fixing the bug. The change is correct and necessary.

# NOTE: To be clear, we need to make sure that during graph capture, the number of
# tokens is less than or equal to mc2_tokens_capacity. According to _set_cudagraph_sizes,
# the max number of tokens in graph is min(max_num_seqs * uniform_decode_query_len, 512).
max_num_tokens = self.parallel_config.tensor_parallel_size
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

The calculation for max_num_tokens was incorrect. It was set to the tensor parallel size, which is not related to the number of tokens. This leads to an incorrect mc2_tokens_capacity, which can cause issues with MoE communication strategy selection and other capacity-dependent logic. The fix correctly calculates it based on the maximum number of requests and the uniform decode query length.

Suggested change
max_num_tokens = self.parallel_config.tensor_parallel_size
max_num_tokens = self.max_num_reqs * self.uniform_decode_query_len

@wangxiyuan wangxiyuan added ready read for review ready-for-test start test by label for PR labels Oct 31, 2025
@MengqingCao MengqingCao merged commit ec98320 into vllm-project:main Nov 3, 2025
50 of 51 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready read for review ready-for-test start test by label for PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants