Adapt has_labels test when no labels were found (#20113)

* Make default labels for non-pretrained models

* Fix the has_labels test instead
This commit is contained in:
Sylvain Gugger 2022-11-08 13:53:04 -05:00 committed by GitHub
parent e2a23b6ce9
commit c08a1e26ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3189,7 +3189,7 @@ class Trainer:
Tuple[Optional[torch.Tensor], Optional[torch.Tensor], Optional[torch.Tensor]]: A tuple with the loss,
logits and labels (each being optional).
"""
has_labels = all(inputs.get(k) is not None for k in self.label_names)
has_labels = False if len(self.label_names) == 0 else all(inputs.get(k) is not None for k in self.label_names)
inputs = self._prepare_inputs(inputs)
if ignore_keys is None:
if hasattr(self.model, "config"):