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 .