Skip to content

[Bugfix] Decode Tokenized IDs to Strings for hf_processor in llm.chat() with model_impl=transformers #21353

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 22, 2025

Conversation

ariG23498
Copy link
Contributor

@ariG23498 ariG23498 commented Jul 22, 2025

This PR adds a check in the llm.chat() processing logic to decode tokenized IDs back to strings when using model_impl="transformers". This ensures compatibility with the Hugging Face processor (hf_processor), which expects string inputs and does not support raw token IDs.

To verify the issue without this fix (or confirm the fix works), use the following code:

from vllm import LLM

model_id = "llava-hf/llava-onevision-qwen2-0.5b-ov-hf"
vlm = LLM(
    model=model_id,
    model_impl="transformers",
    disable_mm_preprocessor_cache=True,
    enable_prefix_caching=False,
    enable_chunked_prefill=False
)

image_url = "http://images.cocodataset.org/val2017/000000039769.jpg"
conversation = [
    {
        "role": "user",
        "content": [
            {"type": "image_url", "image_url": {"url": image_url}},
            {"type": "text", "text": "What is the content of this image?"}
        ],
    },
]

# Perform inference and log output.
outputs = vlm.chat(conversation)

for o in outputs:
    generated_text = o.outputs[0].text
    print(generated_text)
  • Without fix: Expect errors due to tokenized IDs being passed to hf_processor.
  • With fix: Inference should succeed, printing a description of the image (e.g., cats on a couch).

CC: @hmellor @zucchini-nlp

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 PR addresses an issue where tokenized IDs were passed to a Hugging Face processor that expects string inputs. The fix correctly decodes the IDs to strings. My review focuses on improving the robustness of the implementation by avoiding in-place modification of input data, which could lead to unexpected side effects or errors.

Copy link

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

🚀

@ariG23498
Copy link
Contributor Author

@DarkLight1337 I have modified the file as suggested.

Copy link
Member

@DarkLight1337 DarkLight1337 left a comment

Choose a reason for hiding this comment

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

Thanks for the fix! Can you also add a test case in tests/models/multimodal/processing to avoid regression? cc @Isotr0py @hmellor

Copy link
Collaborator

@Isotr0py Isotr0py left a comment

Choose a reason for hiding this comment

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

LGTM too as long as regression test added!

@ariG23498 ariG23498 requested a review from ywang96 as a code owner July 22, 2025 09:36
@mergify mergify bot added the multi-modality Related to multi-modality (#4194) label Jul 22, 2025
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am pretty sure this does not fit the bill for the processing only dir. Any pointers would be great.

Copy link
Member

Choose a reason for hiding this comment

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

You can create a new file called test_transformers.py

Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't the test case for this PR test that the MultiModalProcessor in vllm/model_executor/models/transformers.py still works when token IDs are provided to apply?

Copy link
Member

@DarkLight1337 DarkLight1337 Jul 22, 2025

Choose a reason for hiding this comment

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

We are testing the multi-modal processor here rather than the model implementation, so the test should be under processing directory. The other tests under processing directory also only check the multi-modal processor

Copy link
Member

Choose a reason for hiding this comment

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

And like @hmellor said, we should be unit testing the multi-modal processor without instantiating vLLM engine

Copy link
Member

@hmellor hmellor left a comment

Choose a reason for hiding this comment

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

The fix LGTM, but I think we should change the test to be more specific to the problem we're fixing. Instantiating a full LLM is quite an expensive way to check that the processor can consume token IDs

Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't the test case for this PR test that the MultiModalProcessor in vllm/model_executor/models/transformers.py still works when token IDs are provided to apply?

@ariG23498 ariG23498 requested a review from DarkLight1337 July 22, 2025 11:03
@DarkLight1337 DarkLight1337 enabled auto-merge (squash) July 22, 2025 11:20
@github-actions github-actions bot added the ready ONLY add when PR is ready to merge/full CI is needed label Jul 22, 2025
@DarkLight1337
Copy link
Member

Please fix pre-commit

auto-merge was automatically disabled July 22, 2025 12:44

Head branch was pushed to by a user without write access

Signed-off-by: ariG23498 <[email protected]>
Signed-off-by: ariG23498 <[email protected]>
Signed-off-by: ariG23498 <[email protected]>
Signed-off-by: ariG23498 <[email protected]>
Signed-off-by: ariG23498 <[email protected]>
@DarkLight1337 DarkLight1337 enabled auto-merge (squash) July 22, 2025 12:46
@DarkLight1337 DarkLight1337 changed the title Decode Tokenized IDs to Strings for hf_processor in llm.chat() with model_impl=transformers [Bugfix] Decode Tokenized IDs to Strings for hf_processor in llm.chat() with model_impl=transformers Jul 22, 2025
@DarkLight1337 DarkLight1337 disabled auto-merge July 22, 2025 15:19
@vllm-bot vllm-bot merged commit 2226d5b into vllm-project:main Jul 22, 2025
67 of 71 checks passed
yeqcharlotte pushed a commit to yeqcharlotte/vllm that referenced this pull request Jul 23, 2025
…hat()` with `model_impl=transformers` (vllm-project#21353)

Signed-off-by: ariG23498 <[email protected]>
zixi-qi pushed a commit to zixi-qi/vllm that referenced this pull request Jul 23, 2025
…hat()` with `model_impl=transformers` (vllm-project#21353)

Signed-off-by: ariG23498 <[email protected]>
Signed-off-by: qizixi <[email protected]>
LyrisZhong pushed a commit to LyrisZhong/vllm that referenced this pull request Jul 23, 2025
…hat()` with `model_impl=transformers` (vllm-project#21353)

Signed-off-by: ariG23498 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
multi-modality Related to multi-modality (#4194) ready ONLY add when PR is ready to merge/full CI is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants