2. Installation
PopTorch is part of the Poplar SDK. It is packaged as a Python wheel
file that can be installed using pip
.
Important
pip >= 18.1 is required for PopTorch dependencies to be installed properly.
To update pip
:
$ pip install -U pip
For more information about installing the Poplar SDK, see the relevant “Getting Started” guide for your IPU system on the Graphcore documentation portal.
2.1. Version compatibility
The following are the corresponding torch
, torchvision
, torchaudio
and
torch_scatter
versions and supported Python versions.
|
|
|
|
|
|
---|---|---|---|---|---|
3.3 |
2.0.1 |
0.15.2 |
2.0.1 |
>=2.0.9 and <=2.1.1 |
>=3.8 |
3.2 |
1.13.1 |
0.14.1 |
0.13.1 |
>=2.0.9 and <=2.1.0 |
>=3.7 |
3.1 |
1.13.0 |
0.14.0 |
0.13.0 |
>=2.0.9 and <=2.1.0 |
>=3.7 |
3.0 |
1.10.0 |
0.11.1 |
0.10.0 |
N/A |
>=3.6 |
2.6 |
1.10.0 |
0.11.1 |
0.10.0 |
N/A |
>=3.6 |
2.5 |
1.10.0 |
0.11.1 |
0.10.0 |
N/A |
>=3.6 |
2.4 |
1.10.0 |
0.11.1 |
0.10.0 |
N/A |
>=3.6 |
2.3 |
1.9.0 |
0.10.0 |
0.9.0 |
N/A |
>=3.6 |
2.2 |
1.9.0 |
0.10.0 |
0.9.0 |
N/A |
>=3.6 |
2.1 |
1.7.1 |
0.8.2 |
0.7.1 |
N/A |
>=3.6 |
2.0 |
1.7.1 |
0.8.2 |
0.7.1 |
N/A |
>=3.6 |
1.4 |
1.6.0 |
0.7.0 |
0.6.0 |
N/A |
>=3.6 |
Based on https://github.com/pytorch/vision/blob/master/README.md
Note
To ensure version compatibility, torchvision
and torchaudio
are automatically installed with PopTorch in Poplar SDK 3.3 and later.
2.2. Using a Python virtual environment
We recommend creating a virtual environment to isolate your PopTorch environment
from the system Python environment. You can use the Python tool virtualenv
for this. You can create a virtual environment and install PopTorch as shown below:
$ virtualenv -p python3 poptorch_test
$ source poptorch_test/bin/activate
$ pip install -U pip
$ pip install <sdk_path>/poptorch_x.x.x.whl
2.3. Setting the environment variables
The PopART and Poplar runtime libraries are required to use PopTorch, so you will need to set the library search paths, using the scripts provided in the SDK:
# Enable the Python environment containing PopTorch (if not already enabled)
$ source poptorch_test/bin/activate
# Add the Poplar and PopART runtime libraries to the search path
$ source <path to poplar installation>/enable.sh
$ source <path to popart installation>/enable.sh
2.4. Validating the setup
You can run this simple example to verify that the system is working as expected. This example can be found in the Poplar SDK installation.
1#!/usr/bin/env python3
2# Copyright (c) 2020 Graphcore Ltd. All rights reserved.
3
4import torch
5import torch.nn as nn
6import poptorch
7
8# This simple example demonstrates compiling a model to add
9# two tensors together using the IPU.
10
11
12class SimpleAdder(nn.Module):
13 def forward(self, x, y):
14 return x + y
15
16
17model = SimpleAdder()
18inference_model = poptorch.inferenceModel(model)
19
20t1 = torch.tensor([1.])
21t2 = torch.tensor([2.])
22
23assert inference_model(t1, t2) == 3.0
24print("Success")