Skip to content

[Sampler] Support returning all logprobs or logits#21792

Merged
vllm-bot merged 8 commits intovllm-project:mainfrom
22quinn:more-logprobs
Aug 4, 2025
Merged

[Sampler] Support returning all logprobs or logits#21792
vllm-bot merged 8 commits intovllm-project:mainfrom
22quinn:more-logprobs

Conversation

@22quinn
Copy link
Copy Markdown
Collaborator

@22quinn 22quinn commented Jul 28, 2025

Essential Elements of an Effective PR Description Checklist

  • The purpose of the PR, such as "Fix some issue (link existing issues this PR will resolve)".
  • The test plan, such as providing test command.
  • The test results, such as pasting the results comparison before and after, or e2e results
  • (Optional) The necessary documentation update, such as updating supported_models.md and examples for a new model.

Purpose

Often for numerical benchmark and debugging purpose, we need to get all the logits or logprobs (controlled by logprobs_mode). This PR supports returning all of them, of vocab_size length, if SampleingParams.logprobs=-1 and ModelConfig.max_logprobs=-1

Test Plan

pytest tests/v1/sample/test_logprobs.py -k 'test_all_logprobs'

Test Result

Test passed

(Optional) Documentation Update

22quinn added 4 commits July 28, 2025 00:04
Signed-off-by: 22quinn <33176974+22quinn@users.noreply.github.com>
Signed-off-by: 22quinn <33176974+22quinn@users.noreply.github.com>
Signed-off-by: 22quinn <33176974+22quinn@users.noreply.github.com>
Signed-off-by: 22quinn <33176974+22quinn@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown

👋 Hi! Thank you for contributing to the vLLM project.

💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels.

Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run fastcheck CI which starts running only a small and essential subset of CI tests to quickly catch errors. You can run other CI tests on top of those by going to your fastcheck build on Buildkite UI (linked in the PR checks section) and unblock them. If you do not have permission to unblock, ping simon-mo or khluu to add you in our Buildkite org.

Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging.

To run CI, PR reviewers can either: Add ready label to the PR or enable auto-merge.

🚀

@mergify mergify bot added the v1 label Jul 28, 2025
Copy link
Copy Markdown
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 introduces support for returning all logprobs or logits by setting logprobs=-1. The changes are well-contained and include updates to configuration, validation, and worker logic, along with a new test case.

My review identified a critical bug in the validation logic. The current implementation would incorrectly allow a request with logprobs=-1 even when the engine has a max_logprobs limit set, which could lead to unexpected resource consumption. I've provided a code suggestion to fix this validation logic. The rest of the implementation appears correct and effectively adds the desired functionality.

Signed-off-by: 22quinn <33176974+22quinn@users.noreply.github.com>
@DarkLight1337
Copy link
Copy Markdown
Member

cc @njhill

Signed-off-by: 22quinn <33176974+22quinn@users.noreply.github.com>
@22quinn 22quinn added the ready ONLY add when PR is ready to merge/full CI is needed label Jul 30, 2025
Copy link
Copy Markdown
Collaborator

@houseroad houseroad left a comment

Choose a reason for hiding this comment

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

why do we want to return all the logits? This can easily run into OOM, right?

Copy link
Copy Markdown
Member

@njhill njhill left a comment

Choose a reason for hiding this comment

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

This looks reasonable to me but would be good to get some more opinions.

why do we want to return all the logits? This can easily run into OOM, right?

@houseroad yes I think it could cause significant performance problems in a multi-user production scenario but imo it's ok to support this for experimental purposes given that it needs to be explicitly enabled via the config.

@22quinn
Copy link
Copy Markdown
Collaborator Author

22quinn commented Jul 31, 2025

yea this is not for production but nice to provide an option for power users to get everything they want (e.g. for debugging).
Btw test failures look irrelevant

Copy link
Copy Markdown
Collaborator

@houseroad houseroad left a comment

Choose a reason for hiding this comment

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

Sure, I am fine with opt-in solution then. :-)

vllm/config.py Outdated
"""Maximum number of log probabilities to return when `logprobs` is
specified in `SamplingParams`. The default value comes the default for the
OpenAI Chat Completions API."""
OpenAI Chat Completions API. -1 means no cap."""
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.

Let's add a comment to explicitly call out that -1 is likely causing OOM?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

sounds good, updated

22quinn added 2 commits August 3, 2025 22:45
Signed-off-by: 22quinn <33176974+22quinn@users.noreply.github.com>
Signed-off-by: 22quinn <33176974+22quinn@users.noreply.github.com>
@vllm-bot vllm-bot merged commit 54de71d into vllm-project:main Aug 4, 2025
38 of 40 checks passed
npanpaliya pushed a commit to odh-on-pz/vllm-upstream that referenced this pull request Aug 6, 2025
Signed-off-by: 22quinn <33176974+22quinn@users.noreply.github.com>
myselvess pushed a commit to myselvess/vllm that referenced this pull request Aug 7, 2025
Signed-off-by: 22quinn <33176974+22quinn@users.noreply.github.com>
jinzhen-lin pushed a commit to jinzhen-lin/vllm that referenced this pull request Aug 9, 2025
Signed-off-by: 22quinn <33176974+22quinn@users.noreply.github.com>
Signed-off-by: Jinzhen Lin <linjinzhen@hotmail.com>
noamgat pushed a commit to noamgat/vllm that referenced this pull request Aug 9, 2025
Signed-off-by: 22quinn <33176974+22quinn@users.noreply.github.com>
Signed-off-by: Noam Gat <noamgat@gmail.com>
paulpak58 pushed a commit to paulpak58/vllm that referenced this pull request Aug 13, 2025
Signed-off-by: 22quinn <33176974+22quinn@users.noreply.github.com>
Signed-off-by: Paul Pak <paulpak58@gmail.com>
diegocastanibm pushed a commit to diegocastanibm/vllm that referenced this pull request Aug 15, 2025
Signed-off-by: 22quinn <33176974+22quinn@users.noreply.github.com>
Signed-off-by: Diego-Castan <diego.castan@ibm.com>
epwalsh pushed a commit to epwalsh/vllm that referenced this pull request Aug 28, 2025
Signed-off-by: 22quinn <33176974+22quinn@users.noreply.github.com>
zhewenl pushed a commit to zhewenl/vllm that referenced this pull request Aug 28, 2025
Signed-off-by: 22quinn <33176974+22quinn@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready ONLY add when PR is ready to merge/full CI is needed v1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants