You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+23-13Lines changed: 23 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -8,47 +8,57 @@ See article [Clarifying exceptions and visualizing tensor operations in deep lea
8
8
9
9
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/).
10
10
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)*.
12
12
13
13
## Visualizations
14
14
15
15
For more, see [examples.ipynb](testing/examples.ipynb).
16
16
17
17
```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:
24
28
Y = W @ X.T + b
25
29
```
26
30
27
31
Displays this in a jupyter notebook or separate window:
Instead of the following default exception message:
32
36
33
37
```
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)
35
39
```
36
40
37
41
TensorSensor augments the message with more information about which operator caused the problem and includes the shape of the operands:
38
42
39
43
```
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)
41
45
```
42
46
43
47
You can also get the full computation graph for an expression that includes all of these sub result shapes.
0 commit comments