39 |
40 | See the [documentation](https://graphcore-research.github.io/pytorch-tensor-tracker/) for more info, or for a more practical example, see our demo of [visualising transformer activations & gradients using UMAP](doc/Example.ipynb). To use on IPU with PopTorch, please see [Usage (PopTorch)](doc/UsagePopTorch.ipynb).
41 |
42 |
43 | ## License
44 |
45 | Copyright (c) 2023 Graphcore Ltd. Licensed under the MIT License ([LICENSE](LICENSE)).
46 |
47 | Our dependencies are (see [requirements.txt](requirements.txt)):
48 |
49 | | Component | About | License |
50 | | --- | --- | --- |
51 | | torch | Machine learning framework | BSD 3-Clause |
52 |
53 | We also use additional Python dependencies for development/testing (see [requirements-dev.txt](requirements-dev.txt)).
54 |
--------------------------------------------------------------------------------
/doc/UsagePopTorch.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "Copyright (c) 2023 Graphcore Ltd. All rights reserved.\n",
8 | "\n",
9 | "# Usage example (PopTorch)\n",
10 | "\n",
11 | "Create a toy model to track:"
12 | ]
13 | },
14 | {
15 | "cell_type": "code",
16 | "execution_count": 1,
17 | "metadata": {},
18 | "outputs": [],
19 | "source": [
20 | "import torch\n",
21 | "from torch import nn, Tensor\n",
22 | "\n",
23 | "class Model(nn.Module):\n",
24 | " def __init__(self):\n",
25 | " super().__init__()\n",
26 | " self.embed = nn.Embedding(10, 4)\n",
27 | " self.project = nn.Linear(4, 4)\n",
28 | " self.unembed = nn.Linear(4, 10)\n",
29 | "\n",
30 | " def forward(self, tokens: Tensor) -> Tensor:\n",
31 | " logits = self.unembed(self.project(self.embed(tokens)))\n",
32 | " return nn.functional.cross_entropy(logits, tokens)\n",
33 | "\n",
34 | "torch.manual_seed(100)\n",
35 | "module = Model()\n",
36 | "inputs = torch.randint(0, 10, (3,))"
37 | ]
38 | },
39 | {
40 | "cell_type": "markdown",
41 | "metadata": {},
42 | "source": [
43 | "**PopTorch:**\n",
44 | "\n",
45 | "A few modifications to work with PopTorch:\n",
46 | " - Any tracking should be contained within `forward()`.\n",
47 | " - We shouldn't call `tensor.cpu()`, as this is implicit on returned tensors.\n",
48 | " - We don't have access to the backward pass."
49 | ]
50 | },
51 | {
52 | "cell_type": "code",
53 | "execution_count": 8,
54 | "metadata": {},
55 | "outputs": [
56 | {
57 | "name": "stderr",
58 | "output_type": "stream",
59 | "text": [
60 | "[13:48:29.771] [poptorch:cpp] [warning] [DISPATCHER] Type coerced from Long to Int for tensor id 138\n",
61 | "Graph compilation: 100%|██████████| 100/100 [00:04<00:00]\n"
62 | ]
63 | },
64 | {
65 | "data": {
66 | "text/plain": [
67 | "[Stash(name='embed', type=| \n", 154 | " | name | \n", 155 | "type | \n", 156 | "grad | \n", 157 | "std | \n", 158 | "
|---|---|---|---|---|
| 0 | \n", 163 | "embed | \n", 164 | "torch.nn.modules.sparse.Embedding | \n", 165 | "False | \n", 166 | "0.853265 | \n", 167 | "
| 1 | \n", 170 | "project | \n", 171 | "torch.nn.modules.linear.Linear | \n", 172 | "False | \n", 173 | "0.494231 | \n", 174 | "
| 2 | \n", 177 | "unembed | \n", 178 | "torch.nn.modules.linear.Linear | \n", 179 | "False | \n", 180 | "0.581503 | \n", 181 | "
| 3 | \n", 184 | "\n", 185 | " | __main__.Model | \n", 186 | "False | \n", 187 | "NaN | \n", 188 | "
| 4 | \n", 191 | "\n", 192 | " | __main__.Model | \n", 193 | "True | \n", 194 | "NaN | \n", 195 | "
| 5 | \n", 198 | "unembed | \n", 199 | "torch.nn.modules.linear.Linear | \n", 200 | "True | \n", 201 | "0.105266 | \n", 202 | "
| 6 | \n", 205 | "project | \n", 206 | "torch.nn.modules.linear.Linear | \n", 207 | "True | \n", 208 | "0.112392 | \n", 209 | "
| 7 | \n", 212 | "embed | \n", 213 | "torch.nn.modules.sparse.Embedding | \n", 214 | "True | \n", 215 | "0.068816 | \n", 216 | "