Here you will learn how to check PyTorch version in Python or from command line through your Python package manager
You should have installed PyTorch already, which is the assumption of this tutorial. If you have not install PyTorch, search install PyTorch — we have written a bunch of tutorial on this for various versions.
Use Python code to check PyTorch version
If you are in the Python interpreter or want to use programmingly check PyTorch version, use
torch.__version__. Note that if you haven’t import PyTorch, you need to use
import torch in the beginning of your Python script or before the print statement below.
import torch print(torch.__version__)
Use pip to check PyTorch package version
If you have used
pip to install PyTorch, you can use
pip3 show to check the details of PyTorch. Note that
pip show may also work.
pip3 show torch
You will see something like below. The second line starting with version will show which version have you installed or updated PyTorch. Here I have installed 1.5.1. The
+cu101 means my cuda version is 10.1. This is because I am running Ubuntu 20.04, which comes with CUDA 10.1 by default. We wrote a tutorial before on how to install PyTorch on Ubuntu 20.04.
Here is the full output in text for your reference:
vh@varhowto-com:~$ pip3 show torch Name: torch Version: 1.5.1+cu101 Summary: Tensors and Dynamic neural networks in Python with strong GPU acceleration Home-page: https://pytorch.org/ Author: PyTorch Team Author-email: email@example.com License: BSD-3 Location: /home/vh/.local/lib/python3.8/site-packages Requires: future, numpy Required-by: torchvision
Use conda to check PyTorch package version
Similar to pip, if you used Anaconda to install PyTorch. you can use the command
conda list to check its detail which also include the version info.
conda list -f pytorch
You you want to check in another environment, e.g.,
pytorch14 below, use
-n like this:
conda list -n pytorch14 -f pytorch
What is PyTorch?
PyTorch is an open-source Deep Learning framework for research, stable and enabling implementation that is scalable and flexible. This enables quick, scalable testing through an autograding component designed for fast and python-like execution. The framework now has graph-based execution with the release of PyTorch 1.0, a hybrid front-end that allows for seamless mode switching, interactive monitoring, and efficient and stable implementation on mobile platforms.
PyTorch has 4 key features according to its official homepage.
- PyTorch is production-ready: TorchScript smoothly toggles between eager and graph modes. TorchServe speeds up the production process.
- PyTorch support distributed training: The torch.collaborative interface allows for efficient distributed training and performance optimization in research and development.
- PyTorch has a robust ecosystem: It has an expansive ecosystem of tools and libraries to support applications such as computer vision and NLP.
- PyTorch has native cloud support: It is well recognized for its zero-friction development and fast scaling on key cloud providers.
[summary] 3 Ways to Check PyTorch Version
- [Python] Write Python code to check PyTorch version
You can use
torch.__version__to check the version of PyTorch. If you have not imported PyTorch, use
- [pip] Use pip3 to check the PyTorch package information
If you used pip to install PyTorch, run
pip3 show torchto show all the information of the installation, which also includes the version of PyTorch.
- [conda] Use
conda listto show the PyTorch package information
If you used Anaconda or Miniconda to install PyTorch, you can use
conda list -f pytorchto check PyTorch package's information, which also includes its version.
If you want to check PyTorch version for a specific environment such as
conda list -n pytorch14 -f pytorch.