Support tool-returned images across VLM architectures - #6906
Open
DaoyuanLi2816 wants to merge 1 commit into
Open
Support tool-returned images across VLM architectures#6906DaoyuanLi2816 wants to merge 1 commit into
DaoyuanLi2816 wants to merge 1 commit into
Conversation
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?
Follow up on the multimodal tool-response path added in #6723 by resolving the image placeholder used by each supported VLM family.
The current code recognizes only
<|image_pad|>and<|image|>. Gemma 3, InternVL, and LLaVA use<image_soft_token>,<IMG_CONTEXT>, and<image>respectively, so their rebuiltmm_token_type_idscontain no image positions after a tool returns an image. This change keeps the trainer-local logic aligned in GRPO and Distillation and extends the existing VLM matrices to pin the expected placeholder for every covered architecture.Validation:
4 passed, 12 deselectedfor Gemma 3/Gemma 4 GRPO and Distillation VLM training2 passedfor the GRPO and Distillation multimodal tool-response testsgit diff --checkBefore 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
Touches multimodal forward/generate wiring for tool images across several VLM families; wrong token resolution could silently mis-tag image tokens, but scope is limited to the new candidate list and existing tool-image paths.
Overview
Extends GRPO and Distillation VLM handling so tool-returned images mark the correct positions in rebuilt
mm_token_type_ids/token_type_ids, not only Qwen/Gemma-style<|image_pad|>/<|image|>.Trainers now probe a fixed candidate list (
<IMG_CONTEXT>,<image_soft_token>,<image>,<|image|>,<|image_pad|>) and store the first valid ID in_image_token_id(renamed from_image_pad_token_id). That ID is used everywhere image positions are flagged during generation and forward when tools inject images into completions.VLM matrix tests in
test_grpo_trainer.pyandtest_distillation_trainer.pyparametrize the expected placeholder per architecture and assert it matchestrainer._image_token_idafter init.Reviewed by Cursor Bugbot for commit 7cbff6b. Bugbot is set up for automated code reviews on this repo. Configure here.