in utils/main_utils.py [0:0]
def distribute_model_to_cuda(models, args):
squeeze = False
if not isinstance(models, list):
models = [models]
squeeze = True
for i in range(len(models)):
if args.multiprocessing_distributed:
# For multiprocessing distributed, DistributedDataParallel constructor
# should always set the single device scope, otherwise,
# DistributedDataParallel will use all available devices.
if args.gpu is not None:
torch.cuda.set_device(args.gpu)
models[i].cuda(args.gpu)
models[i] = torch.nn.parallel.DistributedDataParallel(models[i], device_ids=[args.gpu])
else:
models[i].cuda()
# DistributedDataParallel will divide and allocate batch_size to all
# available GPUs if device_ids are not set
models[i] = torch.nn.parallel.DistributedDataParallel(models[i])
elif args.gpu is not None:
torch.cuda.set_device(args.gpu)
models[i] = models[i].cuda(args.gpu)
else:
# DataParallel will divide and allocate batch_size to all available GPUs
# Careful!!! DataParallel does not work for vox
models[i] = torch.nn.DataParallel(models[i]).cuda()
if squeeze:
models = models[0]
return models, args