Skip to content

Commit a77936c

Browse files
committed
update the readme
1 parent f8011d1 commit a77936c

File tree

5 files changed

+1450
-387
lines changed

5 files changed

+1450
-387
lines changed

README.md

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,47 +8,57 @@ See article [Clarifying exceptions and visualizing tensor operations in deep lea
88

99
To help myself and other programmers debug tensor code, I built this library. TensorSensor clarifies exceptions by augmenting messages and visualizing Python code to indicate the shape of tensor variables (see figure to the right for a teaser). It works with [Tensorflow](https://www.tensorflow.org/), [PyTorch](https://pytorch.org/), [JAX](https://github.com/google/jax), and [Numpy](https://numpy.org/), as well as higher-level libraries like [Keras](https://keras.io/) and [fastai](https://www.fast.ai/).
1010

11-
*TensorSensor is currently at 0.1.2 (May 2021) so I'm happy to receive issues created at this repo or direct email*.
11+
*TensorSensor is currently at 1.0 (December 2021)*.
1212

1313
## Visualizations
1414

1515
For more, see [examples.ipynb](testing/examples.ipynb).
1616

1717
```python
18-
import torch
19-
import tsensor
20-
W = torch.rand(d,n_neurons)
21-
b = torch.rand(n_neurons,1)
22-
X = torch.rand(n,d)
23-
with tsensor.clarify():
18+
import numpy as np
19+
20+
n = 200 # number of instances
21+
d = 764 # number of instance features
22+
n_neurons = 100 # how many neurons in this layer?
23+
24+
W = np.random.rand(d,n_neurons)
25+
b = np.random.rand(n_neurons,1)
26+
X = np.random.rand(n,d)
27+
with tsensor.clarify() as c:
2428
Y = W @ X.T + b
2529
```
2630

2731
Displays this in a jupyter notebook or separate window:
2832

29-
<img src="https://explained.ai/tensor-sensor/images/mm.svg">
33+
<img src="images/mm.svg">
3034

3135
Instead of the following default exception message:
3236

3337
```
34-
RuntimeError: size mismatch, m1: [764 x 100], m2: [764 x 200] at /tmp/pip-req-build-as628lz5/aten/src/TH/generic/THTensorMath.cpp:41
38+
ValueError: matmul: Input operand 1 has a mismatch in its core dimension 0, with gufunc signature (n?,k),(k,m?)->(n?,m?) (size 764 is different from 100)
3539
```
3640

3741
TensorSensor augments the message with more information about which operator caused the problem and includes the shape of the operands:
3842

3943
```
40-
Cause: @ on tensor operand W w/shape [764, 100] and operand X.T w/shape [764, 200]
44+
Cause: @ on tensor operand W w/shape (764, 100) and operand X.T w/shape (764, 200)
4145
```
4246

4347
You can also get the full computation graph for an expression that includes all of these sub result shapes.
4448

4549
```python
46-
tsensor.astviz("b = W@b + (h+3).dot(h) + torch.abs(torch.tensor(34))", sys._getframe())
50+
W = torch.rand(size=(2000,2000), dtype=torch.float64)
51+
b = torch.rand(size=(2000,1), dtype=torch.float64)
52+
h = torch.zeros(size=(1_000_000,), dtype=int)
53+
x = torch.rand(size=(2000,1))
54+
z = torch.rand(size=(2000,1), dtype=torch.complex64)
55+
56+
tsensor.astviz("b = W@b + (h+3).dot(h) + z", sys._getframe())
4757
```
4858

4959
yields the following abstract syntax tree with shapes:
5060

51-
<img src="images/ast.svg" width="400">
61+
<img src="images/ast.svg" width="250">
5262

5363
## Install
5464

@@ -70,7 +80,7 @@ $ pip list | grep -i numpy
7080
numpy 1.19.5
7181
numpydoc 1.1.0
7282
$ pip list | grep -i torch
73-
torch 1.9.0
83+
torch 1.10.0
7484
torchvision 0.10.0
7585
$ pip list | grep -i jax
7686
jax 0.2.20

0 commit comments

Comments
 (0)