Skip to content

Add detail about set_epoch in the DDP tutorial series #2066

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions beginner_source/ddp_series_multigpu.rst
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,18 @@ Distributing input data
+ sampler=DistributedSampler(train_dataset),
)

- Calling the ``set_epoch()`` method on the ``DistributedSampler`` at the beginning of each epoch is necessary to make shuffling work
properly across multiple epochs. Otherwise, the same ordering will be used in each epoch.

.. code:: diff

def _run_epoch(self, epoch):
b_sz = len(next(iter(self.train_data))[0])
+ self.train_data.sampler.set_epoch(epoch)
for source, targets in self.train_data:
...
self._run_batch(source, targets)


Saving model checkpoints
~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down