File size: 1,153 Bytes
3f29a93 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# This file contains the changes to implement DDP training with the train.yaml config.
is_dist: '$dist.is_initialized()'
rank: '$dist.get_rank() if @is_dist else 0'
device: '$torch.device(f"cuda:{@rank}" if torch.cuda.is_available() else "cpu")' # assumes GPU # matches rank #
# wrap the network in a DistributedDataParallel instance, moving it to the chosen device for this process
network:
_target_: torch.nn.parallel.DistributedDataParallel
module: $@network_def.to(@device)
device_ids: ['@device']
find_unused_parameters: true
train_sampler:
_target_: DistributedSampler
dataset: '@train_dataset'
even_divisible: true
shuffle: true
train_dataloader#sampler: '@train_sampler'
train_dataloader#shuffle: false
val_sampler:
_target_: DistributedSampler
dataset: '@val_dataset'
even_divisible: false
shuffle: false
val_dataloader#sampler: '@val_sampler'
run:
- $import torch.distributed as dist
- $dist.init_process_group(backend='nccl')
- $torch.cuda.set_device(@device)
- $monai.utils.set_determinism(seed=123) # may want to choose a different seed or not do this here
- $@trainer.run()
- $dist.destroy_process_group()
|