Skip to content

Commit

Permalink
fix to issue #14833 in data_collator - consider no labels (#14930)
Browse files Browse the repository at this point in the history
  • Loading branch information
kleinay authored Dec 27, 2021
1 parent 501307b commit 03885a3
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/transformers/data/data_collator.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,11 @@ def __call__(self, features, return_tensors=None):
)

# prepare decoder_input_ids
if self.model is not None and hasattr(self.model, "prepare_decoder_input_ids_from_labels"):
if (
labels is not None
and self.model is not None
and hasattr(self.model, "prepare_decoder_input_ids_from_labels")
):
decoder_input_ids = self.model.prepare_decoder_input_ids_from_labels(labels=features["labels"])
features["decoder_input_ids"] = decoder_input_ids

Expand Down

0 comments on commit 03885a3

Please sign in to comment.