Why `torch.cuda.is_available()` Returns False After Installing PyTorch and How to Fix It
torch.cuda.is_available() returns False when the CUDA runtime shipped with your PyTorch wheel is incompatible with the host NVIDIA driver, and the fix is to reinstall PyTorch using uv's --torch-backend flag to match your driver's CUDA version.
In the NVIDIA/cosmos repository, the default installation workflow pulls the newest CUDA-enabled PyTorch build, which can trigger this mismatch on systems with older NVIDIA drivers. Understanding how the repository handles CUDA versioning is essential for a working GPU setup. This guide explains the root cause and the exact commands to resolve it, as documented in the project's troubleshooting documentation.
Root Cause in the NVIDIA Cosmos Repository
Driver-CUDA Version Mismatch
In README.md, the troubleshooting section identifies the most common cause: the installed torch wheel targets a newer CUDA than the host driver supports. When you run uv pip install torch, uv selects the latest wheel—currently the CUDA 13 (cu130) variant. If the system's driver only supports CUDA 12.8 or earlier, the CUDA runtime aborts during initialization because the driver cannot load the newer libraries.
The repository's inference_benchmarks.md lists the exact CUDA versions used in validated benchmarking environments, confirming that driver-version alignment is expected across the codebase.
Missing GPU or Incorrect Environment
Beyond version mismatches, torch.cuda.is_available() returns False if the hardware is absent or disabled. A missing NVIDIA GPU, BIOS-disabled device, or broken LD_LIBRARY_PATH that excludes libcuda.so can all prevent the CUDA runtime from detecting the driver.
How to Fix torch.cuda.is_available() Returning False
Step 1 – Verify Your NVIDIA Driver Version
Run the following command to check the maximum CUDA version your driver supports:
nvidia-smi
Look for the CUDA Version field in the output. If it reports 12.8, you must install a PyTorch build compiled for CUDA 12.8 rather than the default CUDA 13 build.
Step 2 – Install a Matching PyTorch Wheel with --torch-backend
The NVIDIA/cosmos README recommends using the --torch-backend flag to force uv to download a compatible wheel instead of the newest one.
- Automatic selection – Let
uvdetect and install the best match with--torch-backend=auto:
uv pip install --torch-backend=auto torch torchvision
- Explicit pin – Manually specify the backend to match your driver exactly:
# For a driver supporting CUDA 12.8
uv pip install --torch-backend=cu128 torch torchvision
# For a driver already supporting CUDA 13
uv pip install --torch-backend=cu130 torch torchvision
According to the repository's troubleshooting guide, this flag is the primary mechanism to avoid the default cu130 wheel on older drivers.
Step 3 – Confirm CUDA Availability in Python
After installation, verify that PyTorch can see the GPU:
import torch
print("CUDA driver version:", torch.version.cuda)
print("CUDA available:", torch.cuda.is_available())
A successful fix prints the expected CUDA version and True.
Complete Verification Script
For a full diagnostic, run a script that checks the PyTorch build, queries nvidia-smi, and tests torch.cuda.is_available():
python - <<'PY'
import torch
import subprocess
# Show which CUDA runtime PyTorch was compiled against
print("torch compiled for CUDA:", torch.version.cuda)
# Check driver visibility
try:
out = subprocess.check_output(["nvidia-smi"], text=True)
print(out.splitlines()[0])
except Exception as e:
print("nvidia-smi failed:", e)
# Final availability test
print("torch.cuda.is_available() ->", torch.cuda.is_available())
PY
Typical output after the fix resembles:
torch compiled for CUDA: 12.8
Tue Jun 6 12:34:56 2026
+-----------------------------------------------------------------------------+
| NVIDIA-SMI ... |
| CUDA Version: 12.8 |
+-----------------------------------------------------------------------------+
torch.cuda.is_available() -> True
Notebook and uv sync Environments
If you are working inside a notebook environment that relies on the COSMOS3_UV_GROUP variable, set it to the appropriate group before running uv sync. For example, use cu128-train when your driver supports CUDA 12.8. This ensures the lock file resolves the same compatible backend during environment synchronization.
The project's pyproject.toml defines the required uv version and the integration point for --torch-backend, while README.md documents the environment-specific workflow.
Summary
torch.cuda.is_available()returnsFalseinNVIDIA/cosmossetups when the defaultcu130PyTorch wheel exceeds the host driver's supported CUDA version.- Check your driver's maximum CUDA version with
nvidia-smibefore installing PyTorch. - Use
uv pip install --torch-backend=<version>to select a matching wheel, or setCOSMOS3_UV_GROUPforuv syncworkflows. - Confirm the fix by inspecting
torch.version.cudaand verifyingtorch.cuda.is_available()isTrue.
Frequently Asked Questions
What does torch.cuda.is_available() actually check?
The function verifies that PyTorch can load and initialize the NVIDIA CUDA runtime on the host. It returns False if the driver is missing, too old for the compiled runtime, or if necessary libraries like libcuda.so cannot be found.
Can I use the default uv pip install torch command with an older NVIDIA driver?
No. The NVIDIA/cosmos documentation warns that the default command resolves to the newest CUDA wheel, currently cu130. On a driver that only supports CUDA 12.8 or earlier, this mismatch causes the runtime to fail and the function to return False. You must specify --torch-backend to override this behavior.
What is the --torch-backend flag in uv?
The --torch-backend flag tells the uv package installer which CUDA variant of PyTorch to download, such as cu128 for CUDA 12.8 or cu130 for CUDA 13. It prevents uv from automatically selecting the latest wheel that might be incompatible with your system, as noted in the repository's README.md troubleshooting section.
How do I set the correct backend for notebook or uv sync environments?
For notebook or synchronized environments, export the COSMOS3_UV_GROUP environment variable to match your driver before running uv sync. For example, set it to cu128-train for CUDA 12.8 systems. The repository's pyproject.toml encodes these groups, and README.md provides the exact configuration steps.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →