DEV Community

torch.cuda.is_available() Returns False on RunPod: What It Means and What To Do Before Billing Starts

You SSH into your pod. You run your training script. The loss starts printing. Everything looks normal. Except it is running at 24 seconds per iteration instead of 0.4.

That is how I found out torch.cuda.is_available() had returned False on a Vast.ai pod a failure that hits RunPod users equally. No exception. No warning. My script resolved to CPU and kept running. I was paying full GPU rates and training on CPU the entire time.

Why this happens without an error

torch.cuda.is_available() returns False when PyTorch cannot find a usable CUDA installation. The reasons vary:

  • PyTorch was installed without CUDA support a CPU-only build (torch+cpu) instead of a CUDA build (torch+cu121, torch+cu124 etc)
  • The host NVIDIA driver does not meet the compatibility requirements for the CUDA runtime PyTorch was compiled against
  • CUDA_VISIBLE_DEVICES is set to an empty string or -1, hiding all GPUs from PyTorch the GPU may still appear in nvidia-smi but PyTorch cannot see it
  • The NVIDIA driver failed to load correctly on this pod

None of these throw an exception at import time. PyTorch imports cleanly. nvidia-smi may show the GPU. The failure only surfaces when your code tries to use CUDA or never surfaces at all if your script silently falls back to CPU.

The silent fallback is the expensive case

Most training scripts use the standard pattern:

device = "cuda" if torch.cuda.is_available() else "cpu"

When CUDA is unavailable, the script continues on CPU with no error and no warning. On a rented pod you typically will not notice until you check iteration speed or run nvidia-smi and see GPU utilisation at 0%.

By then you have already paid for the warmup time, the dependency install, and however long training ran before you caught it. The hard guard below stops your training script from running but the pod is still billing while you diagnose. The goal is to catch this before you start the job, not after.

Diagnose it in 10 seconds

python3 -c "import torch; print(torch.__version__, torch.version.cuda, torch.cuda.is_available())"

If is_available() prints False, check:

  • Is the GPU visible at the system level? nvidia-smi
  • Which PyTorch build is installed? pip show torch | grep -i version
  • Is CUDA_VISIBLE_DEVICES hiding GPUs? echo $CUDA_VISIBLE_DEVICES

If torch.version.cuda is None, you have a CPU-only build. That is the most common cause on a fresh pod with the wrong template selected.

Fix by cause

  • CPU-only build (torch.version.cuda is None): pip install --force-reinstall torch --index-url .../whl/cu124
  • CUDA_VISIBLE_DEVICES set to "" or -1: unset CUDA_VISIBLE_DEVICES or export CUDA_VISIBLE_DEVICES=0
  • Driver not loaded or incompatible: Terminate the pod and rent a fresh one driver issues don't resolve inside the container

Reinstalling PyTorch: A plain pip install torch will often do nothing if torch is already installed pip sees the version requirement as satisfied. Force a clean replacement:

pip install --force-reinstall torch --index-url https://download.pytorch.org/whl/cu124

Check pytorch.org/get-started/locally for the right CUDA build for your environment. Do not assume cu124 is correct for every pod.

Add a hard guard to your training script

The standard "cuda" if torch.cuda.is_available() else "cpu" pattern is a liability on rented compute. Replace it:

import torch
if not torch.cuda.is_available():
    raise RuntimeError(
        "CUDA not available. Check PyTorch build, CUDA_VISIBLE_DEVICES, "
        "and nvidia-smi before starting a paid job."
    )
device = torch.device("cuda")

This turns a silent CPU fallback into a hard error at line one.

Catch it automatically before every job

uvx computefence doctor

Real output from a machine with no PyTorch installed:

ComputeFence v0.3.3 - Pre-flight diagnostic โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ” 4 WARNINGS ยท 0 BLOCKERS ยท 2 PASSED Environment โœ“ Python 3.14.3 โš  PyTorch not found - skipping GPU checks Fix: pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118

This output is from a Mac with no PyTorch installed the fix command shows cu118 as a safe default. On a Linux pod the right CUDA wheel depends on your driver version; check pytorch.org/get-started/locally for the correct build. When PyTorch is present but CUDA is unavailable, the torch_cuda check fires instead.

Chain it with your training command so the job never starts if something is wrong:

uvx computefence doctor && python train.py

GitHub: github.com/Francisco-Booth/ComputeFence Install: pip install computefence

Read on DEV Community ↗ ← Back to News

Comments

No comments yet. Start the discussion.