Skip to content

Conversation

@Krovatkin
Copy link
Contributor

No description provided.

@netlify
Copy link

netlify bot commented Jul 17, 2019

Deploy preview for pytorch-tutorials-preview failed.

Built with commit 39aaf86

https://app.netlify.com/sites/pytorch-tutorials-preview/deploys/5d2f6862635013000a782293

@netlify
Copy link

netlify bot commented Jul 17, 2019

Deploy preview for pytorch-tutorials-preview failed.

Built with commit 4294700

https://app.netlify.com/sites/pytorch-tutorials-preview/deploys/5d2f68d16b0ce000096c4cd7

@netlify
Copy link

netlify bot commented Jul 17, 2019

Deploy preview for pytorch-tutorials-preview ready!

Built with commit d028e91

https://deploy-preview-560--pytorch-tutorials-preview.netlify.com

method::
it to a ``ScriptModule``.
In order to convert the module to the ``ScriptModule``, one needs to
enable ``torch.jit._enable_recursive_script``

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This flag is gone in nightly and recursive mode is always on

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oopsie, I'll fix this.

@brianjo
Copy link
Contributor

brianjo commented Aug 5, 2019

@Krovatkin Nick, can you rebase this? Thanks!

fix cpp block

rearrange stray comments

address david's feedback
@Krovatkin Krovatkin force-pushed the krovatkin/cpp_export branch from ddf2f8b to 400b466 Compare August 5, 2019 20:21
@Krovatkin
Copy link
Contributor Author

@brianjo done!

@suo
Copy link
Member

suo commented Aug 7, 2019

@Krovatkin is this ready for merge?

@Krovatkin
Copy link
Contributor Author

@suo looks it like it's out of date again. Lemme rebase it again

@brianjo brianjo merged commit 80201b6 into pytorch:master Aug 7, 2019
@SethHWeidman
Copy link
Contributor

@brianjo @Krovatkin running the code in the tutorial here did not work. See here.

@Krovatkin
Copy link
Contributor Author

@SethHWeidman I'll take a look!

@Krovatkin
Copy link
Contributor Author

Krovatkin commented Aug 7, 2019

@SethHWeidman looks like you are using 1.1.0. This tutorial was updated for 1.2 or 1.1.1 whichever it will be called.
I tried the scripting part of the tutorial against our nightly and it seems to work: https://colab.research.google.com/drive/1BRE0hbKoW9jYwmNtxh4X93ol1xNB5304
I couldn't test tracing resnet since it seems to require GPU and I couldn't find nightly for GPU; I'll double check that it works in a little bit.

@SethHWeidman
Copy link
Contributor

@Krovatkin cool - that is why I noted that I used 1.1.0 🙂. I will check that this works with nightly as well!

@SethHWeidman
Copy link
Contributor

@Krovatkin still getting an error using 1.2.0. See here for how I exported the model into C++ (doesn't explicitly say how to do so in the tutorial).

When I save the model and try to load into C++, as in the tutorial, I get an error; it simply says "error loading the model". (Step 3 of the tutorial)

Also, the tutorial contains this line: traced_script_module.save("model.pt"), which doesn't make sense since we haven't defined an object called traced_script_module.

This is all on torch 1.2.0 by the way. Can you please try testing the C++ load sections and see if they work?

@Krovatkin
Copy link
Contributor Author

Krovatkin commented Aug 8, 2019 via email

@SethHWeidman
Copy link
Contributor

Thanks @Krovatkin.

Update:

  • Reading the model into C++ works - you just have to point the command to the path of model.pt. Perhaps we could say "run the command ./example-app <PATH-TO-model.pt>" in the tutorial so people don't get confused if they're just following along.

  • This is a minor point; the major point is: the second part, where we try to pass a Tensor of 1s through our model, generated the following error when I ran ./example-app ../model.pt from within build:

terminate called after throwing an instance of 'std::runtime_error'
  what():  matrix and vector expected, got 2D, 4D at /pytorch/aten/src/TH/generic/THTensorMath.cpp:626
The above operation failed in interpreter, with the following stack trace:
at code/model.py:6:14
op_version_set = 1
def forward(self,
    input: Tensor) -> Tensor:
  _0 = torch.gt(torch.sum(input, dtype=None), 0)
  if bool(_0):
    output = torch.mv(self.weight, input)
             ~~~~~~~~ <--- HERE
  else:
    output = torch.add(self.weight, input, alpha=1)
  return output
Compiled from code at <ipython-input-4-0d89e318784e>:8:20
    def forward(self, input):
        if input.sum() > 0:
          output = self.weight.mv(input)
                   ~~~~~~~~~~~~~~ <--- HERE
        else:
          output = self.weight + input
        return output

Aborted (core dumped)

See my .cpp file here.

Hope this helps.

@Krovatkin
Copy link
Contributor Author

Krovatkin commented Aug 9, 2019

@SethHWeidman

Reading the model into C++ works - you just have to point the command to the path of model.pt. Perhaps we could say "run the command ./example-app <PATH-TO-model.pt>" in the tutorial so people don't get confused if they're just following along.

I'll make the correction!

where we try to pass a Tensor of 1s through our model, generated the following error when I ran ./example-app ../model.pt from within build:

What's input's shape you are passing in? mv expects a vector of shape (m) where m should match m of weight's shape (n, m)
I think the confusion might stem from the fact that the tutorial assumes that you are serializing/loading resnet18.

@SethHWeidman
Copy link
Contributor

Hey @Krovatkin, I see what you mean, you're right: the problem is that we save two models during the tutorial, and unless people are paying close attention - which, I acknowledge, they should be! - they might try to run example-app with the wrong one.

How about we call the models different things to clarify - see here. I think just calling the ResNet model traced_resnet_model.pt could help quite a bit.

Tutorial is great by the way - very clear and to-the-point. Thanks for looking into this 🙂

@Krovatkin
Copy link
Contributor Author

@SethHWeidman , Thank you very much for your very detailed feedback! I'll tried to address all the points you brought up in #609 . Please let me know if I missed anything.

rodrigo-techera pushed a commit to Experience-Monks/tutorials that referenced this pull request Nov 29, 2021
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

Successfully merging this pull request may close these issues.

5 participants