Fix GRPOTrainer vLLM prompt token expansion bug with VLMs (#6294)#6300
Fix GRPOTrainer vLLM prompt token expansion bug with VLMs (#6294)#6300Saurav-Gupta-9741 wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit dee50fe. Configure here.
|
Hi @kashif Sir and @lewtun Sir, I hope you're both doing well! I have implemented a fix for the vLLM multimodal token expansion bug that was thoroughly detailed by @Strongich Sir in #6294. The PR is now ready for review. Could one of you please approve the workflows so the GPU tests can run? I am very much looking forward to your feedback. If there are any changes or improvements you would like me to make to align better with the codebase, please let me know and I will update it right away! Thank you for your time and the incredible work you do on this repository. |

What does this PR do?
Fixes #6294
Currently, when using
GRPOTrainerwithuse_vllm=Truefor multimodal models (like SmolVLM), the image processor expands the<image>token into multiple image features (e.g. 729 tokens) before passing them to vLLM. vLLM then receives these already-expanded token IDs but applies its own prompt updates, causing the first image feature token to be re-expanded into another huge block of tokens. This corrupts the prompt and leads to garbage generation rollouts.This PR implements the fix by allowing
_tokenize_promptsto generate a pure, text-only set ofvllm_prompt_ids(withadd_special_tokens=False) before the image processor artificially expands them. These unexpanded tokens are now safely passed directly tovllm_generation.generate().Before submitting
AI writing disclosure
We welcome the use of AI tools to help with contributions. For transparency and to help us improve our review process, please indicate the level of AI involvement in this PR.
Who can review?
Anyone in the community is free to review the PR once the tests have passed.
Note
Medium Risk
Changes only the vLLM generation input for conversational multimodal prompts; text-only and non-vLLM paths are unchanged, but GRPO rollouts depend on correct prompt/image alignment with vLLM.
Overview
Fixes corrupted vLLM rollouts when GRPOTrainer runs multimodal models (e.g. SmolVLM) with
use_vllm=True: the VLM processor was expanding<image>into hundreds of feature tokens before vLLM, and vLLM expanded again on top of that._tokenize_promptsnow also returnsvllm_prompt_ids. When vLLM is on and the batch has images, those IDs come from the chat template as plain text (tokenize=False) plus tokenizer encoding withadd_special_tokens=False—before the full processor run that inflates image tokens. Expandedprompt_idsandmultimodal_fieldsare unchanged for the training-model forward path._generate_single_turnpassesvllm_prompt_idsintovllm_generation.generateinstead of the processor-expanded lists;_generatethreads the new return value through the default rollout path.Reviewed by Cursor Bugbot for commit e3c2772. Bugbot is set up for automated code reviews on this repo. Configure here.