Fix device count check (#6290)

* Fix device count check()

* Update torch_utils.py

* Update torch_utils.py

* Update hubconf.py
This commit is contained in:
Glenn Jocher authored and GitHub committed 2022-01-13 21:23:03 -10:00
1 parent af001349e4
commit e7bf38277f
2 files changed
+4 -3

No files matched your search

+3 -2
View File
@@ -61,8 +61,9 @@ 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
os.environ['CUDA_VISIBLE_DEVICES'] = device # set environment variable
assert torch.cuda.is_available(), f'CUDA unavailable, invalid device {device} requested' # check availability
assert torch.cuda.is_available(), 'CUDA unavailable' # check CUDA is available
assert torch.cuda.device_count() > int(device), f'invalid CUDA device {device} requested' # check index
os.environ['CUDA_VISIBLE_DEVICES'] = device # set environment variable (must be after asserts)
cuda = not cpu and torch.cuda.is_available()
if cuda: