(Optional) Local installation

Last updated: January 4, 2023

Installing PyTorch on your machine is entirely optional as you can run everything on the training cluster. If you would like to practice on your machine in addition to (or instead of) the training cluster, this lesson will guide you through the setup of your machine. Please note that we won't be debugging local installations.

Python and package manager

First of all, you need Python 3.7 or higher and a package manager (to install Python packages).

There are many ways to go about this. For those new to Python, I suggest installing Anaconda:

Go to the Anaconda Installers section at the bottom of this page, download and install the 64-Bit installer for your operating system (unless you still have a 32-Bit version of Windows of course, but those are becoming rare).

Notes:

  • Anaconda is extremely convenient on personal computers. It is also huge since it installs a whole suite of scientific Python packages. If you are looking for a much leaner installation than Anaconda, Miniconda3 will only install Python 3.7, the package manager conda, and their dependencies.
  • Those on Linux, depending on their distro, can also install Python packages with their distribution package manager.
  • While Anaconda is a good option on personal computers, this is NOT the way to go once you move to the Compute Canada clusters.

Python packages

Then, you need 4 Python packages: Matplotlib, PyTorch, TorchVision, and TensorBoard.

Matplotlib

Matplotlib is already packaged with Anaconda. So if you installed Anaconda as suggested above, you are done. Those who chose an alternative method can find information on how to install Matplotlib here.

PyTorch and TorchVision

Use this page to find the command you need to run based on your operating system and whether or not you have CUDA (this only concerns you if you have an Nvidia GPU).

I recommend using the Stable (1.5) build.

Examples:

  • You are on Windows, you installed Anaconda as suggested above, and you do not have CUDA, then:

Launch the Anaconda Prompt (for instance by typing it in the main Windows search box or by going to Start | Anaconda3 | Anaconda Prompt ) and type:

conda install pytorch torchvision cpuonly -c pytorch
  • You are on a Mac and you do not have CUDA, then run in Terminal:
conda install pytorch torchvision -c pytorch
  • Etc.

Test the installation

Make sure that all works by launching Python, loading the torch package and creating a 2-dimensional tensor filled with zeros:

[In]

import torch

print(torch.zeros(3, 4))

[Out]

tensor([[0., 0., 0., 0.],
        [0., 0., 0., 0.],
        [0., 0., 0., 0.]])

Note: if you have a CUDA-enabled GPU on your machine and you want to test whether it is accessible to PyTorch, you can run:

[In]

print(torch.cuda.is_available())

[Out]

True

TensorBoard

Install TensorBoard with:

pip install tensorboard

Comments & questions