Skip to content

Commit

Permalink
Set sampler in DDP example
Browse files Browse the repository at this point in the history
  • Loading branch information
rasbt authored Oct 21, 2024
1 parent 3896986 commit 7513360
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions appendix-A/01_main-chapter-code/DDP-script.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ def main(rank, world_size, num_epochs):
# the core model is now accessible as model.module

for epoch in range(num_epochs):
# NEW: Set sampler to ensure each epoch has a different shuffle order
train_loader.sampler.set_epoch(epoch)

model.train()
for features, labels in train_loader:
Expand Down

0 comments on commit 7513360

Please sign in to comment.