Fix token_type_ids requirement for gemma-3 models in GRPOTrainer#5644
Closed
robrui wants to merge 3 commits intohuggingface:mainfrom
Closed
Fix token_type_ids requirement for gemma-3 models in GRPOTrainer#5644robrui wants to merge 3 commits intohuggingface:mainfrom
robrui wants to merge 3 commits intohuggingface:mainfrom
Conversation
When fine-tuning gemma-3-4b-pt with TRL, the model requires token_type_ids in the forward pass. This fix ensures token_type_ids are properly set during training data preparation for text-only (non-VLM) models whose forward method expects them. Closes huggingface#5032
…ainer These trainers have the same code path: text-only (non-VLM) models receive an empty forward_kwargs dict, causing token_type_ids to be missing when the model requires them (e.g., gemma-3).
These experimental trainers share the same pattern: text-only models receive an empty forward_kwargs dict, missing token_type_ids when the model requires them (e.g., gemma-3).
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?
Fixes #5032: gemma-3 models crash during GRPO/RLOO training with
ValueError: token_type_ids is requiredwhen no processor (e.g. VLM processor) is available.Root cause: in the text-only forward path,
forward_kwargsis empty. Models like gemma-3 that includetoken_type_idsin their forward signature receive notoken_type_ids, causing a crash.Fix: Before the text-only forward pass, if
"token_type_ids" in self.model_kwarg_keys, create a zero tensor matching the prompt length. The existing extension block then pads zeros for completion tokens automatically.Applied across 5 trainers: GRPOTrainer, RLOOTrainer, DPPOTrainer, GFPOTrainer, GRPOWithReplayBufferTrainer.
Before submitting
token_type_idsis required as a model input when training" #5032)AI writing disclosure