Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: module 'torch.onnx' has no attribute '_optimize_trace' #100

Open
Abermal opened this issue Jan 18, 2023 · 7 comments · May be fixed by #101
Open

AttributeError: module 'torch.onnx' has no attribute '_optimize_trace' #100

Abermal opened this issue Jan 18, 2023 · 7 comments · May be fixed by #101

Comments

@Abermal
Copy link

Abermal commented Jan 18, 2023

The name of the error says it all.
Probably a version error.

Installed hiddenlayer-0.2 from source.
OS: Linux ubuntu 20 lts
torch.version = '1.13.0+cu117'

@papy-ganjha
Copy link

Hello,
You have to change the following :
_optimize_trace to _optimize_graph
in pytorch_builder.py line 71
I will if there is no pull request make one to fix this little bug
Hope it helps!

amitbar05 added a commit to amitbar05/hiddenlayer that referenced this issue Apr 8, 2023
@amitbar05 amitbar05 linked a pull request Apr 8, 2023 that will close this issue
@janspiegel
Copy link

Hello, I have made this change manually in pytorch_builder.py but now get the below

`---------------------------------------------------------------------------

TypeError Traceback (most recent call last)

in <cell line: 11>()
9 # see:#100
10 # Jupyter Notebook renders it automatically
---> 11 hl.build_graph(model_resnet, torch.zeros([4,3,256,256]).to(device))

2 frames

/usr/local/lib/python3.10/dist-packages/hiddenlayer/pytorch_builder.py in (.0)
80 op = torch_node.kind()
81 # Parameters
---> 82 params = {k: torch_node[k] for k in torch_node.attributeNames()}
83 # Inputs/outputs
84 # TODO: inputs = [i.unique() for i in node.inputs()]

TypeError: 'torch._C.Node' object is not subscriptable`

@code-acrobat
Copy link

code-acrobat commented May 19, 2023

You need to hack more.

try:
  params = {k: torch_node[k] for k in torch_node.attributeNames()}
except Exception: 
  params = {}

If you follow various old tutorials with Jupyther notebooks you might need to change stuff like

hl.build_graph(model,torch.zeros([1]))

to

hl.build_graph(model,torch.zeros([1])).build_dot()

Hello, I have made this change manually in pytorch_builder.py but now get the below

`---------------------------------------------------------------------------

TypeError Traceback (most recent call last)

in <cell line: 11>() 9 # see:#100 10 # Jupyter Notebook renders it automatically ---> 11 hl.build_graph(model_resnet, torch.zeros([4,3,256,256]).to(device))

2 frames

/usr/local/lib/python3.10/dist-packages/hiddenlayer/pytorch_builder.py in (.0) 80 op = torch_node.kind() 81 # Parameters ---> 82 params = {k: torch_node[k] for k in torch_node.attributeNames()} 83 # Inputs/outputs 84 # TODO: inputs = [i.unique() for i in node.inputs()]

TypeError: 'torch._C.Node' object is not subscriptable`

@pikarpov
Copy link

While that works, it also loses kernel size information from parameters to be included in the graph. Alternatively, you can follow the error and change __getitem__ to _node_get. To do that, include the following in the beginning of your pytorch_builder.py

# From https://github.com/pytorch/pytorch/blob/2efe4d809fdc94501fc38bf429e9a8d4205b51b6/torch/utils/tensorboard/_pytorch_graph.py#L384
def _node_get(node: torch._C.Node, key: str):
    """Gets attributes of a node which is polymorphic over return type."""
    sel = node.kindOf(key)
    return getattr(node, sel)(key)

torch._C.Node.__getitem__ = _node_get

Now, you should be able to extract from the nodes just fine, so there should be no issues with this line.

params = {k: torch_node[k] for k in torch_node.attributeNames()}

Credit: TypeError: 'torch._C.Node' object is not subscriptable

@annahedstroem
Copy link

+1 with the same problem

@martin3398
Copy link

+1 I have the same problem

@DonggeJia
Copy link

While that works, it also loses kernel size information from parameters to be included in the graph. Alternatively, you can follow the error and change __getitem__ to _node_get. To do that, include the following in the beginning of your pytorch_builder.py

# From https://github.com/pytorch/pytorch/blob/2efe4d809fdc94501fc38bf429e9a8d4205b51b6/torch/utils/tensorboard/_pytorch_graph.py#L384
def _node_get(node: torch._C.Node, key: str):
    """Gets attributes of a node which is polymorphic over return type."""
    sel = node.kindOf(key)
    return getattr(node, sel)(key)

torch._C.Node.__getitem__ = _node_get

Now, you should be able to extract from the nodes just fine, so there should be no issues with this line.

params = {k: torch_node[k] for k in torch_node.attributeNames()}

Credit: TypeError: 'torch._C.Node' object is not subscriptable

still do not show data flow dimension

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants