Skip to content

fix: check CUDA availability before calling get_device_capability#45371

Closed
HelloAnner wants to merge 1 commit intohuggingface:mainfrom
HelloAnner:clawoss/fix/testing_utils_cuda_check
Closed

fix: check CUDA availability before calling get_device_capability#45371
HelloAnner wants to merge 1 commit intohuggingface:mainfrom
HelloAnner:clawoss/fix/testing_utils_cuda_check

Conversation

@HelloAnner
Copy link
Copy Markdown

Fixes #45341

When CUDA is installed but no GPU is available, get_device_properties() calls torch.cuda.get_device_capability() which fails because there is no CUDA device.

The fix moves import torch to the top of the function and adds a torch.cuda.is_available() check to the condition, so the function gracefully falls through to the else branch when no GPU is present.

Fixes huggingface#45341

When CUDA is installed but no GPU is available, testing_utils.py line 3223 calls torch.cuda.get_device_capability() which fails.

Changed the condition to check torch.cuda.is_available() before accessing GPU capabilities.
@remi-or
Copy link
Copy Markdown
Collaborator

remi-or commented Apr 13, 2026

Thanks for the fix, but this is a duplicate of #45351, closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A little bug in testing_utils.py

2 participants