How can I get access to the torch._C.Node values in python?

Hi, I am trying out jit trace functions to automatically parse the model structure.
Originally, I use model_output.grad_fn for parsing the structure, but the graph structure seems simpler.

FYI, I am using PyTorch version 0.3.1 (installed with pip) in Python 2.7

Below is a part of the code I wrote:

input_var = Variable(torch.FloatTensor( np.random.random((1, init_shape[0], init_shape[1],init_shape[2])).astype(np.float32))).cuda()
trace, out = torch.jit.trace(model, (input_var,))
graph = trace.graph()

Once I get the graph, I notice that I can get access to the Nodes and Inputs (I assume they are Nodes containing weights, including the input tensor).
I want to get access to the weights inside the nodes, but I cannot find any instructions related to get the weight values into python.

One workaround can be parse the Nodes, and retrieve the weights from model.state_dict(), but I think there should be as simpler way.

1 Like


Have you found a way?

@JCPARK, any luck with the issue?

I am stuck in a similar problem. Need inbound and outbound tensors for the node. Did not find any documentation to get attributes of torch._C.Value

except for dir(torch._C.Value) or review the source code. you can do nothing.