Skip to content

Commit

Permalink
Fix length of IterableDatasetShard and add test (huggingface#13792)
Browse files Browse the repository at this point in the history
* Fix length of IterableDatasetShard and add test

* Add comments
  • Loading branch information
sgugger authored and Alberto B茅gu茅 committed Jan 27, 2022
1 parent a220407 commit 3af7ddd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/transformers/trainer_pt_utils.py
Expand Up @@ -775,9 +775,9 @@ def __iter__(self):
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
return (len(self.dataset) // (self.batch_size * self.num_processes)) * self.batch_size
else:
return math.ceil(len(self.dataset) / self.num_processes)
return math.ceil(len(self.dataset) / (self.batch_size * self.num_processes)) * self.batch_size


# In order to keep `trainer.py` compact and easy to understand, place any secondary PT Trainer
Expand Down
1 change: 1 addition & 0 deletions utils/tests_fetcher.py
Expand Up @@ -281,6 +281,7 @@ def create_reverse_dependency_map():
"test_trainer_distributed.py",
"test_trainer_tpu.py",
],
"train_pt_utils.py": "test_trainer_utils.py",
"utils/versions.py": "test_versions_utils.py",
}

Expand Down

0 comments on commit 3af7ddd

Please sign in to comment.