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 'set_training' #66

Open
keosu opened this issue Aug 19, 2020 · 13 comments
Open

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

keosu opened this issue Aug 19, 2020 · 13 comments

Comments

@keosu
Copy link

keosu commented Aug 19, 2020

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])
@btdan
Copy link

btdan commented Sep 3, 2020

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

@ckmufeng
Copy link

ckmufeng commented Sep 7, 2020

image

Maybe we should mofify some code.

@kuku-miku
Copy link

Do we have any solution? Thank you,

@YunhaoDu
Copy link

just change the source code is OK
image

@kuku-miku
Copy link

kuku-miku commented Nov 11, 2020

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

@YunhaoDu
Copy link

YunhaoDu commented Nov 11, 2020

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.

@wyuzyf
Copy link

wyuzyf commented Dec 28, 2020

Have you solved the problem?

@Bowenwu1
Copy link

same problem

@holestine
Copy link

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

@ZyangLee
Copy link

Same problem

1 similar comment
@102757017
Copy link

Same problem

@CheapMeow
Copy link

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

@JasonYangCode
Copy link

Same problem

Same problem

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

No branches or pull requests