Fix IDs shape mismatch in SFT for VLMs with text-only#5354
Merged
albertvillanova merged 7 commits intohuggingface:mainfrom Mar 24, 2026
Merged
Fix IDs shape mismatch in SFT for VLMs with text-only#5354albertvillanova merged 7 commits intohuggingface:mainfrom
albertvillanova merged 7 commits intohuggingface:mainfrom
Conversation
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
qgallouedec
reviewed
Mar 23, 2026
Member
|
For the records: we do not have the same issue in DPO (text-only data is properly supported), neither in RewardTrainer which doesn't support VLM |
qgallouedec
approved these changes
Mar 24, 2026
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.
Fix IDs shape mismatch in SFT for VLMs with text-only.
Fix #5334.
This PR addresses a regression issue when training vision-language models (VLMs) with text-only datasets, ensuring compatibility between data preprocessing and model expectations. The main focus is on fixing how input IDs are handled for VLMs and adding a regression test to prevent future breakage.
Changes
Bug fix for VLM text-only input handling:
tokenize_fnwhere VLM processors returned input IDs as a list of lists (e.g.,[[1, 2, 3]]) instead of a flat list (e.g.,[1, 2, 3]). The function now unwraps the extra list level to prevent downstream shape errors in models expecting 3-D position IDs.Testing improvements:
test_sft_trainer.pyto verify that training a VLM with a text-only dataset works correctly and does not produce shape errors.Note
Medium Risk
Touches SFT dataset tokenization for standard (non-conversational) examples; a small shape-normalization change could affect any processor that returns nested
input_ids, but it is guarded by a targeted regression test.Overview
Fixes a regression when training vision-language models on text-only standard datasets by normalizing
input_idsreturned from VLMprocessing_classcalls (unwrapping[[...]]to[...]) to match the LLM code path and avoid downstream shape/position-id errors.Adds a regression case to
test_train_vlm_text_only_datato includestandard_language_modelingin the parameterized dataset configs, ensuring VLM text-only training remains supported.Written by Cursor Bugbot for commit 7b1acb1. This will update automatically on new commits. Configure here.