You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.
I met an interesting problem of TorchModuleGraph. In the latest version of NNI, TorchModuleGraph has two sets of interfaces to build the graph, specifically, users can provide either the model and dummy input to trace the model, or an already traced model so that we don't need to trace the model again. The model and dummy input works fine, however, I found that if we use the traced_model as input for the TorchModuleGraph, we need to trace the model in a specific way, else it may meet some problems.
To reproduce:
When we trace the model in the following way(the same way with TrochModuleGraph to trace the model using model and dummy input) and pass the traced_model to TorchModuleGraph, it works fine.
Output:
Traceback (most recent call last):
File "test_torchmodule_graph.py", line 32, in <module>
_graph = TorchModuleGraph(net, data, trace)
File "/home/core/znx/nni/build/nni/_graph_utils.py", line 238, in __init__
self.name_to_node, self.input_to_node, self.output_to_node = self._build_graph()
File "/home/core/znx/nni/build/nni/_graph_utils.py", line 525, in _build_graph
node_cpps, input_to_node, output_to_node, 'module')
File "/home/core/znx/nni/build/nni/_graph_utils.py", line 364, in _expand_module_node
node_group, inputs=inputs, outputs=outputs)
File "/home/core/znx/nni/build/nni/_graph_utils.py", line 210, in __init__
self.add_nodes(node_cpps)
File "/home/core/znx/nni/build/nni/_graph_utils.py", line 216, in add_nodes
nodepy = NodePyOP(node_cpp)
File "/home/core/anaconda3/envs/nnidoc/lib/python3.7/site-packages/torch/utils/tensorboard/_pytorch_graph.py", line 92, in __init__
self.attributes = str({k: node_cpp[k] for k in node_cpp.attributeNames()}).replace("'", ' ')
File "/home/core/anaconda3/envs/nnidoc/lib/python3.7/site-packages/torch/utils/tensorboard/_pytorch_graph.py", line 92, in <dictcomp>
self.attributes = str({k: node_cpp[k] for k in node_cpp.attributeNames()}).replace("'", ' ')
TypeError: 'torch._C.Node' object is not subscriptable
More interestingly, when I trace the model in the second way(torch.onnx.set_training), but import torchvision this time, then everything works fine again.
Environment:
I met an interesting problem of TorchModuleGraph. In the latest version of NNI, TorchModuleGraph has two sets of interfaces to build the graph, specifically, users can provide either the model and dummy input to trace the model, or an already traced model so that we don't need to trace the model again. The model and dummy input works fine, however, I found that if we use the traced_model as input for the TorchModuleGraph, we need to trace the model in a specific way, else it may meet some problems.
To reproduce:
When we trace the model in the following way(the same way with TrochModuleGraph to trace the model using model and dummy input) and pass the traced_model to TorchModuleGraph, it works fine.
In contrast, when we trace the model in a second way(as shown in the following code), it will raise an error in the code of tensorboard.
More interestingly, when I trace the model in the second way(torch.onnx.set_training), but import torchvision this time, then everything works fine again.
I'll keep updating if I find something new.
The text was updated successfully, but these errors were encountered: