Problem with load_state_dict after installing latest pytorch from source

  • OS: MacOS Sierra
  • PyTorch version: 0.4.0a0+7588893
  • How you installed PyTorch (conda, pip, source): source
  • Python version: Python 2.7.14 |Anaconda, Inc.|
  • CUDA/cuDNN version: No Cuda
  • GPU models and configuration: No GPU models
  • GCC version (if compiling from source): GCC 4.2.1 Compatible Clang 4.0.1

In order to use onnx on nn.InstanceNorm2d layers, I installed the latest pytorch from source following the instruction. Before installing the latest pytorch from source, I trained some pytorch model using the pytorch version installed through http://pytorch.org/. I was able to save the trained model as .pth file and load it back in successfully by doing the following:

model = myNet(parameters...)
model.load_state_dict(torch.load('xxx.pth'))

However, after I install the latest pytorch (from source). The load_state_dict is reporting errors:

File “/anaconda2/lib/python2.7/site-packages/torch/nn/modules/module.py”, line 528, in load_state_dict
.format(name))
KeyError: ‘unexpected key “pre_model.1.running_mean” in state_dict’

I did the following to check which layer was causing the problem
model1 = myNet(parameters...)
model2 = torch.load('xxx.pth')

for name, param in model2.items():
print(name)

for name, param in model1.state_dict().items():
print(name)

I found that for the instanceNorm2D layers, model2 contains xxx.running_mean and xxx.running_var, but not model1. Any idea what I should do?