PyTorch can be installed and used on macOS. Depending on your system and GPU capabilities, your experience with PyTorch on macOS may vary in terms of processing time.
Prerequisites macOS VersionPyTorch is supported on macOS 10.15 (Catalina) or above.
PythonIt is recommended that you use Python 3.9 - 3.12. You can install Python either through Homebrew or the Python website.
Package ManagerTo install the PyTorch binaries, you will need to use the supported package manager: pip.
pipPython 3
If you installed Python via Homebrew or the Python website, pip
was installed with it. If you installed Python 3.x, then you will be using the command pip3
.
Installation pipTip: If you want to use just the command
pip
, instead ofpip3
, you can symlinkpip
to thepip3
binary.
To install PyTorch via pip, use the following command, depending on your Python version:
# Python 3.x
pip3 install torch torchvision
Verification
To ensure that PyTorch was installed correctly, we can verify the installation by running sample PyTorch code. Here we will construct a randomly initialized tensor.
import torch
x = torch.rand(5, 3)
print(x)
The output should be something similar to:
tensor([[0.3380, 0.3845, 0.3217],
[0.8337, 0.9050, 0.2650],
[0.2979, 0.7141, 0.9069],
[0.1449, 0.1132, 0.1375],
[0.4675, 0.3947, 0.1426]])
Building from source
For the majority of PyTorch users, installing from a pre-built binary via a package manager will provide the best experience. However, there are times when you may want to install the bleeding edge PyTorch code, whether for testing or actual development on the PyTorch core. To install the latest PyTorch code, you will need to build PyTorch from source.
PrerequisitesYou can verify the installation as described above.
Installing on LinuxPyTorch can be installed and used on various Linux distributions. Depending on your system and compute requirements, your experience with PyTorch on Linux may vary in terms of processing time. It is recommended, but not required, that your Linux system has an NVIDIA or AMD GPU in order to harness the full power of PyTorch’s CUDA support or ROCm support.
Prerequisites Supported Linux DistributionsPyTorch is supported on Linux distributions that use glibc >= v2.28, which include the following:
PythonThe install instructions here will generally apply to all supported Linux distributions. An example difference is that your distribution may support
yum
instead ofapt
. The specific examples shown were run on an Ubuntu 18.04 machine.
Python 3.9-3.12 is generally installed by default on any of our supported Linux distributions, which meets our recommendation.
Tip: By default, you will have to use the command
python3
to run Python. If you want to use just the commandpython
, instead ofpython3
, you can symlinkpython
to thepython3
binary.
However, if you want to install another version, there are multiple ways:
If you decide to use APT, you can run the following command to install it:
Package ManagerTo install the PyTorch binaries, you will need to use the supported package manager: pip.
pipPython 3
While Python 3.x is installed by default on Linux, pip
is not installed by default.
sudo apt install python3-pip
Installation pip No CUDATip: If you want to use just the command
pip
, instead ofpip3
, you can symlinkpip
to thepip3
binary.
To install PyTorch via pip, and do not have a CUDA-capable or ROCm-capable system or do not require CUDA/ROCm (i.e. GPU support), in the above selector, choose OS: Linux, Package: Pip, Language: Python and Compute Platform: CPU. Then, run the command that is presented to you.
With CUDATo install PyTorch via pip, and do have a CUDA-capable system, in the above selector, choose OS: Linux, Package: Pip, Language: Python and the CUDA version suited to your machine. Often, the latest CUDA version is better. Then, run the command that is presented to you.
With ROCmTo install PyTorch via pip, and do have a ROCm-capable system, in the above selector, choose OS: Linux, Package: Pip, Language: Python and the ROCm version supported. Then, run the command that is presented to you.
VerificationTo ensure that PyTorch was installed correctly, we can verify the installation by running sample PyTorch code. Here we will construct a randomly initialized tensor.
import torch
x = torch.rand(5, 3)
print(x)
The output should be something similar to:
tensor([[0.3380, 0.3845, 0.3217],
[0.8337, 0.9050, 0.2650],
[0.2979, 0.7141, 0.9069],
[0.1449, 0.1132, 0.1375],
[0.4675, 0.3947, 0.1426]])
Additionally, to check if your GPU driver and CUDA/ROCm is enabled and accessible by PyTorch, run the following commands to return whether or not the GPU driver is enabled (the ROCm build of PyTorch uses the same semantics at the python API level link, so the below commands should also work for ROCm):
import torch
torch.cuda.is_available()
Building from source
For the majority of PyTorch users, installing from a pre-built binary via a package manager will provide the best experience. However, there are times when you may want to install the bleeding edge PyTorch code, whether for testing or actual development on the PyTorch core. To install the latest PyTorch code, you will need to build PyTorch from source.
PrerequisitesYou can verify the installation as described above.
Installing on WindowsPyTorch can be installed and used on various Windows distributions. Depending on your system and compute requirements, your experience with PyTorch on Windows may vary in terms of processing time. It is recommended, but not required, that your Windows system has an NVIDIA GPU in order to harness the full power of PyTorch’s CUDA support.
Prerequisites Supported Windows DistributionsPyTorch is supported on the following Windows distributions:
PythonThe install instructions here will generally apply to all supported Windows distributions. The specific examples shown will be run on a Windows 10 Enterprise machine
Currently, PyTorch on Windows only supports Python 3.9-3.12; Python 2.x is not supported.
As it is not installed by default on Windows, there are multiple ways to install Python:
If you decide to use Chocolatey, and haven’t installed Chocolatey yet, ensure that you are running your command prompt as an administrator.
For a Chocolatey-based install, run the following command in an administrative command prompt:
Package ManagerTo install the PyTorch binaries, you will need to use the supported package manager: pip.
pipIf you installed Python by any of the recommended ways above, pip will have already been installed for you.
Installation pip No CUDATo install PyTorch via pip, and do not have a CUDA-capable system or do not require CUDA, in the above selector, choose OS: Windows, Package: Pip and CUDA: None. Then, run the command that is presented to you.
With CUDATo install PyTorch via pip, and do have a CUDA-capable system, in the above selector, choose OS: Windows, Package: Pip and the CUDA version suited to your machine. Often, the latest CUDA version is better. Then, run the command that is presented to you.
VerificationTo ensure that PyTorch was installed correctly, we can verify the installation by running sample PyTorch code. Here we will construct a randomly initialized tensor.
From the command line, type:
then enter the following code:
import torch
x = torch.rand(5, 3)
print(x)
The output should be something similar to:
tensor([[0.3380, 0.3845, 0.3217],
[0.8337, 0.9050, 0.2650],
[0.2979, 0.7141, 0.9069],
[0.1449, 0.1132, 0.1375],
[0.4675, 0.3947, 0.1426]])
Additionally, to check if your GPU driver and CUDA is enabled and accessible by PyTorch, run the following commands to return whether or not the CUDA driver is enabled:
import torch
torch.cuda.is_available()
Building from source
For the majority of PyTorch users, installing from a pre-built binary via a package manager will provide the best experience. However, there are times when you may want to install the bleeding edge PyTorch code, whether for testing or actual development on the PyTorch core. To install the latest PyTorch code, you will need to build PyTorch from source.
PrerequisitesYou can verify the installation as described above.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4