TensorRT-LLM icon indicating copy to clipboard operation
TensorRT-LLM copied to clipboard

[Bug]: MS Phi-4 Multimodal requires stop_words_list handling to prevent unnecessary token generation

Open moku opened this issue 1 year ago • 6 comments

System Info

Device: Jetson Orin AGX (64GB)

OS / SDK: JetPack 6.2.1, Ubuntu 22.04

TensorRT-LLM: v0.21

Model: MS Phi-4 Multimodal

Who can help?

No response

Information

  • [x] The official example scripts
  • [ ] My own modified scripts

Tasks

  • [x] An officially supported task in the examples folder (such as GLUE/SQuAD, ...)
  • [ ] My own task or dataset (give details below)

Reproduction

run the example of Phi-4-multimodal with --run_profiling option

Expected behavior

The model generates only response to my prompt.

actual behavior

Regardless of the input prompt, the model always generates exactly max_new_tokens tokens. After expected response, irregular texts are appended. Below is one of exmple. 'The image shows a stunning view of the Marina Bay Sands in Singapore, with the iconic Marina Bay Sands hotel and its two iconic towers, known as the "Eye of the Storm" and the "Infinity Pool," illuminated against a backdrop of a beautiful sunset. In the foreground, there is a majestic stone sculpture of the Chinese dragon, known as the "Lion Dance," which is a symbol of good luck and prosperity. The image also features a tranquil water scene with a fountain, creating a serene and picturesque atmosphere. The overall scene captures the beauty and modernity of Singapore's skyline at dusk.The image shows a stunning view of the Marina Bay Sands in Singapore, with the iconic Marina Bay Sands hotel and its two iconic towers, known as the "Eye of the Storm" and the "Infinity Pool," illuminated against a backdrop of a beautiful sunset. In the foreground, there is a majestic stone sculpture of the Chinese dragon, known as the "Lion Dance," which is a symbol of good luck and prosperity. The image also features a tranquil water scene with a fountain, creating a serene and picturesque atmosphere. The overall scene captures the beauty and modernity of Singapore's skyline at dusk.The image shows a stunning view of the Marina Bay Sands in Singapore, with the iconic Marina Bay Sands hotel and its two iconic towers, known as the "Eye of the Storm" and the "Infinity Pool," illuminated against a backdrop of a beautiful sunset. In the foreground, there is a majestic stone sculpture of the Chinese dragon, known as the "Lion Dance," which is a symbol of good luck and prosperity. The image also features a tranquil water scene with a fountain, creating a serene and picturesque atmosphere. The overall scene captures the beauty and modernity of Singapore's skyline at dusk.The image shows a stunning view of the Marina Bay Sands in Singapore, with the iconic Marina Bay Sands hotel and its two iconic towers, known as the "Eye of the Storm" and the "Infinity Pool," illuminated against a backdrop of a beautiful sunset. In the foreground, there is a majestic stone sculpture of the Chinese dragon, known as the "Lion Dance," which is a symbol of good luck and prosperity. The image also features a tranquil water scene with a fountain, creating a serene and picturesque atmosphere. The overall scene captures the beauty and modernity of Singapore's skyline at dusk.The image shows a stunning view of the Marina Bay Sands in Singapore, with the iconic Marina Bay Sands hotel and its two iconic towers, known as the "Eye'

additional notes

Root Cause

In MS Phi-4 Multimodal, when the generation should stop, the model returns the <|USER|> token (200020) instead of the standard EOS token (eos_id=199999).

Currently, the MultimodalModelRunner class does not handle this case, so generation continues until max_new_tokens is reached, causing unnecessary tokens to be produced.

Proposed Fix

In the MultimodalModelRunner class, when using MS Phi-4 Multimodal, add the argument stop_words_list=[[[200020]]] to the self.model.generate call so generation stops correctly when <|USER|> is encountered.

Before submitting a new issue...

  • [x] Make sure you already searched for relevant issues, and checked the documentation and examples for answers to frequently asked questions.

moku avatar Aug 27 '25 18:08 moku

@kaiyux , could you review this request of stop_words_list support in MultimodalModelRunner?

karljang avatar Aug 28 '25 17:08 karljang

@dcampora , could you please take a look at this?

MartinMarciniszyn avatar Sep 02 '25 13:09 MartinMarciniszyn

@evezhier could you please have a look? Thanks

dcampora avatar Nov 13 '25 08:11 dcampora

Hi @moku, could you please rerun your test with the latest code? I think the issue is solved now:) The issue of stop tokens was fixed by this PR#10389. I have tested a simple demo, and the token id 200020 is correctly set in the stop words of the sampler now. Just like your proposal. cc @evezhier

JadoTu avatar Jan 15 '26 08:01 JadoTu

I can confirm stop words are now respected.

evezhier avatar Jan 16 '26 12:01 evezhier

I test it again and the problem is solved. Now I close this issue. Thank you for noticing me.

moku avatar Jan 16 '26 12:01 moku