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 is the corresponding torch and torchvision versions and supported Python versions.

poptorch

torch

torchvision

python

2.2

1.9.0

0.10.0

>=3.6

2.1

1.7.1

0.8.2

>=3.6

2.0

1.7.1

0.8.2

>=3.6

1.4

1.6.0

0.7.0

>=3.6

Based on https://github.com/pytorch/vision/blob/master/README.rst

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.

Listing 2.1 Simple adder example
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/env python3
# Copyright (c) 2020 Graphcore Ltd. All rights reserved.

import torch
import torch.nn as nn
import poptorch

# This simple example demonstrates compiling a model to add
# two tensors together using the IPU.


class SimpleAdder(nn.Module):
    def forward(self, x, y):
        return x + y


model = SimpleAdder()
inference_model = poptorch.inferenceModel(model)

t1 = torch.tensor([1.])
t2 = torch.tensor([2.])

assert inference_model(t1, t2) == 3.0
print("Success")