Skip to content

AttributeError: 'Conv2d' object has no attribute 'padding_mode' when loading model from pytorch 1.0 to 1.1 #20756

@trougnouf

Description

@trougnouf

Loading a model created with pytorch 1.0 fails on pytorch 1.1 with the error "AttributeError: 'Conv2d' object has no attribute 'padding_mode'".

This issue was also reported on jacquelinelala/GFN#11 .

complete backtrace:

Traceback (most recent call last):
  File "run_nn.py", line 213, in <module>
    loss = criterion(model(batch_y)[:,:,loss_crop_lb:loss_crop_up, loss_crop_lb:loss_crop_up], batch_x[:,:,loss_cro
p_lb:loss_crop_up, loss_crop_lb:loss_crop_up]).cuda()
  File "/usr/lib/python3.7/site-packages/torch/nn/modules/module.py", line 493, in __call__
    result = self.forward(*input, **kwargs)
  File "/orb/Dev/mthesis-denoise/networks/Hul.py", line 511, in forward
    l126 = self.enc128to126std(x)
  File "/usr/lib/python3.7/site-packages/torch/nn/modules/module.py", line 493, in __call__
    result = self.forward(*input, **kwargs)
  File "/usr/lib/python3.7/site-packages/torch/nn/modules/container.py", line 92, in forward
    input = module(input)
  File "/usr/lib/python3.7/site-packages/torch/nn/modules/module.py", line 493, in __call__
    result = self.forward(*input, **kwargs)
  File "/usr/lib/python3.7/site-packages/torch/nn/modules/conv.py", line 331, in forward
    if self.padding_mode == 'circular':
  File "/usr/lib/python3.7/site-packages/torch/nn/modules/module.py", line 539, in __getattr__
    type(self).__name__, name))
AttributeError: 'Conv2d' object has no attribute 'padding_mode'

Example of problematic model: https://github.com/trougnouf/mthesis-denoise/blob/master/networks/Hul.py , loaded with model = torch.load(args.load_g_path, map_location=device)

A workaround is to comment out the lines that use self.padding_mode in module.py, the model can then be imported, and saving the state_dictionary instead of the whole model allows loading into an unmodified version of pytorch 1.1.

Metadata

Metadata

Assignees

Labels

has workaroundhigh prioritymodule: nnRelated to torch.nntriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions