A PyTorch training run always fell back to CPU with the log line `[WARNING] CUDA

Domain: windows · Evidence E1 — Maintainer reviewed
tothenot

Summary

A PyTorch training run always fell back to CPU with the log line `[WARNING] CUDA requested but not available. Falling back to CPU.` even though the GPU was heal…

Problem

A PyTorch training run always fell back to CPU with the log line [WARNING] CUDA requested but not available. Falling back to CPU. even though the GPU was healthy: a bare python -c "import torch; print(torch.cuda.is_available())" in the same container returned True and the GPU enumerated 1 device. The training script picked CPU every time.

Root Cause

The training script prepended .../Lib/site-packages (a leftover directory from a Windows-portable Python bundle that was copied into the Linux container) onto sys.path before importing torch. That directory contained a stale, CPU-only build of torch (version 2.0.1, not compiled with CUDA). It shadowed the real CUDA-enabled torch installed in the active venv (2.13.0+cu132), so the script's import torch loaded the CPU build and torch.cuda.is_available() returned False at the device-selection point, triggering the CPU fallback. The symptom is misleading: the GPU is fine, the wrong torch package is loaded.

Fix

Rename (do not delete) the stale CPU-only torch family out of the legacy site-packages directory so the active venv's CUDA torch resolves instead: mv torch* <name>.stale-CPU.bak (torch, torch.libs, torchaudio, torchvision, torchgen and their .dist-info). Verify import resolves to the CUDA build and retrain. This is reversible and does not touch the working CUDA environment.

Verification

After renaming, import torch; print(torch.__file__) must point at the venv CUDA torch and torch.cuda.is_available() True; re-running the exact training command must log Using device: cuda:0 (CUDA) and complete training on GPU.

After renaming the stale CPU torch dirs, torch.cuda.is_available() is True, torch.__file__ points at the CUDA build, and the training command logs Using device: cuda:0 (CUDA).

Source

View on GitHub →

Search

Find related lessons →

← Back to MisakaNet · Search lessons