tensorwatch icon indicating copy to clipboard operation
tensorwatch copied to clipboard

AttributeError: module 'torch.onnx' has no attribute 'set_training'

Open keosu opened this issue 5 years ago • 13 comments

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])

keosu avatar Aug 19 '20 04:08 keosu

I have the same question, Is there anyone solve it?Thanks very much.

btdan avatar Sep 03 '20 02:09 btdan

image

Maybe we should mofify some code.

jian-ke avatar Sep 07 '20 04:09 jian-ke

Do we have any solution? Thank you,

kuku-miku avatar Oct 19 '20 10:10 kuku-miku

just change the source code is OK image

YunhaoDu avatar Oct 22 '20 03:10 YunhaoDu

just change the source code is OK image

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' :(

kuku-miku avatar Nov 11 '20 06:11 kuku-miku

just change the source code is OK image

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' :(

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.

YunhaoDu avatar Nov 11 '20 07:11 YunhaoDu

Have you solved the problem?

wyuzyf avatar Dec 28 '20 03:12 wyuzyf

same problem

Bowenwu1 avatar Dec 30 '20 02:12 Bowenwu1

I had this issue due to an old version of TensorBoardX, installing version 2.2 fixed it for me.

holestine avatar Apr 14 '21 23:04 holestine

Same problem

ZyangLee avatar May 25 '21 07:05 ZyangLee

Same problem

102757017 avatar Jun 04 '21 03:06 102757017

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 image

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'>'.

CheapMeow avatar Feb 28 '23 11:02 CheapMeow

Same problem

Same problem

JasonYangCode avatar Mar 13 '24 02:03 JasonYangCode