Skip to content

Commit 2ddbd0f

Browse files
gchalumpfacebook-github-bot
authored andcommitted
Guard GPU device queries on CPU lane in verify script
Summary: `__verify_pytorch_gpu_integration` in .github/scripts/utils_pytorch.bash computed `torch_cuda_available` but never used it, then called `torch.cuda.get_device_capability()` and `get_device_name()` unconditionally. On the CPU lane (torch built without CUDA) these raise "Torch not compiled with CUDA enabled", failing the whole GPU-integration check and the fbgemm_gpu_ci_cpu job. Guard both device-property queries behind `torch_cuda_available == True`; print an explicit "N/A (CUDA not available)" placeholder on CPU so the report block still renders. Surfaced during the torch-2.14 CI triage (T277878947); independent of any torch version. Differential Revision: D118316051
1 parent f51f3f4 commit 2ddbd0f

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

.github/scripts/utils_pytorch.bash

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,19 @@ __verify_pytorch_gpu_integration () {
2727
local torch_version_cuda=$(conda run ${env_prefix} python -c "import torch; print(torch.version.cuda)")
2828
# shellcheck disable=SC2086,SC2155
2929
local torch_version_hip=$(conda run ${env_prefix} python -c "import torch; print(torch.version.hip)")
30-
# shellcheck disable=SC2086,SC2155
31-
local torch_device_compatibility=$(conda run ${env_prefix} python -c "import torch; print(torch.cuda.get_device_capability())")
32-
# shellcheck disable=SC2086,SC2155
33-
local torch_device_name=$(conda run ${env_prefix} python -c "import torch; print(torch.cuda.get_device_name(torch.cuda.current_device()))")
30+
# Only query CUDA device properties when CUDA is actually available. On the
31+
# CPU lane (torch built without CUDA), get_device_capability()/get_device_name()
32+
# raise "Torch not compiled with CUDA enabled" and fail the whole check.
33+
local torch_device_compatibility torch_device_name
34+
if [ "${torch_cuda_available}" == "True" ]; then
35+
# shellcheck disable=SC2086,SC2155
36+
torch_device_compatibility=$(conda run ${env_prefix} python -c "import torch; print(torch.cuda.get_device_capability())")
37+
# shellcheck disable=SC2086,SC2155
38+
torch_device_name=$(conda run ${env_prefix} python -c "import torch; print(torch.cuda.get_device_name(torch.cuda.current_device()))")
39+
else
40+
torch_device_compatibility="N/A (CUDA not available)"
41+
torch_device_name="N/A (CUDA not available)"
42+
fi
3443

3544
echo ""
3645
echo "################################################################################"

0 commit comments

Comments
 (0)