AttributeError: 'Conv2d' object has no attribute 'padding_mode'

I save resnet model using old pytorch and I load it using Pytorch1.1 but I get error:
AttributeError: ‘Conv2d’ object has no attribute ‘padding_mode’

How did you store and try to load the model?
padding_mode was introduced in PyTorch 1.1.0 ( docs ), so this argument shouldn’t throw an error while trying to load the model in 1.1.0.

I save the model using old Pytorch version

How did you store the resnet in the older PyTorch version?
Did you store the state_dict or the complete model?
In the latter case, you might encounter some issues, if the source code of the used classes has changed, which is the case in nn.Conv2d.
Could you save and load the state_dict instead as described in the Serialization Docs?

Im here because of the same “error”.
I think that there is somethin fundamentally incomplete in the serialization strategy in pytorch. You could call it user error - but it pops up more often than not when loading saved models from githubs. I dont do this often enough to have a full view on the matter, but Ive had several times to load a pth, wipe it clean and save it again, or save its parts, or… I figure that to write a fault tolerant torch load ought to be a quite simple task. And while the software is “maturing”, deep learning is far from ripe yet. Itd be a useful tool.

thanks.

I haven’t seen these issues yet, so could you point me to some examples?
If I’m understanding it correctly, it seems the writing/saving process was somehow interrupted, which resulted in an invalid file?

Storing the state_dict is backward compatible and thus the recommended way.
If you store the model completely, you might need to use dump_patches=True to fix the code.

Sure, I was looking at super resolution githubs with pytorch.
One of the ones I grabbed was https://github.com/BUPTLdy/Pytorch-LapSRN.

Download it and run the python test.py on torch ‘1.0.1.post2’ (version im currently working with) this error will occur.
Clearly, the author should have saved a state_dict, but they saved the entire model instead.

The fix is quite simple, for this one, on a separate script load the entire model as in test.py then save state state dict as per the serialization docs, then change test.py to load the model class then load the state dict you just saved.

So, if one follows the recommended serialization proc then everything works, but in many cases this isn’t done, because its in human nature to take the perceived simpler path. All Im just arguing that pytorch could have a more comprehensive error tolerant serialization.

btw. not related; a much better written superresolution github is ESRGAN - curiously it isnt in modelzoo.