Skip to content

🔖 Fix: ensure user-provided labels are retained in self._signature_columns #3589

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 19, 2025
Merged
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
7 changes: 5 additions & 2 deletions trl/trainer/sft_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,10 @@ def torch_call(self, examples: list[Union[list[int], Any, dict[str, Any]]]) -> d
position_ids = [torch.tensor(example["position_ids"]) for example in examples]
else:
position_ids = [torch.arange(len(ids)) for ids in input_ids]
labels = [torch.tensor(example["input_ids"]) for example in examples]
if "labels" in examples[0]:
labels = [torch.tensor(example["labels"]) for example in examples]
else:
labels = [torch.tensor(example["input_ids"]) for example in examples]
if self.completion_only_loss and "completion_mask" in examples[0]:
completion_mask = [torch.tensor(example["completion_mask"]) for example in examples]

Expand Down Expand Up @@ -704,7 +707,7 @@ def _set_signature_columns_if_needed(self):
# and "attention_mask"). When using `train_on_completion_only` we add a "completion_mask" column to the
# dataset. So we need to override the default signature columns to include "completion_mask" as well.
if self._signature_columns is None:
self._signature_columns = ["input_ids", "attention_mask", "position_ids", "completion_mask"]
self._signature_columns = ["input_ids", "labels", "attention_mask", "position_ids", "completion_mask"]

def compute_loss(self, model, inputs, return_outputs=False, num_items_in_batch=None):
"""
Expand Down
Loading