szagoruyko / pytorchviz

A small package to create visualizations of PyTorch execution graphs
MIT License
3.24k stars 279 forks source link

Not every modal has a grad_fn #43

Closed john012343210 closed 3 years ago

john012343210 commented 4 years ago

I personally think that sometimes self-defined modal might not have grad_fn, so maybe could consider this more general case.

'NetworkCIFAR' object has no attribute 'grad_fn'

aitikgupta commented 4 years ago

Quoting this answer:

make_dot expects a variable (i.e., tensor with grad_fn), not the model itself.

Try this snippet:

out = net(dummy_input) #net is your NetworkCIFAR instance, while dummy_input is a tensor
make_dot(out)

Moreover, grad_fn is a tensor attribute, not of the model itself.

szagoruyko commented 3 years ago

thanks @aitikgupta ! closing