Open hughperkins opened 5 years ago
Hi @hughperkins , it's been a while! you need to provide either None parameters, or all tensors that require grad in the graph, this will fix your example:
torchviz.make_dot(outputs, params={**{'inputs': inputs}, **dict(h1.named_parameters())})
we should be either giving a better error message, or allow missing named nodes.
it's been a while!
Yes :)
you need to provide either None parameters, or all tensors that require grad in the graph
Ah, ok. Awesome, thanks! Will give this a try :)
I am getting this issue as well. Here is the final stacktrace line:
~/Documents/github/ssdmultibox/venv/lib/python3.7/site-packages/torchviz/dot.py in add_nodes(var)
45 elif hasattr(var, 'variable'):
46 u = var.variable
---> 47 name = param_map[id(u)] if params is not None else ''
48 node_name = '%s\n %s' % (name, size_to_str(u.size()))
49 dot.node(str(id(var)), node_name, fillcolor='lightblue')
KeyError: 4871725920
I tried:
torchviz.make_dot(loss, params={**{'inputs': inputs}, **dict(model.named_parameters())})
And also:
torchviz.make_dot(loss, params=dict(model.named_parameters()))
But, I still got the same error. Is this user error on my part? My model is an SSD Multibox model where the predictions are a list of tensors of different sizes. I am wondering if that might be the issue and it doesn't work with make_dot
. Thanks
Hi @szagoruyko ,I met the same error when i train my network using 'make_dot' function to visulize my nerual network structure. There are the errors as follow:
output = self.lstmlayer(output)[0]
Traceback (most recent call last):
File "/data/xiaojianli/sorftWare/pycharm-2017.3.1/helpers/pydev/pydevd.py", line 1668, in <module>
main()
File "/data/xiaojianli/sorftWare/pycharm-2017.3.1/helpers/pydev/pydevd.py", line 1662, in main
globals = debugger.run(setup['file'], None, None, is_module)
File "/data/xiaojianli/sorftWare/pycharm-2017.3.1/helpers/pydev/pydevd.py", line 1072, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "/mnt/data/polygonRNN_data/pytorch-polygon-rnn-master-pmri/train.py", line 113, in <module>
make_dot(r, params=dict(list(PolygonNet().named_parameters())+[('x',x),('x1',x1),('x2',x2),('x3',x3)]))
File "/usr/local/lib/python2.7/dist-packages/torchviz/dot.py", line 70, in make_dot
add_nodes(var.grad_fn)
File "/usr/local/lib/python2.7/dist-packages/torchviz/dot.py", line 59, in add_nodes
add_nodes(u[0])
File "/usr/local/lib/python2.7/dist-packages/torchviz/dot.py", line 59, in add_nodes
add_nodes(u[0])
File "/usr/local/lib/python2.7/dist-packages/torchviz/dot.py", line 59, in add_nodes
add_nodes(u[0])
File "/usr/local/lib/python2.7/dist-packages/torchviz/dot.py", line 59, in add_nodes
add_nodes(u[0])
File "/usr/local/lib/python2.7/dist-packages/torchviz/dot.py", line 59, in add_nodes
add_nodes(u[0])
File "/usr/local/lib/python2.7/dist-packages/torchviz/dot.py", line 47, in add_nodes
name = param_map[id(u)] if params is not None else ''
KeyError: 140707794969536
there are the 'make_dot' function in my code:
x = Variable(data[0].type(dtype), requires_grad=True)
x1 = Variable(data[1].type(dtype), requires_grad=True)
x2 = Variable(data[2].type(dtype), requires_grad=True)
x3 = Variable(data[3].type(dtype), requires_grad=True)
ta = Variable(data[4].type(dtype_t))
optimizer.zero_grad() #make the grad be zero
r = net(x,x1,x2,x3) # go to forward func in model.py script
make_dot(r, params=dict(list(PolygonNet().named_parameters())+[('x',x),('x1',x1),('x2',x2),('x3',x3)]))
when i debuge my code, i found this line code output_o = self.lstmlayer(output_i)[0]
that call lstmlayer casued this Error. Why when i call lstmlayer() the error occured? What's more, when i uncomment make_dot(r, params=dict(list(PolygonNet().named_parameters())+[('x',x),('x1',x1),('x2',x2),('x3',x3)]))
code, the training code goes well. So the error only occured when i try to visulize the network structure. Waiting for your appreciative apply. Thank U~
@szagoruyko set None parameters works for me, thanks
There's a hacky way to fix it
Change line 47 in torchviz/dot.py to
name = param_map.get(id(u), ' ') if params is not None else ''
When I run:
I get:
collectenv output: