Improve trainer DDP device handling (#15383)

Co-authored-by: UltralyticsAssistant <web@ultralytics.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
pull/15443/head
alanZee 3 months ago committed by GitHub
parent 592f421663
commit 03e0b1033c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 4
      ultralytics/engine/trainer.py

@ -174,9 +174,11 @@ class BaseTrainer:
world_size = len(self.args.device.split(","))
elif isinstance(self.args.device, (tuple, list)): # i.e. device=[0, 1, 2, 3] (multi-GPU from CLI is list)
world_size = len(self.args.device)
elif self.args.device in {"cpu", "mps"}: # i.e. device='cpu' or 'mps'
world_size = 0
elif torch.cuda.is_available(): # i.e. device=None or device='' or device=number
world_size = 1 # default to device 0
else: # i.e. device='cpu' or 'mps'
else: # i.e. device=None or device=''
world_size = 0
# Run subprocess if DDP training, else train normally

Loading…
Cancel
Save