Skip to content

Support tool-returned images across VLM architectures - #6906

Open
DaoyuanLi2816 wants to merge 1 commit into
huggingface:mainfrom
DaoyuanLi2816:fix/gemma-tool-image-token
Open

Support tool-returned images across VLM architectures#6906
DaoyuanLi2816 wants to merge 1 commit into
huggingface:mainfrom
DaoyuanLi2816:fix/gemma-tool-image-token

Conversation

@DaoyuanLi2816

@DaoyuanLi2816 DaoyuanLi2816 commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

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 rebuilt mm_token_type_ids contain 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 deselected for Gemma 3/Gemma 4 GRPO and Distillation VLM training
  • 2 passed for the GRPO and Distillation multimodal tool-response tests
  • focused Ruff check and format check
  • git diff --check

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline, Pull Request section?
  • Was this discussed/approved via a GitHub issue? Please add a link to it if that's the case.
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests?

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.

  • No AI usage: the PR was written entirely by a human.
  • AI-assisted: some parts were suggested or improved by AI, but the PR was written and reviewed by a human.
  • AI-generated: the PR was mostly or fully generated by an AI tool.

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.py and test_distillation_trainer.py parametrize the expected placeholder per architecture and assert it matches trainer._image_token_id after init.

Reviewed by Cursor Bugbot for commit 7cbff6b. Bugbot is set up for automated code reviews on this repo. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant