Load a 0.4.0 trained pytorch model in 1.2.0

Is it possible to load a model trained on the earlier version of PyTorch (0.4.0) in the latest version(let say 1.2.0)?

1 Like

Yes, loading models is backward compatible.

Thanks for the response, can you guide me to a link which explains such a case

You can just use the regular torch.load and load_state_dict. Are there specific modules you are looking for more details with?

Yes, when I load my model in 1.2.0 and inference it

Traceback (most recent call last):
  File "inferencer.py", line 100, in <module>
    main(args)
  File "inferencer.py", line 96, in main
    seg_process(args, myModel)
  File "inferencer.py", line 72, in seg_process
    seg, alpha = net(inputs)
  File "/opt/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 547, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/jupyter/mobile_matting/model/segnet.py", line 290, in forward
    seg = self.seg_extract(x)
  File "/opt/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 547, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/jupyter/mobile_matting/model/segnet.py", line 191, in forward
    input_cascade1 = self.cascade1(input)
  File "/opt/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 547, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/jupyter/mobile_matting/model/segnet.py", line 98, in forward
    input = pool(input)
  File "/opt/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 547, in __call__
    result = self.forward(*input, **kwargs)
  File "/opt/anaconda3/lib/python3.7/site-packages/torch/nn/modules/pooling.py", line 551, in forward
    self.padding, self.ceil_mode, self.count_include_pad, self.divisor_override)
  File "/opt/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 591, in __getattr__
    type(self).__name__, name))
AttributeError: 'AvgPool2d' object has no attribute 'divisor_override'

I get the following error, but when i roll back to 0.4.0, the model works fine

Are you serializing the state dict or the module object?

I got the same error. Model developed on PyTorch 1.0.1 and tested on 1.3.0. Any workaround?