Skip to content

Fix token_type_ids requirement for gemma-3 models in GRPOTrainer#5644

Closed
robrui wants to merge 3 commits intohuggingface:mainfrom
robrui:fix/gemma-token-type-ids
Closed

Fix token_type_ids requirement for gemma-3 models in GRPOTrainer#5644
robrui wants to merge 3 commits intohuggingface:mainfrom
robrui:fix/gemma-token-type-ids

Conversation

@robrui
Copy link
Copy Markdown

@robrui robrui commented Apr 26, 2026

What does this PR do?

Fixes #5032: gemma-3 models crash during GRPO/RLOO training with ValueError: token_type_ids is required when no processor (e.g. VLM processor) is available.

Root cause: in the text-only forward path, forward_kwargs is empty. Models like gemma-3 that include token_type_ids in their forward signature receive no token_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

AI writing disclosure

  • AI-assisted (AI tools assisted with code generation; all changes reviewed and verified by a human before submission)

robrui added 3 commits April 26, 2026 02:10
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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fine-Tuning gemma-3-4b-pt raises "ValueError: token_type_ids is required as a model input when training"

2 participants