Skip to main content

How to Check Which Version of PyTorch Is Installed

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

Before you follow a guide or report a problem, you need to know which PyTorch you have, and whether it was built with CUDA. PyTorch tells you both from Python. This guide reads them for PyTorch 2.15.0 on an Apple M1 Pro, then reads the version without importing PyTorch at all.

Syntax​

Syntax
torch.__version__
torch.version.cuda
PartWhat it gives
torch.__version__PyTorch's version as text, such as 2.15.0. Some builds add a label after a + that says what they were built for: +cu132 for CUDA 13.2, +cpu for the processor only
torch.version.cudaThe version of CUDA the build was made with, as text such as 13.2, or None for a build without CUDA

The Example​

A two-line script prints both values in a project that has PyTorch.

Prerequisites​

  • A uv project with PyTorch. This guide uses PyTorch 2.15.0 with NumPy 2.5.5 on Python 3.15.2 and uv 0.13.10, on an Apple M1 Pro. Without NumPy in the project, PyTorch also prints a NumPy warning when it starts.

Step 1: Write the Script​

versions.py
import torch

print(torch.__version__)
print(torch.version.cuda)

The versions.py script in a macOS-style code window: import torch, then print torch.version and torch.version.cuda.

Step 2: Run It​

Terminal
uv run python versions.py
Output
2.15.0
None

The terminal after uv run python versions.py: 2.15.0, then None.

PyTorch is version 2.15.0. torch.version.cuda is None because PyTorch for the Mac is built without CUDA. That doesn't mean there's no GPU: on an Apple silicon Mac, PyTorch reaches the GPU through MPS instead. The command works unchanged in PowerShell.

I could run it only on this Mac. Every build of PyTorch keeps these two values in a small file, torch/version.py, and reading that file inside the other published builds of PyTorch 2.15.0 shows what they print:

Build of PyTorch 2.15.0torch.__version__torch.version.cuda
macOS, from PyPI (the run above)2.15.0None
Linux on x86-64, from PyPI2.15.0+cu13213.2
Windows, from PyPI2.15.0+cpuNone
Windows, from PyTorch's CUDA 13.2 index2.15.0+cu13213.2

Step 3: Check It Without Importing PyTorch​

Importing PyTorch takes a few seconds. uv can read the version from the project's environment instead:

Terminal
uv pip show torch
Output
Name: torch
Version: 2.15.0
Location: /Users/you/source/pytorch-basics/.venv/lib/python3.15/site-packages
Requires: filelock, fsspec, jinja2, networkx, setuptools, sympy, typing-extensions
Required-by: pytorch-basics

The terminal after uv pip show torch: Name torch, Version 2.15.0, its location in the project's .venv, and the packages it requires.

Version: 2.15.0 matches. Requires lists the packages PyTorch itself depends on, and Required-by names the project. uv pip show reads the package's own records, which leave out the + label for PyPI's builds: PyPI's Linux build records 2.15.0, while its torch.__version__ says 2.15.0+cu132. How to Check the Installed Version of a Python Package with uv covers uv pip show and the other ways uv reports versions.

Common Mistakes​

MistakeWhat happensDo this instead
torch.version instead of torch.__version__print(torch.version) printed <module 'torch.version' from '…/torch/version.py'>: the module that holds the values, not the versionPrint torch.__version__
Reading None from torch.version.cuda as "no GPU"On a Mac, MPS still uses the GPUCheck the GPU directly
Running the check with the system's PythonIt reports another install, or none at allRun it with uv run in the project

FAQ​

What does +cu132 mean in a version?​

The build was made with CUDA 13.2, so it can use an NVIDIA GPU. PyPI's Linux build is one; on Windows, the CUDA build comes from PyTorch's own index, as How to Install PyTorch with CUDA Using uv shows.

How do I compare versions in code?​

Compare torch.__version__ with the version as text. It compares as a version, which plain text doesn't:

version_order.py
import torch

print(type(torch.__version__))
print(torch.__version__ >= "2.9")
print("2.15.0" >= "2.9")
Terminal
uv run python version_order.py
Output
<class 'torch.torch_version.TorchVersion'>
True
False

torch.__version__ is a TorchVersion, text that knows 2.15 comes after 2.9. Plain text compares character by character, and 1 comes before 9, so "2.15.0" >= "2.9" is False.

Conclusion​

torch.__version__ printed 2.15.0 and torch.version.cuda printed None on an Apple M1 Pro, whose PyTorch is built without CUDA. PyTorch's Linux and Windows builds label their version +cu132 or +cpu. uv pip show torch read the version without importing PyTorch.

Additional Resources​