I want to generate a following computation graph mentioned in How Computational Graphs are Constructed in PyTorch | PyTorch 11

image1262×1079 106 KB

I try with make_dot with following code
from graphviz import Digraph
import torch
from torch.autograd import Variable

# make_dot was moved to https://github.com/szagoruyko/pytorchviz
from torchviz import make_dot

x1 = Variable(torch.Tensor([3]), requires_grad=True)
x2 = Variable(torch.Tensor([5]), requires_grad=True)

a = torch.mul(x1, x2)
y1 = torch.log(a)
y2 = torch.sin(x2)
w = torch.mul(y1, y2)

make_dot(w)

but it doesn’t work
Traceback (most recent call last):
  File "graph.py", line 21, in <module>
    make_dot(w)
  File "~/.pyenv/versions/pymarl/lib/python3.6/site-packages/torchviz/dot.py", line 163, in make_dot
    add_base_tensor(var)
  File "~/.pyenv/versions/pymarl/lib/python3.6/site-packages/torchviz/dot.py", line 153, in add_base_tensor
    if var._is_view():
AttributeError: 'Tensor' object has no attribute '_is_view'