All Projects → parrt → Tensor Sensor

parrt / Tensor Sensor

Licence: mit
The goal of this library is to generate more helpful exception messages for numpy/pytorch matrix algebra expressions.

Projects that are alternatives of or similar to Tensor Sensor

Matrex
A blazing fast matrix library for Elixir/Erlang with C implementation using CBLAS.
Stars: ✭ 429 (-19.36%)
Mutual labels:  matrix, jupyter-notebook, numpy
Pyrr
3D mathematical functions using NumPy
Stars: ✭ 282 (-46.99%)
Mutual labels:  matrix, vector, numpy
Python Notlarim
Python notes in Turkish.
Stars: ✭ 356 (-33.08%)
Mutual labels:  jupyter-notebook, numpy
Stats Maths With Python
General statistics, mathematical programming, and numerical/scientific computing scripts and notebooks in Python
Stars: ✭ 381 (-28.38%)
Mutual labels:  jupyter-notebook, numpy
Deep learning nlp
Keras, PyTorch, and NumPy Implementations of Deep Learning Architectures for NLP
Stars: ✭ 407 (-23.5%)
Mutual labels:  jupyter-notebook, numpy
Numpy neural network
仅使用numpy从头开始实现神经网络,包括反向传播公式推导过程; numpy构建全连接层、卷积层、池化层、Flatten层;以及图像分类案例及精调网络案例等,持续更新中... ...
Stars: ✭ 339 (-36.28%)
Mutual labels:  jupyter-notebook, numpy
Thesemicolon
This repository contains Ipython notebooks and datasets for the data analytics youtube tutorials on The Semicolon.
Stars: ✭ 345 (-35.15%)
Mutual labels:  jupyter-notebook, numpy
Workshopscipy
A workshop for scientific computing in Python. ( December 2017 )
Stars: ✭ 391 (-26.5%)
Mutual labels:  jupyter-notebook, numpy
Python
This repository helps you understand python from the scratch.
Stars: ✭ 285 (-46.43%)
Mutual labels:  jupyter-notebook, numpy
Pytablewriter
pytablewriter is a Python library to write a table in various formats: CSV / Elasticsearch / HTML / JavaScript / JSON / LaTeX / LDJSON / LTSV / Markdown / MediaWiki / NumPy / Excel / Pandas / Python / reStructuredText / SQLite / TOML / TSV.
Stars: ✭ 422 (-20.68%)
Mutual labels:  jupyter-notebook, numpy
Dsp Theory
Theory of digital signal processing (DSP): signals, filtration (IIR, FIR, CIC, MAF), transforms (FFT, DFT, Hilbert, Z-transform) etc.
Stars: ✭ 437 (-17.86%)
Mutual labels:  jupyter-notebook, numpy
Gdrl
Grokking Deep Reinforcement Learning
Stars: ✭ 304 (-42.86%)
Mutual labels:  jupyter-notebook, numpy
Tensorwatch
Debugging, monitoring and visualization for Python Machine Learning and Data Science
Stars: ✭ 3,191 (+499.81%)
Mutual labels:  jupyter-notebook, debugging
Pytorch Tutorials Examples And Books
PyTorch1.x tutorials, examples and some books I found 【不定期更新】整理的PyTorch 1.x 最新版教程、例子和书籍
Stars: ✭ 346 (-34.96%)
Mutual labels:  jupyter-notebook, numpy
Tapping device
TappingDevice makes objects tell you what they do, so you don't need to track them yourself.
Stars: ✭ 296 (-44.36%)
Mutual labels:  tracing, debugging
Armadillo Code
Armadillo: fast C++ library for linear algebra & scientific computing - http://arma.sourceforge.net
Stars: ✭ 388 (-27.07%)
Mutual labels:  matrix, vector
Pysynth
Several simple music synthesizers in Python 3. Input from ABC or MIDI files is also supported.
Stars: ✭ 279 (-47.56%)
Mutual labels:  jupyter-notebook, numpy
Re Frame 10x
A debugging dashboard for re-frame. X-ray vision as tooling.
Stars: ✭ 491 (-7.71%)
Mutual labels:  tracing, debugging
Icebox
Virtual Machine Introspection, Tracing & Debugging
Stars: ✭ 422 (-20.68%)
Mutual labels:  tracing, debugging
Joml
A Java math library for OpenGL rendering calculations
Stars: ✭ 479 (-9.96%)
Mutual labels:  matrix, vector

Tensor Sensor

See article Clarifying exceptions and visualizing tensor operations in deep learning code.

One of the biggest challenges when writing code to implement deep learning networks, particularly for us newbies, is getting all of the tensor (matrix and vector) dimensions to line up properly. It's really easy to lose track of tensor dimensionality in complicated expressions involving multiple tensors and tensor operations. Even when just feeding data into predefined Tensorflow network layers, we still need to get the dimensions right. When you ask for improper computations, you're going to run into some less than helpful exception messages.

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, PyTorch, JAX, and Numpy, as well as higher-level libraries like Keras and fastai.

TensorSensor is currently at 0.1 (Dec 2020) so I'm happy to receive issues created at this repo or direct email.

Visualizations

For more, see examples.ipynb.

import torch
W = torch.rand(d,n_neurons)
b = torch.rand(n_neurons,1)
X = torch.rand(n,d)
with tsensor.clarify():
    Y = W @ X.T + b

Displays this in a jupyter notebook or separate window:

Instead of the following default exception message:

RuntimeError: size mismatch, m1: [764 x 100], m2: [764 x 200] at /tmp/pip-req-build-as628lz5/aten/src/TH/generic/THTensorMath.cpp:41

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

Cause: @ on tensor operand W w/shape [764, 100] and operand X.T w/shape [764, 200]

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

tsensor.astviz("b = [email protected] + (h+3).dot(h) + torch.abs(torch.tensor(34))", sys._getframe())

yields the following abstract syntax tree with shapes:

Install

pip install tensor-sensor             # This will only install the library for you
pip install tensor-sensor[torch]      # install pytorch related dependency
pip install tensor-sensor[tensorflow] # install tensorflow related dependency
pip install tensor-sensor[jax]        # install jax, jaxlib
pip install tensor-sensor[all]        # install tensorflow, pytorch, jax

which gives you module tsensor. I developed and tested with the following versions

$ pip list | grep -i flow
tensorflow                         2.3.0
tensorflow-estimator               2.3.0
$ pip list | grep -i numpy
numpy                              1.18.5
numpydoc                           1.1.0
$ pip list | grep -i torch
torch                              1.6.0
$ pip list | grep -i jax
jax                                0.2.6
jaxlib                             0.1.57

Graphviz for tsensor.astviz()

For displaying abstract syntax trees (ASTs) with tsensor.astviz(...), then you need the dot executable from graphviz, not just the python library.

On Mac, do this before or after tensor-sensor install:

brew install graphviz

On Windows, apparently you need

conda install python-graphviz  # Do this first; get's dot executable and py lib
pip install tensor-sensor      # Or one of the other installs

Limitations

I rely on parsing lines that are assignments or expressions only so the clarify and explain routines do not handle methods expressed like:

def bar(): b + x * 3

Instead, use

def bar():
	b + x * 3

watch out for side effects! I don't do assignments, but any functions you call with side effects will be done while I reevaluate statements.

Can't handle \ continuations.

With Python threading package, don't use multiple threads calling clarify(). multiprocessing package should be fine.

Also note: I've built my own parser to handle just the assignments / expressions tsensor can handle.

Deploy (parrt's use)

$ python setup.py sdist upload 

Or download and install locally

$ cd ~/github/tensor-sensor
$ pip install .

TODO

  • can i call pyviz in debugger?
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].