Set sampler in DDP example

This commit is contained in:
Sebastian Raschka 2024-10-21 09:26:01 -05:00 committed by GitHub
parent 38969864e6
commit 75133605c5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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: