Skip to content

Commit e851405

Browse files
committed
[Fix] Fix conflict of downloading dataset
1 parent be7f1b3 commit e851405

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

intermediate_source/FSDP_tutorial.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,12 @@ We add the following code snippets to a python script “FSDP_mnist.py”.
208208
transforms.Normalize((0.1307,), (0.3081,))
209209
])
210210
211-
dataset1 = datasets.MNIST('../data', train=True, download=True,
212-
transform=transform)
213-
dataset2 = datasets.MNIST('../data', train=False,
214-
transform=transform)
211+
#if dataset not exists, download it on rank 0
212+
dataset_dir = '../data'
213+
if rank == 0:
214+
print(f"Preparing MNIST dataset on {rank=} ...")
215+
datasets.MNIST(dataset_dir, train=True, download=True)
216+
dist.barrier()
215217
216218
sampler1 = DistributedSampler(dataset1, rank=rank, num_replicas=world_size, shuffle=True)
217219
sampler2 = DistributedSampler(dataset2, rank=rank, num_replicas=world_size)

0 commit comments

Comments
 (0)