vllm icon indicating copy to clipboard operation
vllm copied to clipboard

[Bugfix]: Fix messy code when using logprobs

Open chaunceyjiang opened this issue 6 months ago • 7 comments

FIX https://github.com/vllm-project/vllm/issues/19177

chaunceyjiang avatar Jun 05 '25 11:06 chaunceyjiang

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

🚀

github-actions[bot] avatar Jun 05 '25 11:06 github-actions[bot]

/cc @njhill PTAL

chaunceyjiang avatar Jun 06 '25 22:06 chaunceyjiang

test

from transformers import AutoTokenizer
from vllm.transformers_utils.detokenizer_utils import convert_ids_list_to_tokens
tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen2.5-1.5B-Instruct")
token_ids = tokenizer.encode("Hello, world!", add_special_tokens=True)
print(token_ids)
print(tokenizer.convert_ids_to_tokens([9707]))
print(tokenizer.convert_ids_to_tokens([11]))
print(tokenizer.convert_ids_to_tokens([1879]))
print(tokenizer.convert_ids_to_tokens([0]))
print(tokenizer.convert_ids_to_tokens(token_ids))
print("-----")
print(tokenizer.decode([9707]))
print(tokenizer.decode([11]))
print(tokenizer.decode([1879]))
print(tokenizer.decode([0]))
print("-----")
texts = convert_ids_list_to_tokens(tokenizer,[9707, 11, 1879, 0])
print(texts)

[9707, 11, 1879, 0]
['Hello']
[',']
['Ġworld']
['!']
['Hello', ',', 'Ġworld', '!']
-----
Hello
,
 world
!
-----
['Hello', ',', ' world', '!']

We can observe that using tokenizer.convert_ids_to_tokens() leads to messy code.

chaunceyjiang avatar Jun 17 '25 09:06 chaunceyjiang

@DarkLight1337 @ywang96 @ProExpertProg PTAL.

chaunceyjiang avatar Jun 17 '25 09:06 chaunceyjiang

Directly using tokenizer.convert_ids_to_tokens() does not produce human-readable text; it still needs to be passed through tokenizer.convert_tokens_to_string(). However, using tokenizer.decode() directly yields human-readable output.

Reference: https://github.com/huggingface/transformers/blob/main/src/transformers/tokenization_utils.py#L1090-L1115

chaunceyjiang avatar Jun 17 '25 14:06 chaunceyjiang

The CI failures look related to detokenize changes, PTAL

mgoin avatar Jun 20 '25 06:06 mgoin

The CI failures look related to detokenize changes,

Yes. I'm currently investigating this issue.

chaunceyjiang avatar Jun 20 '25 06:06 chaunceyjiang

@chaunceyjiang Hi, any update for this? thanks.

ericg108 avatar Jul 01 '25 02:07 ericg108

Hi, @ericg108 I was on vacation last week. I will complete this PR this week.

chaunceyjiang avatar Jul 01 '25 02:07 chaunceyjiang

btw, is there any way to postprocess to get the expected token, like from the bytes array or messy code?

ericg108 avatar Jul 01 '25 03:07 ericg108

Hi, @ericg108 I was on vacation last week. I will complete this PR this week.

thank you for your kindly effort @chaunceyjiang

ericg108 avatar Jul 01 '25 08:07 ericg108

This pull request has merge conflicts that must be resolved before it can be merged. Please rebase the PR, @chaunceyjiang.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

mergify[bot] avatar Jul 07 '25 10:07 mergify[bot]

@DarkLight1337 @ywang96 The docker-build-image-cpu test failure is unrelated to my code. All other tests have passed. PTAL.

chaunceyjiang avatar Jul 08 '25 02:07 chaunceyjiang

I believe this PR broke mistral models: https://buildkite.com/organizations/vllm/analytics/suites/ci-1/tests/41bf2871-4779-8f39-b029-6db37181eed7?period=14days&tags=scm.branch%3Amain

DarkLight1337 avatar Jul 14 '25 07:07 DarkLight1337