Skip to content

Conversation

@linfeng-yuan
Copy link
Collaborator

@linfeng-yuan linfeng-yuan commented Nov 12, 2025

What this PR does / why we need it?

Does this PR introduce any user-facing change?

How was this patch tested?

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 updates the _apply_top_k_top_p sampler function to leverage the npu_top_k_top_p operator when either k (top-k) or p (top-p) parameters are None. While the change correctly broadens the conditions for using the optimized NPU kernel, it introduces a potential for a runtime crash. My review focuses on a critical fix to handle empty tensors safely.

# npu_top_k_top_p uses the operator aclnnApplyTopKTopP, but aclnnApplyTopKTopP currently does not support 310P
if not is_310p():
# npu_top_k_top_p requires parameter k ranged from 1 to 1024
if k is None or 1 <= int(k.max()) <= 1024:
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

This condition is unsafe. If k is a non-None but empty tensor, k.max() will raise a RuntimeError, causing a crash. Please add a check to ensure the tensor is not empty before calling .max().

Suggested change
if k is None or 1 <= int(k.max()) <= 1024:
if k is None or (k.numel() > 0 and 1 <= int(k.max()) <= 1024):

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

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant