fix(vllm): record logprob for the sampled token - #3297
Merged
Conversation
Fix vLLM generation output processing to record the log probability of the
token actually sampled, rather than relying on the first entry in the
per-position logprob dictionary.
vLLM returns each generated position as a mapping from token ID to logprob
metadata. When that mapping contains multiple tokens, the first entry is not
guaranteed to be the sampled token.
For example, if token 880 was sampled:
{
512: Logprob(logprob=-0.10, rank=1),
880: Logprob(logprob=-2.30, rank=2),
}
The previous implementation recorded -0.10 by taking the first dictionary
entry. The correct value for the generated token is -2.30.
So Pair each generated token ID with its corresponding logprob dictionary and
look up the logprob by that token ID.
The behavior is unchanged when vLLM returns only the sampled token.
Signed-off-by: Hollow Man <hollowman@opensuse.org>
|
Auto-sync is disabled for ready for review pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
Contributor
Author
|
/ok to test bdb414e |
terrykong
approved these changes
Jul 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do ?
Record logprob for the sampled token
Issues
#2608 (comment)
Fix vLLM generation output processing to record the log probability of the token actually sampled, rather than relying on the first entry in the per-position logprob dictionary.
vLLM returns each generated position as a mapping from token ID to logprob metadata. When that mapping contains multiple tokens, the first entry is not guaranteed to be the sampled token.
For example, if token 880 was sampled:
{ 512: Logprob(logprob=-0.10, rank=1), 880: Logprob(logprob=-2.30, rank=2), }The previous implementation recorded -0.10 by taking the first dictionary entry. The correct value for the generated token is -2.30.
So Pair each generated token ID with its corresponding logprob dictionary and look up the logprob by that token ID.
The behavior is unchanged when vLLM returns only the sampled token.
Usage
# Add a code snippet demonstrating how to use thisBefore your PR is "Ready for review"
Pre checks:
Additional Information