From 2aa330139f3cc1237aeb3132245ed7e5d6da1683 Mon Sep 17 00:00:00 2001 From: NanoCode012 Date: Tue, 7 Jul 2020 12:07:40 +0700 Subject: [PATCH] Remove apex.parallel. Use torch.nn.parallel For future compatibility --- train.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/train.py b/train.py index 9b5deee5d5aa..7eaedf5ecdf0 100644 --- a/train.py +++ b/train.py @@ -7,6 +7,7 @@ import torch.optim.lr_scheduler as lr_scheduler import torch.utils.data from torch.utils.tensorboard import SummaryWriter +from torch.nn.parallel import DistributedDataParallel as DDP import test # import test.py to get mAP after each epoch from models.yolo import Model @@ -17,9 +18,7 @@ mixed_precision = True try: # Mixed precision training https://github.com/NVIDIA/apex from apex import amp - from apex.parallel import DistributedDataParallel as DDP except: - from torch.nn.parallel import DistributedDataParallel as DDP print('Apex recommended for faster mixed precision training: https://github.com/NVIDIA/apex') mixed_precision = False # not installed @@ -195,10 +194,7 @@ def train(hyp, tb_writer, opt, device): if device.type != 'cpu' and opt.local_rank != -1: # pip install torch==1.4.0+cku100 torchvision==0.5.0+cu100 -f https://download.pytorch.org/whl/torch_stable.html model = torch.nn.SyncBatchNorm.convert_sync_batchnorm(model) - if mixed_precision: - model = DDP(model, delay_allreduce=True) - else: - model = DDP(model, device_ids=[opt.local_rank]) + model = DDP(model, device_ids=[opt.local_rank], output_device=opt.local_rank) # Model parameters hyp['cls'] *= nc / 80. # scale coco-tuned hyp['cls'] to current dataset