From c0ffcdf998aa0e00f1f39e79ee8124b74b53d23f Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 24 Dec 2020 13:01:35 -0800 Subject: [PATCH] Display correct CUDA devices (#1776) * Display correct CUDA devices * cleanup --- utils/torch_utils.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/utils/torch_utils.py b/utils/torch_utils.py index 754b0870c..4aea9ba10 100644 --- a/utils/torch_utils.py +++ b/utils/torch_utils.py @@ -48,20 +48,20 @@ def select_device(device='', batch_size=None): cpu_request = device.lower() == 'cpu' if device and not cpu_request: # if device requested other than 'cpu' os.environ['CUDA_VISIBLE_DEVICES'] = device # set environment variable - assert torch.cuda.is_available(), 'CUDA unavailable, invalid device %s requested' % device # check availablity + assert torch.cuda.is_available(), f'CUDA unavailable, invalid device {device} requested' # check availablity cuda = False if cpu_request else torch.cuda.is_available() if cuda: c = 1024 ** 2 # bytes to MB ng = torch.cuda.device_count() if ng > 1 and batch_size: # check that batch_size is compatible with device_count - assert batch_size % ng == 0, 'batch-size %g not multiple of GPU count %g' % (batch_size, ng) + assert batch_size % ng == 0, f'batch-size {batch_size} not multiple of GPU count {ng}' x = [torch.cuda.get_device_properties(i) for i in range(ng)] s = f'Using torch {torch.__version__} ' - for i in range(0, ng): + for i, d in enumerate((device or '0').split(',')): if i == 1: s = ' ' * len(s) - logger.info("%sCUDA:%g (%s, %dMB)" % (s, i, x[i].name, x[i].total_memory / c)) + logger.info(f"{s}CUDA:{d} ({x[i].name}, {x[i].total_memory / c}MB)") else: logger.info(f'Using torch {torch.__version__} CPU')