AttributeError: module 'torch.onnx' has no attribute 'set_training'
pytorch version: 1.6.0
import sys
import torch
import tensorwatch as tw
import torchvision.models
alexnet_model = torchvision.models.alexnet()
tw.draw_model(alexnet_model, [1, 3, 224, 224])
I have the same question, Is there anyone solve it?Thanks very much.

Maybe we should mofify some code.
Do we have any solution? Thank you,
just change the source code is OK

just change the source code is OK
so basically you mean to just change at line 85 in /home/ant/anaconda3/lib/python3.8/site-packages/tensorwatch/model_graph/hiddenlayerhiddenlayer/summary_graph.py i.e.
#with torch.onnx.set_training(model_clone, False):
#with torch.onnx.select_model_mode_for_export(model_clone, None):
with torch.onnx.select_model_mode_for_export(model_clone, False):
device = distiller.model_device(model_clone)
dummy_input = distiller.convert_tensors_recursively_to(dummy_input, device=device)
self.dummy_input = dummy_input
well, above changes give another error as below, File "/home/ant/anaconda3/lib/python3.8/site-packages/torch/onnx/utils.py", line 1083, in _node_getitem return getattr(self, sel)(k) AttributeError: 'torch._C.Node' object has no attribute 'ival' :(
just change the source code is OK
so basically you mean to just change at line 85 in /home/ant/anaconda3/lib/python3.8/site-packages/tensorwatch/model_graph/hiddenlayerhiddenlayer/summary_graph.py i.e.
#with torch.onnx.set_training(model_clone, False): #with torch.onnx.select_model_mode_for_export(model_clone, None): with torch.onnx.select_model_mode_for_export(model_clone, False): device = distiller.model_device(model_clone) dummy_input = distiller.convert_tensors_recursively_to(dummy_input, device=device) self.dummy_input = dummy_inputwell, above changes give another error as below, File "/home/ant/anaconda3/lib/python3.8/site-packages/torch/onnx/utils.py", line 1083, in _node_getitem return getattr(self, sel)(k) AttributeError: 'torch._C.Node' object has no attribute 'ival' :(
You're right. There are troublesome problems. I've tried PyTorch v0.4, 1.1, 1.6. Now I've given up using tensorwatch. Instead, PyTorchViz, tensorboardX and netron are also good tools.
Have you solved the problem?
same problem
I had this issue due to an old version of TensorBoardX, installing version 2.2 fixed it for me.
Same problem
Same problem
I had this issue due to an old version of TensorBoardX, installing version 2.2 fixed it for me.
Seems don't work for me.
just change the source code is OK
I meet error:
Traceback (most recent call last):
File "D:\Work\PyCharmProject\nlp-tutorial-master\venv\lib\site-packages\tensorwatch\model_graph\hiddenlayer\pytorch_draw_model.py", line 63, in draw_img_classifier
g = SummaryGraph(non_para_model, dummy_input)
File "D:\Work\PyCharmProject\nlp-tutorial-master\venv\lib\site-packages\tensorwatch\model_graph\hiddenlayer\summary_graph.py", line 86, in __init__
with torch.onnx.select_model_mode_for_export(model_clone, False):
File "C:\Users\CheapMeow\AppData\Local\Programs\Python\Python310\lib\contextlib.py", line 135, in __enter__
return next(self.gen)
File "D:\Work\PyCharmProject\nlp-tutorial-master\venv\lib\site-packages\torch\onnx\utils.py", line 88, in select_model_mode_for_export
raise TypeError(
TypeError: 'mode' should be a torch.onnx.TrainingMode enum, but got '<class 'bool'>'.
Same problem
Same problem