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.
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__
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
Alternatively, use the findstr
command on Windows:
pip list | findstr "torch"
2. Use the pip show
command:
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.
原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/224450.html