waleedka / hiddenlayer

Neural network graphs and training metrics for PyTorch, Tensorflow, and Keras.
MIT License
1.79k stars 266 forks source link

get_trace_graph private in Pytorch 1.4 #66

Closed nanohanno closed 4 years ago

nanohanno commented 4 years ago

system: Python 3.7.5 Pytorch 1.4 torchvision 0.5

code and error: import hiddenlayer as hl

model= vgg16(pretrained=True).features hl.build_graph(model, torch.zeros([1,3,224,224]))

" 69 # Run the Pytorch graph to get a trace and generate a graph from it ---> 70 trace, out = torch.jit.get_trace_graph(model, args) 71 torch.onnx._optimize_trace(trace, torch.onnx.OperatorExportTypes.ONNX) 72 torch_graph = trace.graph()"

AttributeError: module 'torch.jit' has no attribute 'get_trace_graph'

Context: Since Pytorch version 1.4 (this pull request) the function jit.get_trace_graph is private (jit._get_trace_graph).

jonas154 commented 4 years ago

I face the same problem :/

nanohanno commented 4 years ago

Hey @jonas154, have you tried out the proposed changes from #67 ?

jonas154 commented 4 years ago

Hey @nanohanno, sorry for the late response. I just tried out your fix and everything works now fine. Thanks for providing the fix!

MoonBunnyZZZ commented 4 years ago

@jonas154 still face this bug today Python 3.7 Pytorch 1.4 torchvision 0.5

jonas154 commented 4 years ago

@MoonBunnyZZZ have you tried the fix of @nanohanno

MoonBunnyZZZ commented 4 years ago

@MoonBunnyZZZ have you tried the fix of @nanohanno

the fix works now.thank you

level14taken commented 4 years ago

Hey i have tried changing the code as proposed by @nanohanno , but i couldn't get it to work, am i missing something?? torch 1.5, and torchvision 0.6. Screenshot from 2020-03-22 13-57-56

john012343210 commented 4 years ago

After viewing the doc, only pytorch 1.1 have this get_trace_graph so downgrade to pytorch 1.1 will help

nanohanno commented 4 years ago

Hey @level14taken , It seems like the error message still refers to the old version get_trace_graph while showing your updated code. Maybe there is a problem with package installation? Maybe pip install directly from github?

level14taken commented 4 years ago

@nanohanno, Nope the error still persists, even after direct installation from github,any other ideas that i can try out??

nanohanno commented 4 years ago

Sorry, I guess it has more to do with package installation than hiddenlayer itself. Maybe look into that direction. Also, I am not familiar with colab, don't know if that may also cause problems.

mohammedalsayegh commented 4 years ago

I am having the similar issue running hiddenlayer with PyTorch Nightly,

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-12-04717a98c7ee> in <module>
      1 import hiddenlayer
----> 2 hiddenlayer.build_graph(LeNet5(), torch.zeros(1, 1, 32, 32))

~\anaconda3\lib\site-packages\hiddenlayer-0.2-py3.7.egg\hiddenlayer\graph.py in build_graph(model, args, input_names, transforms, framework_transforms)
    141         from .pytorch_builder import import_graph, FRAMEWORK_TRANSFORMS
    142         assert args is not None, "Argument args must be provided for Pytorch models."
--> 143         import_graph(g, model, args)
    144     elif framework == "tensorflow":
    145         from .tf_builder import import_graph, FRAMEWORK_TRANSFORMS

~\anaconda3\lib\site-packages\hiddenlayer-0.2-py3.7.egg\hiddenlayer\pytorch_builder.py in import_graph(hl_graph, model, args, input_names, verbose)
     68 
     69     # Run the Pytorch graph to get a trace and generate a graph from it
---> 70     trace, out = torch.jit.get_trace_graph(model, args)
     71     torch.onnx._optimize_trace(trace, torch.onnx.OperatorExportTypes.ONNX)
     72     torch_graph = trace.graph()

AttributeError: module 'torch.jit' has no attribute 'get_trace_graph'
waleedka commented 4 years ago

I believe this issue is now fixed thanks to https://github.com/waleedka/hiddenlayer/pull/67