Created
May 29, 2021 06:20
-
-
Save rish-16/0fb48446dc9dd29f533901ec15d48528 to your computer and use it in GitHub Desktop.
A guide on Colab TPU training using PyTorch XLA (Part 6)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
num_replicas is the total number of times we'll replicate | |
the batch samples for all cores. | |
''' | |
train_sampler = torch.utils.data.distributed.DistributedSampler( | |
im_train, | |
num_replicas=xm.xrt_world_size(), | |
rank=xm.get_ordinal(), | |
shuffle=True | |
) | |
test_sampler = torch.utils.data.distributed.DistributedSampler( | |
im_test, | |
num_replicas=xm.xrt_world_size(), | |
rank=xm.get_ordinal(), | |
shuffle=False | |
) | |
# ignore batch_size and num_workers for now | |
train_loader = torch.utils.data.DataLoader( | |
im_train, | |
batch_size=flags['batch_size'], | |
sampler=train_sampler, | |
num_workers=flags['num_workers'], | |
drop_last=True | |
) | |
test_loader = torch.utils.data.DataLoader( | |
im_test, | |
batch_size=flags['batch_size'], | |
sampler=test_sampler, | |
num_workers=flags['num_workers'], | |
drop_last=True | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment