RUNLOCALAIv38
->Will it run?Best GPUCompareTroubleshootStartLearnPulseModelsHardwareToolsBench
Run check
RUNLOCALAI

Independently operated catalog for local-AI hardware and software. Hand-written verdicts. Source-cited claims. Reproducible commands when we have them.

OP·Fredoline Eruo
DIR
  • Models
  • Hardware
  • Tools
  • Benchmarks
TOOLS
  • Will it run?
  • Compare hardware
  • Cost vs cloud
  • Choose my GPU
  • Prompting kits
  • Quick answers
REF
  • All buyer guides
  • Learn local AI
  • Methodology
  • Glossary
  • Errors KB
  • Trust
EDITOR
  • About
  • Author
  • How we make money
  • Editorial policy
  • Contact
LEGAL
  • Privacy
  • Terms
  • Sitemap
MAIL · MONTHLY DIGEST
Get monthly local AI changes
Monthly recap. No spam.
DISCLOSURE

Some links on this site are affiliate links (Amazon Associates and other first-class retailers). When you buy through them, we earn a small commission at no extra cost to you. Affiliate links do not influence our verdicts — there are cards we rate highly that we don't have affiliate relationships with, and cards that sell well that we refuse to recommend. Read more →

© 2026 runlocalai.coIndependently operated
RUNLOCALAI · v38
  1. >
  2. Home
  3. /Learn
  4. /How-to
  5. /How to configure PyTorch with GPU support
HOW-TO · SET

How to configure PyTorch with GPU support

intermediate·15 min·By Fredoline Eruo
Target environment
Ubuntu 24.04 · Ollama 0.4.xWindows 11 · Ollama 0.4.xmacOS 15 · Ollama 0.4.x
PREREQUISITES

CUDA or ROCm installed and verified, Python 3.10+, pip

What this does

Installs the PyTorch package with GPU acceleration and verifies that the framework can detect and allocate work on the available accelerator. This is the foundation for running transformer models and inference servers on local hardware.

Steps

  1. Create and activate a virtual environment.

    python3 -m venv ~/pytorch-gpu-env
    source ~/pytorch-gpu-env/bin/activate
    

    Expected output: Prompt reflects the activated environment.

  2. Install PyTorch with the GPU-enabled index.

    pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124
    

    Expected output: Wheels downloaded and installed.

  3. Validate the installation.

    python3 -c "import torch; print('CUDA available:', torch.cuda.is_available()); print('Device:', torch.cuda.get_device_name(0))"
    

    Expected output: True on first line, GPU model string on second line.

  4. Execute a minimal matrix multiplication on the GPU.

    python3 -c "
    import torch
    a = torch.randn(4096, 4096, device='cuda')
    b = torch.randn(4096, 4096, device='cuda')
    c = a @ b
    print('GPU compute succeeded, result shape:', c.shape)
    "
    

    Expected output: GPU compute succeeded, result shape: torch.Size([4096, 4096])

Verification

python3 -c "import torch; print('CUDA:', torch.cuda.is_available(), 'Count:', torch.cuda.device_count(), 'Name:', torch.cuda.get_device_name(0))"
# Expected: CUDA: True Count: 1 Name: <GPU model>

Common failures

  • torch.cuda.is_available() returns False — The PyTorch build does not match host CUDA version. Reinstall from the correct index URL.
  • CUDA error: no kernel image is available for execution — NVIDIA driver is older than the CUDA toolkit used to build PyTorch. Upgrade the driver.
  • No module named 'torch' — Run install inside the activated virtual environment.
  • cuDNN not detected — Ensure libcudnn8 is installed and visible to Python.
  • Out-of-memory error — Reduce tensor size or close other GPU processes. Run nvidia-smi to inspect memory.

Related guides

  • How to verify CUDA setup for AI workloads
  • How to install NVIDIA Container Toolkit for Docker
  • Course Local AI Fundamentals
RELATED GUIDES
SET
How to install NVIDIA Container Toolkit for Docker
SET
How to verify CUDA setup for AI workloads
← All how-to guidesCourses →