Tensorboardx: add_graph() show error 'torch._C.Value' object has no attribute 'uniqueName' with torch 1.2.0

Created on 11 Aug 2019  路  18Comments  路  Source: lanpa/tensorboardX

Describe the bug
add_graph() with torch 1.2.0 will show error 'torch._C.Value' object has no attribute 'uniqueName'
but work well with torch 1.1.0

Minimal runnable code to reproduce the behavior

from tensorboardX import SummaryWriter
class LeNet(nn.Module):
    def __init__(self):
        super(LeNet, self).__init__()
        self.conv1 = nn.Sequential(     #input_size=(1*28*28)
            nn.Conv2d(1, 6, 5, 1, 2),
            nn.ReLU(),      #(6*28*28)
            nn.MaxPool2d(kernel_size=2, stride=2),  #output_size=(6*14*14)
        )
        self.conv2 = nn.Sequential(
            nn.Conv2d(6, 16, 5),
            nn.ReLU(),      #(16*10*10)
            nn.MaxPool2d(2, 2)  #output_size=(16*5*5)
        )
        self.fc1 = nn.Sequential(
            nn.Linear(16 * 5 * 5, 120),
            nn.ReLU()
        )
        self.fc2 = nn.Sequential(
            nn.Linear(120, 84),
            nn.ReLU()
        )
        self.fc3 = nn.Linear(84, 10)

    def forward(self, x):
        x = self.conv1(x)
        x = self.conv2(x)
        x = x.view(x.size()[0], -1)
        x = self.fc1(x)
        x = self.fc2(x)
        x = self.fc3(x)
        return x

dummy_input = torch.rand(13, 1, 28, 28)
model = LeNet()
with SummaryWriter(comment='Net', log_dir='/output') as w:
    w.add_graph(model, (dummy_input, ))

Expected behavior

Screenshots

Environment

Python environment
Python 3.6

Additional context
Add any other context about the problem here.

Most helpful comment

same with python=3.7.4, torch=1.2.0

All 18 comments

Same error for me with torch 1.2.0 and Python 3.5. BTW, the same code does not produce errors with the official torch.utils.tensorboard module but tensorboard does not show any graphs.

@YYRancho The same problem.

Also the example code provided in the repo fails in the same way.

Relevant packages are:

  • tb-nightly 1.15.0a20190806
  • tensorboardX 1.8+366bc8f
  • torch 1.2.0
  • torchvision 0.4.0

~/tmp/tensorboardX$ python3 examples/demo_graph.py
graph(%self : ClassType,
%input : Float(1, 3)):
%1 : ClassType = prim::GetAttrname="l"
%weight : Tensor = prim::GetAttrname="weight"
%bias : Tensor = prim::GetAttrname="bias"
%5 : Float(3!, 5!) = aten::t(%weight), scope: LinearInLinear/Linear[l] # /home/barryf/.local/lib/python3.6/site-packages/torch/nn/functional.py:1369:0
%6 : int = prim::Constantvalue=1, scope: LinearInLinear/Linear[l] # /home/barryf/.local/lib/python3.6/site-packages/torch/nn/functional.py:1369:0
%7 : int = prim::Constantvalue=1, scope: LinearInLinear/Linear[l] # /home/barryf/.local/lib/python3.6/site-packages/torch/nn/functional.py:1369:0
%8 : Float(1, 5) = aten::addmm(%bias, %input, %5, %6, %7), scope: LinearInLinear/Linear[l] # /home/barryf/.local/lib/python3.6/site-packages/torch/nn/functional.py:1369:0
return (%8)

Traceback (most recent call last):
File "examples/demo_graph.py", line 20, in
w.add_graph(LinearInLinear(), dummy_input, True)
File "/home/barryf/tmp/tensorboardX/examples/tensorboardX/writer.py", line 774, in add_graph
self._get_file_writer().add_graph(graph(model, input_to_model, verbose, kwargs))
File "/home/barryf/tmp/tensorboardX/examples/tensorboardX/pytorch_graph.py", line 261, in graph
list_of_nodes, node_stats = parse(graph, args)
File "/home/barryf/tmp/tensorboardX/examples/tensorboardX/pytorch_graph.py", line 218, in parse
nodes_py.append(NodePyIO(node, 'input'))
File "/home/barryf/tmp/tensorboardX/examples/tensorboardX/pytorch_graph.py", line 68, in __init__
super(NodePyIO, self).__init__(node_cpp, methods_IO)
File "/home/barryf/tmp/tensorboardX/examples/tensorboardX/pytorch_graph.py", line 63, in __init__
setattr(self, m, getattr(node_cpp, m)())
**AttributeError: 'torch._C.Value' object has no attribute 'uniqueName'

@YYRancho same here with python=3.6.8, torch=1.2.0

same with python=3.7.4, torch=1.2.0

@YYRancho Does the resulting graph looks OK with the official torch.utils.tensorboard? I fixed the corresponding code in tensorboardX and found the result looks bad.

@lanpa No, tensorboard shows no graphs but two black-edged boxes in the lower right corner. I have tried simple ANN and LSTM and got the same results. I would be glad to provide more information if necessary.

the same problem with python=3.7.4, torch=1.2.0.

@YYRancho @a-pythoner Thanks for the report. Reopen this.

@YYRancho btw, does the error torch._C.Value still happen?
@a-pythoner What is your result of pip list?
Thanks

@lanpa tensorboardX will not show any error if I follow your fix.

I am encountering the same issue here:
Any solution ?

My installations:
torch 1.2.0+cu92
tensorboardX 1.8
python 3.6

Thank you in advance.

I am encountering the same issue when calling hiddenlayer.build_graph method:
In order to fix it in hiddenlayer\pytorch_builder.py, change get_shape method to:

def pytorch_id(node):
    """Returns a unique ID for a node."""
    # After ONNX simplification, the scopeName is not unique anymore
    # so append node outputs to guarantee uniqueness
    return node.scopeName() + "/outputs/" + "/".join([o.debugName() for o in node.outputs()])

Packages information:
torch 1.2.0+cu10
matplotlib 3.1.1
tensorflow 1.14.0
graphviz 0.12
hiddenlayer 0.2
python 3.7.4

try to build from source with :

git clone https://github.com/lanpa/tensorboardX && cd tensorboardX && python setup.py install

try to build from source with :

git clone https://github.com/lanpa/tensorboardX && cd tensorboardX && python setup.py install

It's great. It's perfect for solving problems.

Since pytorch 1.3 is officially released and works with tensorboardX 1.9, closing this.

Since pytorch 1.3 is officially released and works with tensorboardX 1.9, closing this.
add_graph() still error with pytorch 1.1.0 tensorboardx 1.9, error info:
TypeError: __init__() got an unexpected keyword argument 'record_shapes' @lanpa

Was this page helpful?
0 / 5 - 0 ratings