2

I am using PyTorch 0.4.

I defined a PyTorch MyModel by inheriting from nn.Module, and saved an instance of it by calling

torch.save(my_model, my_path)

Then, when loading it again with torch.load(my_path), my program crashed with the following error:

AttributeError: 'MyModel' object has no attribute 'to'

But my program was able to run it in previous stages. What did go wrong?

1 Answer 1

4

I already found it out, and just wanted to quickly post about it since google didn't give an obvious clue.

It turned out that, although I saved the model from a computer with 0.4, I was trying to load it from a different computer that still had an older (<0.4) PyTorch version installed. pip install --upgrade torch fixed it.


I found it out because the my_model.train()and .eval() methods were indeed working, so I remembered that the .to() method was introduced in 0.4. Useful references:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.