Skip to content

[Feature][MRV2][310P] Add temperature / top-k / top-p sampling for MRV2 on the 310P - #16503

Merged
Tflowers-0129 merged 5 commits into
vllm-project:mainfrom
Thiagor2002:mrv2_310p_post
Sep 15, 2026
Merged

Tflowers-0129 merged 5 commits into
vllm-project:mainfrom
Thiagor2002:mrv2_310p_post

Conversation

@Thiagor2002

@Thiagor2002 Thiagor2002 commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

What this PR does / why we need it?

Enable temperature / top-k / top-p sampling on Ascend 310P Model Runner V2.

  • First-version Ascend310PSampler only supported greedy (argmax) and rejected non-zero temperature.
  • Mainline MRV2 uses Triton Gumbel sampling; 310P has no Triton, and NPU exponential_ / large RNG can hang under ACLGraph (same issue fixed in MRV1).
  • This PR reuses the MRV1 inverse-CDF path (_random_sample_310p: CPU uniform per request → NPU softmax + cumsum + searchsorted), while keeping the MRV2 sampling_states surface required by MTP draft propose().
  • Still rejects min_p / penalties / logprobs / logit processors (follow-up).

Refs: MRV1 post-sampling fixes (#8017 / #8077), CDF optimization (#12966).

RFC: #15577

Does this PR introduce any user-facing change?

No. On 310P with VLLM_USE_V2_MODEL_RUNNER=1, requests may now use temperature, top_k, and top_p (previously raised NotImplementedError). Default greedy behavior is unchanged.

How was this patch tested?

  • UT: tests/ut/_310p/test_model_runner_v2_310p.py (temperature accept / scale / greedy; still rejects penalties)

  • vLLM main: vllm-project/vllm@84030bb

@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 enhances the Ascend 310P MRV2 sampler by aligning its sampling capabilities with MRV1. It introduces support for temperature, top-k, and top-p sampling, ensuring that these parameters are correctly processed and applied during inference. The changes include refactoring the sampler to maintain compatibility with MTP draft requirements and adding robust handling for various sampling configurations, while maintaining a fast path for standard greedy decoding.

Highlights

  • Sampling Parameter Alignment: Aligned temperature, top-k, and top-p sampling logic with MRV1 standards for the Ascend 310P platform.
  • Sampler Refactoring: Updated the Ascend310PSampler to expose necessary sampling states for MTP draft propose() and added support for non-greedy sampling.
  • Logits Processing: Implemented PyTorch-based temperature scaling and integrated top-k/top-p filtering to support advanced sampling parameters.
  • Testing: Added comprehensive unit tests to verify temperature scaling, greedy sampling, and parameter rejection logic.
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. ↩

@Thiagor2002 Thiagor2002 changed the title [Feature][MRV2][310P] Add temperature / top-k / top-p sampling aligne… [Feature][MRV2][310P] Add temperature / top-k / top-p sampling for MRV2 on the 310P Sep 14, 2026
@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 [Feature] 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!

…d with MRV1 on the 310P

Signed-off-by: Thiagor2002 <13476117628@163.com>

@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 implements a Triton-free MRV2 sampler for Ascend 310P, aligning temperature, top-k, and top-p post-processing with MRV1's AscendSampler310 while keeping the MRV2 sampling_states surface. The review feedback highlights a potential division-by-zero issue on Ascend NPUs when mixing greedy and random sampling, and a bug where an explicit top_k = 1 can be overwritten during late-binding of the vocabulary size. It is recommended to initialize unset top_k values to -1 instead of 1 to distinguish them, and to add a regression test. Additionally, the PR title and description should be updated to follow the repository style guide.\n\nSuggested PR Title:\n\nmarkdown\n[Ops][Feature] Add temperature / top-k / top-p sampling aligned with MRV1 on the 310P\n\n\nSuggested PR Summary:\n\nmarkdown\n### What this PR does / why we need it?\n\nThis PR implements a Triton-free MRV2 sampler for Ascend 310P. It aligns temperature, top-k, and top-p post-processing with MRV1's `AscendSampler310` (inverse-CDF random sampling) while keeping the MRV2 `sampling_states` surface required by MTP draft `propose()`.\n\n### Does this PR introduce _any_ user-facing change?\n\nNo.\n\n### How was this patch tested?\n\nTested with unit tests in `tests/ut/_310p/test_model_runner_v2_310p.py` including:\n- `test_sampler_accepts_temperature_and_rejects_penalties`\n- `test_sampler_temperature_scales_logits_before_argmax`\n- `test_sampler_greedy_call_returns_argmax`\n

Comment thread vllm_ascend/_310p/worker/v2/sampler.py
Comment thread vllm_ascend/_310p/worker/v2/sampler.py
Comment thread vllm_ascend/_310p/worker/v2/sampler.py
Comment thread vllm_ascend/_310p/worker/v2/sampler.py
Comment thread vllm_ascend/_310p/worker/v2/sampler.py
Comment thread vllm_ascend/_310p/worker/v2/sampler.py
Comment thread tests/ut/_310p/test_model_runner_v2_310p.py
Signed-off-by: Thiagor2002 <13476117628@163.com>
Signed-off-by: Thiagor2002 <13476117628@163.com>
Signed-off-by: Thiagor2002 <13476117628@163.com>
@Tflowers-0129 Tflowers-0129 added the ready-precise run selected e2e test for pr label Sep 14, 2026

@linfeng-yuan linfeng-yuan left a comment

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.

Please add e2e test for sampling.

Signed-off-by: Thiagor2002 <13476117628@163.com>
@Thiagor2002

Thiagor2002 commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor Author

/rerun
[Bot]: rerun completed.

Rerun (failed jobs only):

  • E2E

@Tflowers-0129
Tflowers-0129 merged commit f83fe89 into vllm-project:main Sep 15, 2026
31 of 33 checks passed
@Thiagor2002
Thiagor2002 deleted the mrv2_310p_post branch September 15, 2026 12:44
@Thiagor2002

Copy link
Copy Markdown
Contributor Author

Please add e2e test for sampling.

i have added e2e test in the newest commit.

UniversePeak added a commit to UniversePeak/vllm-ascend that referenced this pull request Sep 17, 2026
Preserve upstream temperature/top-k/top-p sampling tests and the existing unsupported-parameter coverage. Drop only the obsolete top-k/top-p rejection cases now supported by upstream vllm-project#16503, and adjust their comment.

Signed-off-by: UniversePeak <UniversePeak@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module:tests ready-precise run selected e2e test for pr

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants