parrt / tensor-sensor

The goal of this library is to generate more helpful exception messages for matrix algebra expressions for numpy, pytorch, jax, tensorflow, keras, fastai.
https://github.com/parrt/tensor-sensor
MIT License
771 stars 39 forks source link

feat: explainer support pdf #27

Closed sbrugman closed 3 years ago

sbrugman commented 3 years ago

Enable PDF (and other supported formats) savefig in explainer by removing hardcoded extension

import torch
W = torch.rand(d,n_neurons)
b = torch.rand(n_neurons,1)
X = torch.rand(n,d)
with ts.explain(savefig="my_inspection.pdf"):
    Y = W @ X.T + b
parrt commented 3 years ago

Hi. I can't remember why but something prevented me from allowing non-svg. Hmm...let me look.

parrt commented 3 years ago

ok, looks good. We only save with plt.savefig() in one spot, PyVizView.savefig(), so should be safe to allow any extensions. thanks!

parrt commented 3 years ago

Confirmed that this works with pdf now:

import torch
import tsensor

n = 100
d = 10
n_neurons = 100
W = torch.rand(d,n_neurons)
b = torch.rand(n_neurons,1)
X = torch.rand(n,d)
with tsensor.explain(savefig="my_inspection.pdf"):
    Y = W @ X.T + b