[GOLD] GOLDTrainer VLM support - #5461
Conversation
537cc13 to
9a1f345
Compare
|
@kashif @qgallouedec I think you guys might be interested in this PR, looking forward to hearing from u |
|
In 325f897, I added off-policy eval support for VLM distillation (GRPO-style 2. Qwen3-VL-8B -> LFM2.5-VL-1.6B, ULD, lmbda=0.5, no-vllm (cross-family) 3. Qwen3-VL-8B -> Qwen3-VL-2B, ULD, lmbda=0.5 LGTM |
| dtype=updated_slice[k].dtype, | ||
| device=new_input_ids.device, | ||
| ) | ||
| updated_slice[k] = torch.cat([prompt_part, comp_part], dim=1) |
There was a problem hiding this comment.
Non-vLLM text path overwrites ULD original_prompt_text with special tokens
Medium Severity
In _generate_non_vllm_for_slices, original_prompt_text is unconditionally set to prompt_texts which is decoded with skip_special_tokens=False, including student chat-template markers. In contrast, _generate_on_policy_vlm_slice correctly preserves the collator's untemplated text. When ULD loss re-tokenizes these with the teacher tokenizer, student-specific tokens like <|im_end|> are treated as literal text, producing spurious teacher tokens and misaligned logits.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit c187966. Configure here.
|
thanks @Strongich I am working on a refactoring of the tokenization byte-offset issue in this branch: https://github.com/kashif/trl/tree/fix-issue-4393-byte-offsets for issue #4393 so perhaps your feature can also be added to my fix? what do you think? |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.
There are 4 total unresolved issues (including 2 from previous reviews).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 030a831. Configure here.
|
Hi @kashif, sounds good. I'm currently updating the readability of my code, and once I have the time, I will take a look at this issue (maybe something from my imp needs to be addressed too) |
|
@kashif took a look, pretty clear: since the to_canonical_pieces are gone, and ULDLoss signature is changed, let me know when ur branch will be stable enough for me to port VLM features onto it |
|
@Strongich i haved added you to my fork so you can try to add VLM support to the refactor if you like? |
|
This PR will be closed & a clean one will be opened once the #5885 is merged into main |
|
thanks @Strongich looking forward! |
|
Closed in favor of #5969 |





What does this PR do?
Adds VLM support to GOLDTrainer:
examples/scripts/gold_vlm.pywith documented same-family JSD and cross-family ULD examples.Motivation
The GOLD algorithm has no theoretical constraints against VLM-to-VLM distillation -- the barriers were purely engineering (incompatible image token formats, different tokenizers, raw image handling through the dataloader).
Key changes
_teacher_processoris stored and used incompute_lossto build teacher-compatible vision tensors from raw imagesteacher_tokenizer_name_or_pathexamples/scripts/gold_vlm.pywith two documented usage examples (same-family JSD + vLLM, cross-family ULD)Note
Looking for feedback:
pixel_valueson GPU at once.docs/source/gold_trainer.md-- will add if that's desirable, just let me know.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. Feel free to tag members/contributors who may be interested in your PR.
@qgallouedec @kashif
Note
High Risk
Large changes to GOLDTrainer training, buffering, loss, and eval paths plus multimodal vLLM generation; mistakes could cause wrong distillation alignment or GPU/memory issues.
Overview
GOLDTrainer gains end-to-end vision-language model (VLM) distillation: same-family pairs can use JSD; different
model_typepairs require ULD and get a separate teacher processor so images and completions are tokenized correctly on the teacher side.For vision datasets the dataloader uses an identity collator so raw PIL images stay intact; a new
DataCollatorForVisionLanguageChatMLbuilds student batches lazily per gradient-accumulation slice (train, eval, on-policy local gen, and vLLM multimodal gen). Eval andprediction_stepcollate raw examples before loss instead of indexing them as tensors. JSD on VLMs uses a safer completion start from labels; ULD teacher completions are rendered with the teacher chat template (fixing silent misalignment). Liger and text-only teachers on image data are rejected at init.GOLDConfigdefaultsremove_unused_columns=False. Addsexamples/scripts/gold_vlm.pyand a large VLM regression test suite.Reviewed by Cursor Bugbot for commit 3b04456. Bugbot is set up for automated code reviews on this repo. Configure here.