Skip to content

Commit

Permalink
Update torch_utils.py
Browse files Browse the repository at this point in the history
  • Loading branch information
glenn-jocher authored Jan 26, 2022
1 parent 7b98fa6 commit 24b80ca
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions utils/torch_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ def select_device(device='', batch_size=0, newline=True):
os.environ['CUDA_VISIBLE_DEVICES'] = '-1' # force torch.cuda.is_available() = False
elif device: # non-cpu device requested
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)
os.environ['CUDA_VISIBLE_DEVICES'] = device # set environment variable (before assert cuda.is_available)
assert torch.cuda.is_available(), 'CUDA is not available, use `--device cpu` or do not pass a --device'

cuda = not cpu and torch.cuda.is_available()
if cuda:
Expand Down

0 comments on commit 24b80ca

Please sign in to comment.