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

Ultralytics yolov5 complilation, using weights attempt_load not working with torch.load() #277

Closed
anubhavdavid opened this issue Jun 15, 2021 · 3 comments

Comments

@anubhavdavid
Copy link

If I'm directly loading the pre-trained weights using torch.hub.load, the compilation for neuron graph seems to be working, but if I download the weights using attempt_load and then load them with torch.load(), it give the error:

torch.nn.modules.module.ModuleAttributeError: 'Detect' object has no attribute 'inplace'

Compiler Version=> 1.3.7.0+fc8e67ab4

  • OS Version= Ubuntu
  • Python version=3.6
  • ML Framework (MXNet/Tensorflow/Pytorch) being used= Pytorch
  • ML Framework version= 1.7.1
@jeffhataws
Copy link
Contributor

Hi anubhavdavid, thank you for filing the issue. We will take a look.

@mrnikwaws
Copy link
Contributor

Hi Anubhav,

Thanks for the query.

I noticed this issue (which is unrelated to neuron): pytorch/pytorch#46971. It appears the issue here is caused by training a model and saving it in an earlier version of PyTorch and then loading in the current version (or a recent one). The comments indicate that loading just the state dictionary may be productive, if this sound like it matches your use of the model. While the error is not identical it looks similar.

Please also note the compilation notes for YOLOv5 here: #253, and the upstreamed change to YOLOv5 here: ultralytics/yolov5#2953. It was merged here: ultralytics/yolov5#2982. If you are working with a recent version of YOLOv5 then I believe this should 'just work' for you.

On saving and loading in neuron, typically you'd do something like this:

    model_neuron = torch.neuron.trace( ... )
    model_neuron.save('my_filename.pt')
    model_neuron_loaded = torch.jit.load('my_filename.pt')

There is a difference between https://pytorch.org/docs/stable/generated/torch.load.html and https://pytorch.org/docs/stable/generated/torch.jit.load.html. I don't think this is the source of your issue, but worth noting to avoid any future issues.

Thanks for trying torch-neuron, and I hope this information will help you resolve the problem.

If you are still having problems and you believe it is related to Neuron, please share some code that reproduces the issue and we'll take a deeper look.

@mrnikwaws
Copy link
Contributor

Hi Anubhav,

Since we haven't heard back on this issue for a week I am going to close it. Please feel free to reopen it if you have some additional information to share.

awsjoshir pushed a commit that referenced this issue May 2, 2023
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

3 participants