tensor sensor
1.0
请参阅文章澄清异常并在深度学习代码和张量实现幻灯片(PDF)中可视化张量操作。
(截至2021年9月,M1 MAC在通过Anaconda安装的许多张量库中经历非法说明,因此您应该期望TensorSenSor目前仅在基于Intel的Mac上工作。Pytorch似乎有效。 )
而不是以下默认异常消息:
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)
TensOrsensor通过有关哪个操作员引起问题的更多信息来增强该消息,并包括操作数的形状:
Cause: @ on tensor operand W w/shape (764, 100) and operand X.T w/shape (764, 200)
您还可以获取包含所有子表达形状的表达式的完整计算图。
W = torch . rand ( size = ( 2000 , 2000 ), dtype = torch . float64 )
b = torch . rand ( size = ( 2000 , 1 ), dtype = torch . float64 )
h = torch . zeros ( size = ( 1_000_000 ,), dtype = int )
x = torch . rand ( size = ( 2000 , 1 ))
z = torch . rand ( size = ( 2000 , 1 ), dtype = torch . complex64 )
tsensor . astviz ( "b = W@b + (h+3).dot(h) + z" , sys . _getframe ())产生以下具有形状的抽象语法树:
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
它为您提供模块tsensor 。我使用以下版本进行了开发和测试
$ pip list | grep -i flow
tensorflow 2.5.0
tensorflow-estimator 2.5.0
$ pip list | grep -i numpy
numpy 1.19.5
numpydoc 1.1.0
$ pip list | grep -i torch
torch 1.10.0
torchvision 0.10.0
$ pip list | grep -i jax
jax 0.2.20
jaxlib 0.1.71
为了用tsensor.astviz(...)显示抽象的语法树(ASTS),您需要从GraphViz执行的dot ,而不仅仅是Python库。
在Mac上,在张张传感器安装之前或之后执行此操作:
brew install graphviz
在窗户上,显然您需要
conda install python-graphviz # Do this first; get's dot executable and py lib
pip install tensor-sensor # Or one of the other installs
我依赖于仅是作业或表达式的解析行,因此澄清和解释例程不会处理以下表达的方法:
def bar(): b + x * 3
而是使用
def bar():
b + x * 3
提防副作用!我不做分配,但是您调用副作用的任何功能都将在我重新评估语句时执行。
无法处理连续。
使用Python threading软件包,请勿使用多个线程调用Clarlify()。 multiprocessing程序包应该很好。
另请注意:我已经建立了自己的解析器来处理TSESOR可以处理的作业 /表达式。
$ python setup.py sdist upload 或在本地下载并安装
$ cd ~ /github/tensor-sensor
$ pip install .