Skip to content

Commit

Permalink
Implement len in IterableDatasetShard (huggingface#13780)
Browse files Browse the repository at this point in the history
  • Loading branch information
sgugger authored and Alberto committed Jan 13, 2022
1 parent 9969d6d commit 47856fc
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/transformers/trainer_pt_utils.py
Expand Up @@ -772,6 +772,13 @@ def __iter__(self):
for i in process_slice:
yield current_batch[i]

def __len__(self):
# Will raise an error if the underlying dataset is not sized.
if self.drop_last:
return len(self.dataset) // self.num_processes
else:
return math.ceil(len(self.dataset) / self.num_processes)


# In order to keep `trainer.py` compact and easy to understand, place any secondary PT Trainer
# helper methods here
Expand Down

0 comments on commit 47856fc

Please sign in to comment.