Why `torch.cuda.is_available()` Returns False After Installing PyTorch: A Technical Guide

torch.cuda.is_available() returns False when the CUDA runtime version bundled with PyTorch is newer than your NVIDIA driver's supported CUDA version, causing a driver-CUDA mismatch that prevents the CUDA runtime from initializing.

When working with the NVIDIA Cosmos repository, installing PyTorch with the default uv pip install torch command often leads to GPU detection failures. This issue occurs because the installation pulls a CUDA 13.0 wheel (cu130) by default, which requires a compatible driver that many systems lack. Understanding why torch.cuda.is_available() returns False requires examining the relationship between the PyTorch CUDA runtime and your system's NVIDIA driver version.

Understanding the Root Cause

Driver-CUDA Runtime Mismatch

In the Cosmos repository, the default installation command uv pip install torch retrieves the newest CUDA 13 wheel. According to the README.md troubleshooting section, if your machine's driver supports only CUDA 12.8 or earlier, the driver cannot execute the newer CUDA runtime. This driver-CUDA mismatch forces the CUDA runtime to abort during initialization, causing torch.cuda.is_available() to report False.

Hardware and Environment Factors

Additional causes include missing NVIDIA GPU hardware, devices disabled in BIOS/firmware, or incorrect LD_LIBRARY_PATH settings that prevent the dynamic loader from finding the driver's libcuda.so library.

Diagnosing Your CUDA Driver Version

Before installing PyTorch, verify your driver's capabilities using the NVIDIA System Management Interface:

nvidia-smi

Look for the "CUDA Version" field in the output. If it shows 12.8 while PyTorch expects 13.0, you have confirmed the mismatch responsible for the False return value.

You can also check which CUDA version PyTorch was compiled against:

import torch
print("PyTorch compiled for CUDA:", torch.version.cuda)

Resolving the Issue in NVIDIA Cosmos

Method 1: Automatic Backend Selection

Use the --torch-backend=auto flag to let uv select a compatible build automatically based on your detected driver:

uv pip install --torch-backend=auto torch torchvision

Method 2: Explicit CUDA Version Pinning

Explicitly specify the CUDA version that matches your driver. For systems with CUDA 12.8 support:

uv pip install --torch-backend=cu128 torch torchvision

For systems with CUDA 13.0 support:

uv pip install --torch-backend=cu130 torch torchvision

These commands prevent the default cu130 selection that causes the driver mismatch, as implemented in the repository's pyproject.toml configuration.

Method 3: Notebook Environment Configuration

If using notebook environments that rely on the COSMOS3_UV_GROUP variable, set it to the appropriate group before running uv sync:

export COSMOS3_UV_GROUP=cu128-train
uv sync

This ensures the environment pulls the correct CUDA variant during synchronization.

Verification Steps

After installation, confirm the fix with a comprehensive validation script:

import torch
import subprocess

print("PyTorch CUDA version:", torch.version.cuda)

try:
    smi_output = subprocess.check_output(["nvidia-smi"], text=True)
    print(smi_output.splitlines()[0])
except Exception as e:
    print("nvidia-smi error:", e)

print("torch.cuda.is_available() ->", torch.cuda.is_available())

Successful output should show matching CUDA versions and torch.cuda.is_available() -> True. The inference_benchmarks.md file provides example environments demonstrating validated CUDA configurations for reference.

Summary

  • torch.cuda.is_available() returns False when PyTorch's CUDA runtime (e.g., 13.0) exceeds your driver's supported CUDA version (e.g., 12.8)
  • The NVIDIA Cosmos repository defaults to cu130 wheels that require recent NVIDIA drivers
  • Use --torch-backend=auto or explicit versions like --torch-backend=cu128 to install compatible PyTorch builds via uv
  • Always verify driver compatibility with nvidia-smi before installation
  • Configure COSMOS3_UV_GROUP for notebook environments to ensure proper CUDA group selection

Frequently Asked Questions

What does torch.cuda.is_available() actually check?

The function verifies that PyTorch can successfully initialize the CUDA runtime by loading the driver libraries and detecting compatible GPU hardware. It returns False if the runtime initialization fails due to driver mismatches, missing libraries in LD_LIBRARY_PATH, or absent hardware.

Can I use a newer PyTorch with an older NVIDIA driver?

No. PyTorch compiled for CUDA 13.0 requires a driver that supports CUDA 13.0. Attempting to run it on an older driver (e.g., CUDA 12.8) results in torch.cuda.is_available() returning False because the driver cannot load the newer runtime libraries, as documented in the Cosmos README.md troubleshooting section.

Why does NVIDIA Cosmos default to CUDA 13.0 wheels?

The pyproject.toml in the Cosmos repository configures uv to install the latest stable PyTorch, which currently defaults to CUDA 13.0 wheels. This ensures access to the newest features but requires up-to-date drivers, necessitating the --torch-backend flag for compatibility with older systems.

How do I check which CUDA version my driver supports?

Run nvidia-smi in your terminal and examine the "CUDA Version" field in the table header. This indicates the maximum CUDA runtime version your current driver can execute. If this number is lower than torch.version.cuda, you must either upgrade your driver or downgrade PyTorch using the --torch-backend flag.

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:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →