pytorch

How to Check PyTorch Version

PyTorch is a framework primarily used for the testing and training of new Machine Learning models. As its name suggests, it is built on a combination of the “Torch” library and the “Python” programming language. The first beta version of PyTorch was released in September 2016 by Facebook which has since changed its name to Meta.

In this article, we will show how to check which version of PyTorch is installed in the IDE.

How to Check PyTorch Version?

The first public release of PyTorch, “version 0.1.0”, was announced in January 2017 by Adam Pasczke and his team. “Version 1.0” was the first steppingstone in the history of PyTorch and it was opened to the public in October 2018. Fast forward to the present, “version 2.0” was released in March 2023.

Knowing the version of PyTorch installed in the IDE can help to affirm that the specific features required for a particular project are available and resolve code compatibility issues.

Follow the steps below to check the installed version of PyTorch.

Step 1: Launch Google Colab

Open Google Colab and begin a new notebook as shown below:

Step 2: Install Required Libraries

Use the “pip” package installer from Python to install the “Torch” and “Torchvision” libraries:

!pip install torch torchvision

Torch” and “Torchvision” are the fundamental libraries that contain all the functionalities of the PyTorch framework:

Step 3: Import the Installed Libraries

Use the “import” module to import the installed libraries “Torch” and “Torchvision” into the project:

import torch
import torchvision

Step 4: Check PyTorch Version

Now, use the installed “Torch” library as the object to call the “__version__” attribute to access the Pytorch version and print the version using the “print()” method:

print(torch.__version__)

The below output indicates that we have accessed the PyTorch version:

Note: You can access our Google Colab Notebook for yourself from this link.

Pro-Tip:

There are numerous benefits to knowing which version of PyTorch is installed in IDE. It can help avoid any issues of compatibility in the code when a large team is working on the same project. Moreover, bugs and errors can be easily removed by comparing the performance of different versions.

Conclusion

To check the PyTorch version installed in the IDE, install and import the “Torch” library first into your program. After that, use the imported “torch” library along with the “__version__” attribute and pass it as the argument of the “print()” method to check and display the Pytorch version. This blog has explained how to check the Pytorch version.

About the author

Shehroz Azam

A Javascript Developer & Linux enthusiast with 4 years of industrial experience and proven know-how to combine creative and usability viewpoints resulting in world-class web applications. I have experience working with Vue, React & Node.js & currently working on article writing and video creation.