Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions trl/experimental/dppo/dppo_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,11 @@ def _generate_and_score_completions(
forward_kwargs = {k: v for k, v in prompt_inputs.items() if k not in ["input_ids", "attention_mask"]}
else:
forward_kwargs = {}
# For text-only models whose forward pass expects token_type_ids (e.g., gemma-3),
# create a zero tensor matching the prompt length. The extension block below will
# automatically pad it with zeros for the completion part.
if "token_type_ids" in self.model_kwarg_keys:
forward_kwargs["token_type_ids"] = torch.zeros_like(prompt_ids)

# If token_type_ids are used, extend them with zeros for the completion part
if "token_type_ids" in forward_kwargs:
Expand Down
5 changes: 5 additions & 0 deletions trl/experimental/gfpo/gfpo_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ def _generate_and_score_completions(self, inputs):
forward_kwargs = {k: v for k, v in prompt_inputs.items() if k not in ["input_ids", "attention_mask"]}
else:
forward_kwargs = {}
# For text-only models whose forward pass expects token_type_ids (e.g., gemma-3),
# create a zero tensor matching the prompt length. The extension block below will
# automatically pad it with zeros for the completion part.
if "token_type_ids" in self.model_kwarg_keys:
forward_kwargs["token_type_ids"] = torch.zeros_like(prompt_ids)

# If token_type_ids are used, extend them with zeros for the completion part
if "token_type_ids" in forward_kwargs:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ def _generate_and_score_completions(
forward_kwargs = {k: v for k, v in prompt_inputs.items() if k not in ["input_ids", "attention_mask"]}
else:
forward_kwargs = {}
# For text-only models whose forward pass expects token_type_ids (e.g., gemma-3),
# create a zero tensor matching the prompt length. The extension block below will
# automatically pad it with zeros for the completion part.
if "token_type_ids" in self.model_kwarg_keys:
forward_kwargs["token_type_ids"] = torch.zeros_like(prompt_ids)

# If token_type_ids are used, extend them with zeros for the completion part
if "token_type_ids" in forward_kwargs:
Expand Down
5 changes: 5 additions & 0 deletions trl/trainer/grpo_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1938,6 +1938,11 @@ def _generate_and_score_completions(
forward_kwargs = {k: v for k, v in prompt_inputs.items() if k not in ["input_ids", "attention_mask"]}
else:
forward_kwargs = {}
# For text-only models whose forward pass expects token_type_ids (e.g., gemma-3),
# create a zero tensor matching the prompt length. The extension block below will
# automatically pad it with zeros for the completion part.
if "token_type_ids" in self.model_kwarg_keys:
forward_kwargs["token_type_ids"] = torch.zeros_like(prompt_ids)

# If token_type_ids are used, extend them with zeros for the completion part
if "token_type_ids" in forward_kwargs:
Expand Down
5 changes: 5 additions & 0 deletions trl/trainer/rloo_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1171,6 +1171,11 @@ def _generate_and_score_completions(
forward_kwargs = {k: v for k, v in prompt_inputs.items() if k not in ["input_ids", "attention_mask"]}
else:
forward_kwargs = {}
# For text-only models whose forward pass expects token_type_ids (e.g., gemma-3),
# create a zero tensor matching the prompt length. The extension block below will
# automatically pad it with zeros for the completion part.
if "token_type_ids" in self.model_kwarg_keys:
forward_kwargs["token_type_ids"] = torch.zeros_like(prompt_ids)

# If token_type_ids are used, extend them with zeros for the completion part
if "token_type_ids" in forward_kwargs:
Expand Down
Loading