Skip to content

Commit

Permalink
Fix select_device() for Multi-GPU
Browse files Browse the repository at this point in the history
Possible fix for #6431
  • Loading branch information
glenn-jocher committed Jan 26, 2022
1 parent d5966c9 commit 7b98fa6
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion utils/torch_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def select_device(device='', batch_size=0, newline=True):
if cpu:
os.environ['CUDA_VISIBLE_DEVICES'] = '-1' # force torch.cuda.is_available() = False
elif device: # non-cpu device requested
nd = torch.cuda.device_count() # number of CUDA devices
nd = len(os.getenv('CUDA_VISIBLE_DEVICES', '').replace(',','')) # number of CUDA devices
assert torch.cuda.is_available(), 'CUDA is not available, use `--device cpu` or do not pass a --device'
assert nd > int(max(device.split(','))), f'Invalid `--device {device}` request, valid devices are 0 - {nd - 1}'
os.environ['CUDA_VISIBLE_DEVICES'] = device # set environment variable (must be after asserts)
Expand Down

0 comments on commit 7b98fa6

Please sign in to comment.