# Troubleshooting torch.cuda.is_available Returns False After Installing PyTorch with uv

> Fix torch.cuda.is_available returning False after PyTorch install with uv. Force CUDA wheels with uv cache clean torch and uv sync --extra cu124.

- Repository: [Th3Unknovvn/uv-install-torch](https://github.com/baonguyen6742/uv-install-torch)
- Tags: troubleshooting
- Published: 2026-02-26

---

**Run `uv cache clean torch` followed by `uv sync --extra cu124` to force uv to install CUDA-enabled wheels instead of CPU-only packages.**

When `torch.cuda.is_available()` returns **False** despite having an NVIDIA GPU, the installation likely pulled CPU-only PyTorch wheels rather than CUDA-enabled builds. The repository `baonguyen6742/uv-install-torch` demonstrates how uv's dependency resolution can inadvertently select CPU packages when the CUDA extra is not explicitly requested, as configured in the [`pyproject.toml`](https://github.com/baonguyen6742/uv-install-torch/blob/main/pyproject.toml) conflict rules.

## Why CUDA Detection Fails with uv

The failure occurs across several layers, from hardware compatibility to uv's dependency resolution strategy.

### Hardware and Driver Requirements

First, verify your NVIDIA driver supports the CUDA version specified in your PyTorch wheels. Run `nvidia-smi --query-gpu driver_version --format=csv` to check your driver version against the CUDA compatibility matrix. For the `cu124` extra used in this repository, your driver must support CUDA 12.4.

### The CPU vs CUDA Extra Conflict

In [`pyproject.toml`](https://github.com/baonguyen6742/uv-install-torch/blob/main/pyproject.toml) (lines 30-33), the repository defines **mutually exclusive extras**: `cpu` and `cu124`. The conflict rule prevents both from being installed simultaneously. If you run `uv sync` without the `--extra cu124` flag, uv resolves the dependency graph to the CPU-only wheels, causing `torch.cuda.is_available()` to return False even on GPU hardware.

### Stale Cache Issues

The uv cache can retain previously resolved CPU wheels. According to the repository's README, stale cache entries may cause uv to fallback to CPU packages even when requesting CUDA extras. The [`pyproject.toml`](https://github.com/baonguyen6742/uv-install-torch/blob/main/pyproject.toml) (lines 24-50) configures the index URLs for CUDA wheels, but cached metadata can override these settings.

## Step-by-Step Fix Workflow

Follow these commands in your repository root to resolve the detection failure:

1. **Verify driver compatibility**  
   ```bash
   nvidia-smi --query-gpu driver_version,name --format=csv
   ```

2. **Clean uv caches**  
   ```bash
   uv cache prune
   uv cache clean torch
   ```

3. **Remove lockfile and environment**  
   ```bash
   rm -rf .venv uv.lock
   ```

4. **Reinstall with CUDA extra**  
   ```bash
   uv sync --extra cu124
   ```

5. **Run the verification script**  
   ```bash
   uv run main.py
   ```

The [`main.py`](https://github.com/baonguyen6742/uv-install-torch/blob/main/main.py) script in the repository imports the configured libraries and prints CUDA availability status. Expected output shows `torch.cuda.is_available: True` and device properties.

## Verifying Correct Wheel Installation

Confirm uv installed the CUDA-enabled wheels by checking the package metadata:

```bash
uv pip list | grep torch

```

You must see the CUDA suffix in the version string:

```text
torch          2.4.1+cu124
torchvision    0.19.1+cu124
torchaudio     2.4.1+cu124

```

If the `+cu124` suffix is missing, the CPU-only wheel is installed.

Use this diagnostic script to verify the runtime environment:

```python

# basic_check.py

import torch

print("torch version:", torch.__version__)
print("CUDA available?:", torch.cuda.is_available())
print("CUDA device count:", torch.cuda.device_count())
if torch.cuda.is_available():
    print("Device properties:", torch.cuda.get_device_properties(0))

```

Run with `uv run basic_check.py` to confirm the CUDA runtime is accessible.

## Summary

- The **conflict rule** in [`pyproject.toml`](https://github.com/baonguyen6742/uv-install-torch/blob/main/pyproject.toml) (lines 30-33) ensures `cpu` and `cu124` extras are mutually exclusive, requiring explicit selection
- Always invoke **`uv sync --extra cu124`** to resolve CUDA-enabled wheels from the index URLs defined at lines 24-50
- Clear the uv cache with **`uv cache clean torch`** to eliminate stale CPU wheel references
- Verify installation using **`uv pip list`** and check for the `+cu124` version suffix
- The repository's [`main.py`](https://github.com/baonguyen6742/uv-install-torch/blob/main/main.py) provides a reference implementation for testing CUDA availability after installation

## Frequently Asked Questions

### Why does uv install the CPU version of PyTorch by default?

According to the `baonguyen6742/uv-install-torch` source code, the [`pyproject.toml`](https://github.com/baonguyen6742/uv-install-torch/blob/main/pyproject.toml) defines `cpu` and `cu124` as conflicting extras. Without the `--extra cu124` flag, uv's resolver selects the CPU variant to satisfy dependency constraints, as the CPU extra requires fewer system-specific libraries.

### How do I check if my GPU supports the CUDA version in the wheels?

Run `nvidia-smi` and compare the driver version against NVIDIA's CUDA driver compatibility matrix. The repository uses `cu124` (CUDA 12.4), which requires a specific minimum driver version. If your driver is older, modify the extra in [`pyproject.toml`](https://github.com/baonguyen6742/uv-install-torch/blob/main/pyproject.toml) to use a lower CUDA version like `cu118`.

### What should I do if clearing the cache doesn't fix the detection?

Delete both the `.venv` directory and `uv.lock` file completely, then run `uv sync --extra cu124` again. This forces uv to re-resolve the entire dependency graph from scratch, ensuring no stale lockfile entries reference CPU wheels.

### Can I install PyTorch with uv for a different CUDA version?

Yes. Edit the [`pyproject.toml`](https://github.com/baonguyen6742/uv-install-torch/blob/main/pyproject.toml) file to change the index URL (lines 24-50) and the extra name from `cu124` to your target version (e.g., `cu121` for CUDA 12.1). Ensure the extra definition and conflict rules are updated to match the new version identifier.