Skip to content

Commit

Permalink
Fix device count check (ultralytics#6290)
Browse files Browse the repository at this point in the history
* Fix device count check()

* Update torch_utils.py

* Update torch_utils.py

* Update hubconf.py
  • Loading branch information
glenn-jocher committed Jan 14, 2022
1 parent ba24e2b commit a5ceef8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion hubconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def _create(name, pretrained=True, channels=3, classes=80, autoshape=True, verbo

except Exception as e:
help_url = 'https://github.com/ultralytics/yolov5/issues/36'
s = 'Cache may be out of date, try `force_reload=True`. See %s for help.' % help_url
s = f'{e}. Cache may be out of date, try `force_reload=True` or see {help_url} for help.'
raise Exception(s) from e


Expand Down
5 changes: 3 additions & 2 deletions utils/torch_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit a5ceef8

Please sign in to comment.