Print Autograd Graph


(Herleeyandi Markoni) #21

@moskomule Hi I got this error after run it.
How to fixed this?


(Thomas V) #22

You want to upgrade to pytorch 0.2 (for which the used Variable.grad_fn replaces the older and obsolete Variable.creator).

Best regards

Thomas


(Miguel Varela Ramos) #23

Does this work as of pytorch v0.2? I tried to run with a simple sequential model and got an empty image


(Thomas V) #24

The function wants a Variable, e.g. a module calculation result. That worked for me with 0.2.


(Herleeyandi Markoni) #25

@moskomule @tom I tried that script in Resnet18 and it works well. However when I am using my own model it got this error.
image
How to solve this?
-Thank you-


(Thomas V) #26

If you don’t have a test case to show, you get to debug it all by yourself. :wink: As the message says, it looks like your y is a tuple and not a variable.
With errors like this I usually add print(type(var)) before the statement that throws the exception to debug.

Best regards

Thomas


(Holy Chen) #27

The state_dict is a map from Tensor to name, so I change code get(id(u)) to get(id(u.data)), it works without None in blue boxes.

                node_name = '%s\n %s' % (param_map.get(id(u)), size_to_str(u.size()))

(Diego) #28

Hello, Im getting the following error when trying to visualize the graph with params using python 3.6:

ca3/NN/Image_Classification_Using_NN/NNet.py", line 160, in graph_model
dot = v.make_dot(out,params)
File “/home/diego/Desktop/Universidad/3er Año/1er Semestre/APC/Practica/Practica3/NN/Image_Classification_Using_NN/visualize.py”, line 64, in make_dot
add_nodes(var.grad_fn)
File “/home/diego/Desktop/Universidad/3er Año/1er Semestre/APC/Practica/Practica3/NN/Image_Classification_Using_NN/visualize.py”, line 57, in add_nodes
add_nodes(u[0])
File “/home/diego/Desktop/Universidad/3er Año/1er Semestre/APC/Practica/Practica3/NN/Image_Classification_Using_NN/visualize.py”, line 57, in add_nodes
add_nodes(u[0])
File “/home/diego/Desktop/Universidad/3er Año/1er Semestre/APC/Practica/Practica3/NN/Image_Classification_Using_NN/visualize.py”, line 47, in add_nodes
name = param_map[id(u)] if params is not None else ''
KeyError: 140462544025784

Before calling the function i had to convert all params values to Variables, like so:

for key in params:
     params[key] = Variable(params[key])

Can anyone tell me what am I doing wrong?
Why doesnt the id(u) maps correctly to the one in params?

The script works perfectly fine if i dont give it params btw.