How to Check PyTorch Version

Introduction

PyTorch is a well-known neural network and machine learning library for Python. The module is famous for working great on a GPU infrastructure. The continuously updated library offers different functionalities for various versions.

There are many ways to find out which PyTorch version you have, depending on how you installed the library and which environment you are using.

This article shows how to check the PyTorch version on a local machine using various methods.

How to Check PyTorch Version

Prerequisites

  • Python version 3 installed and configured.
  • PyTorch installed.
  • Access to the command line or terminal.

Note: The latest Python version is 3.9 at the time of writing this article. If you want to upgrade, follow our tutorial: How to Upgrade Python to 3.9.

Using Python Code

To check the PyTorch version using Python code:

1. Open the terminal or command prompt and run Python:

python3

2. Import the torch library and check the version:

import torch;
torch.__version__
Output of checking PyTorch version in Python

The output prints the installed PyTorch version along with the CUDA version. For example, 1.9.0+cu102 means the PyTorch version is 1.9.0, and the CUDA version is 10.2.

Alternatively, use your favorite Python IDE or code editor and run the same code.

Using pip

If you installed the torch package via pip, there are two ways to check the PyTorch version.

1. Use the pip list command together with grep to filter out the results from the list:

pip list | grep torch
Terminal output of pip list grep torch

Alternatively, use the findstr command on Windows:

pip list | findstr "torch"

2. Use the pip show command:

pip show torch
Terminal output of pip show torch

The output prints detailed information about the package, including the version.

Using conda

The conda package manager comes with the Anaconda installation by default.

If you used conda to install PyTorch, check the version with:

conda list | grep "torch"

On Windows, use:

conda list | findstr "torch"

As a result, the output shows the torch library as pytorch along with the version number.

Conclusion

After this tutorial, you should know the version PyTorch version installed on your system. To see what's available in your version of the library, read the official documentation and plan your project accordingly.

For additional materials, check out our comparison of PyTorch vs. TensorFlow.

Was this article helpful?
YesNo
Milica Dancuk
Milica Dancuk is a technical writer at phoenixNAP who is passionate about programming. Her background in Electrical Engineering and Computing combined with her teaching experience give her the ability to easily explain complex technical concepts through her content.
Next you should read
Handling Missing Data in Python: Causes and Solutions
July 1, 2021

Some machine learning algorithms won't work with missing data. Learn how to discover if your dataset has missing information, what the causes...
Read more
Python Data Types {Comprehensive Overview}
April 1, 2021

Every programming language has their own set of built-in data types. In Python, data types provide information about a variable and what operations...
Read more
How To Check TensorFlow Version
March 3, 2021

TensorFlow can be installed in many ways and there are many different versions and builds available. Learn how to check which version is installed on your machine.
Read more
How to Install Keras With TensorFlow Backend on Linux
August 24, 2020

Follow the step by step instructions to learn how to prepare your system for the installation of Keras and TensorFlow. We also talk about...
Read more