fix(testing): check torch.cuda.is_available() before get_device_capability#45697
Closed
PHclaw wants to merge 1 commit intohuggingface:mainfrom
Closed
fix(testing): check torch.cuda.is_available() before get_device_capability#45697PHclaw wants to merge 1 commit intohuggingface:mainfrom
PHclaw wants to merge 1 commit intohuggingface:mainfrom
Conversation
Member
|
PR already open at #45351 |
This was referenced Apr 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #45341
get_device_properties()crashes with an error on machines that have CUDA installed (torch.version.cuda is not None) but no physical GPU available. This happens on cloud instances like Lightning AI Studio where CUDA runtime is present but no GPU is attached.Bug
IS_CUDA_SYSTEMis set toTruewhentorch.version.cuda is not None, but this only means CUDA runtime is available, not that a GPU is actually present.Fix
torch.cuda.is_available()check to the condition on line 3207import torch(torch is already imported at module level forIS_CUDA_SYSTEM/IS_ROCM_SYSTEMchecks)This gracefully falls through to the
elsebranch when no GPU is available, returning(torch_device, None, None)instead of crashing.