Executable programs and extensions

When PyTorch seems to use the CPU despite an NVIDIA GPU

When PyTorch runs on CPU, diagnose it in the same environment

An NVIDIA GPU1 can be visible while a PyTorch2 model still runs on CPU3. In the same terminal or notebook that ran the model, use nvidia-smi to check driver detection, a read-only Python snippet to inspect the PyTorch build and CUDA4 availability, then examine model placement and application logs. nvidia-smi, torch.version.cuda, and nvcc --version report different things.

If document summarization in an IDE is slow and CPU-bound while nvidia-smi on the same computer shows a GPU, check the system, Python environment, and model device in sequence. A terminal and IDE may use different Python installations, so run diagnostics in the environment where the failure occurred.

Requirements and key details
  • nvidia-smi reports driver and GPU detection; nvcc --version reports the installed toolkit compiler.
  • torch.version.cuda is the CUDA version of the imported PyTorch build; torch.cuda.is_available() reports availability to the current process.
  • CUDA availability alone does not show whether the model is computing on GPU; also inspect model placement, application logs, and VRAM.

Check whether the driver detects the GPU

Run nvidia-smi to inspect the driver version, GPU detection, and memory use. If the command is missing or no device appears, check the operating system and driver before changing PyTorch packages. In WSL2, the Windows host provides the CUDA GPU driver; do not install a Linux NVIDIA driver inside WSL.

The CUDA Version shown by nvidia-smi is the level supported by the driver, not the installed development toolkit version. Check the toolkit compiler with nvcc --version. A prebuilt PyTorch package may include CUDA runtime5 components even when nvcc is absent, but a compatible driver is still required.

The three CUDA indicators describe different components.
How to checkWhat it tells you
nvidia-smiGPU detected by the driver and its supported CUDA level
torch.version.cudaCUDA build version of the currently imported PyTorch
nvcc --versionCompiler version of the installed CUDA development toolkit
A GPU workstation beside a driver card, software box, and compiler toolkit box
The driver, framework runtime, and development toolkit describe different parts of CUDA.

Run CUDA diagnostics in the failing Python environment

Run the code below in the same terminal or notebook where the model failed. It prints the Python path, PyTorch build, and CUDA availability for the current process; it does not run a model or tensor operation or change files.

First check that the Python path points to the expected environment. If not, correct the IDE interpreter and rerun. If torch.version.cuda is None, the imported PyTorch is likely not a CUDA build; torch.cuda.is_available() reports whether this process can use CUDA. These values may differ from the driver's CUDA level shown by nvidia-smi.

From CUDA 11 onward, minor-version compatibility within a major release is available under minimum driver conditions, with some feature limitations. New features, GPU architectures, PTX compilation, and library combinations may have additional requirements. If the result is False or an error identifies the driver, check the PyTorch selector and NVIDIA compatibility table.

Read-only CUDA availability diagnostic
import sys
import torch

print("Python:", sys.executable)
print("PyTorch:", torch.__version__)
print("PyTorch CUDA build:", torch.version.cuda)
print("CUDA available:", torch.cuda.is_available())

if torch.cuda.is_available():
    print("GPU:", torch.cuda.get_device_name(0))
    print("Device count:", torch.cuda.device_count())
This does not start model computation. Run it in the same Python environment that failed.
An empty device card, graphics card, and development toolkit box in a workspace
Check driver detection before investigating a framework or compiler.

Check the actual device in model parameters and app logs

CUDA available: True and a GPU name show that Python found a device. For a single-GPU model, next(model.parameters()).device can reveal parameter placement, but CPU may still be used if code selects it or tensor devices do not match. For a distributed model, inspect application logs and distribution settings instead of relying on the first parameter.

Run the same document summary and check whether logs record GPU selection or CPU fallback. A short request may show low GPU utilization, and VRAM6 use indicates model loading but not necessarily computation. PyTorch ROCm7 builds can use torch.cuda.* as a compatibility interface; on AMD, distinguish the backend with torch.version.hip8 and its installation guide. CUDA-specific libraries and custom operations may not work in other builds.

A local AI workspace with a monitor showing no text and a graphics card
Even when the framework sees the GPU, confirm the actual device in application logs.

Change one item based on the diagnostic result

If nvidia-smi cannot find the GPU, check the card connection and whether the operating-system driver supports the GPU. For WSL2, inspect both host and guest configuration. If the GPU and driver appear but is_available() is False, examine the failing process's Python path and PyTorch build. Select the OS, package manager, Python, and compute platform in the official PyTorch selector, then install its recommended combination in the project environment.

If CUDA is True but the model remains on CPU, check the application's CUDA backend and GPU offload9 settings, and whether the model and context fit available VRAM and headroom. Insufficient memory can move some computation to CPU or cause failure. Change one relevant option at a time, rather than changing PyTorch and the application together, then retest with the same document.

Rerun the same task and collect error details

After changing a setting, rerun the same document summary in the same IDE notebook. Check logs for GPU/backend selection and runtime errors. If the problem persists, collect the GPU model and OS, driver version and CUDA display from nvidia-smi, Python path from the failing notebook, PyTorch version, torch.version.cuda, is_available() result, application device setting, and error message.

Redact personal directory names from the Python path before sharing it. Full environment variables or a success from another Python session are not needed to explain the current failure.

Terminology notes

  1. GPU — A processor designed to handle many calculations in parallel. It performs model computations during AI inference.

    Back to the text
  2. PyTorch — A software framework for building and running AI models. Check the compatible PyTorch version and hardware support along with the model.

    Back to the text
  3. CPU — The central processor that runs the operating system and general-purpose instructions; in AI workloads it also handles tasks such as preprocessing and data movement.

    Back to the text
  4. CUDA — A software platform for general-purpose computing on NVIDIA GPUs.

    Back to the text
  5. Runtime — The software environment that provides facilities needed while a program runs. In local AI, it can also refer to a model execution engine.

    Back to the text
  6. VRAM — Memory used by a graphics card’s GPU to store model weights and intermediate values.

    Back to the text
  7. ROCm — AMD’s software platform for AI and high-performance computing on GPUs. Support depends on the combination of GPU, operating system, driver, and framework versions.

    Back to the text
  8. HIP — An API and runtime for portable GPU C++ code. It helps with porting CUDA code.

    Back to the text
  9. Offloading — Moving some model data from GPU memory to system RAM or storage when capacity is limited. This adds data transfer.

    Back to the text

Frequently asked questions

What should you check first in this article?
An NVIDIA GPU can be visible while a PyTorch model still runs on CPU. In the same terminal or notebook that ran the model, use nvidia-smi to check driver detection, a read-only Python snippet to inspect the PyTorch build and CUDA availability, then examine model placement and application logs. nvidia-smi, torch.version.cuda, and nvcc --version report different things.
How much memory does it need?
Run nvidia-smi to inspect the driver version, GPU detection, and memory use. If the command is missing or no device appears, check the operating system and driver before changing PyTorch packages. In WSL2, the Windows host provides the CUDA GPU driver; do not install a Linux NVIDIA driver inside WSL.