Skip to content

Commit

Permalink
Double check for attribute num_examples (#12562)
Browse files Browse the repository at this point in the history
* Double check for attribute

* Use right name
  • Loading branch information
sgugger authored Jul 7, 2021
1 parent 0d2bffa commit b868260
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/transformers/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2245,7 +2245,9 @@ def evaluation_loop(
# Number of samples
if not isinstance(eval_dataset, IterableDataset):
num_samples = len(eval_dataset)
elif isinstance(eval_dataset, IterableDatasetShard):
# The instance check is weird and does not actually check for the type, but whether the dataset has the right
# methods. Therefore we need to make sure it also has the attribute.
elif isinstance(eval_dataset, IterableDatasetShard) and hasattr(eval_dataset, "num_examples"):
num_samples = eval_dataset.num_examples
else:
num_samples = observed_num_examples
Expand Down

0 comments on commit b868260

Please sign in to comment.