KeyError: 'track_running_stats' on loading a older version model in pytorch 0.4

I tried to load an old pytorch version built model in pytorch 0.4 but I recieved this error on accessing the layers of model :

python3.6/site-packages/torch/nn/modules/batchnorm.py", line 53, in extra_repr
    'track_running_stats={track_running_stats}'.format(**self.__dict__)
KeyError: 'track_running_stats'

I was able to successfully load my model in pytorch 0.3 (or 0.3.1)

Any idea how to load the model in 0.4 or I need to revert pytorch version back???

Also this seems to be a batchnorm issue, my model loads correctly, and I can access fully connected layer as well!

1 Like

I downgraded for now ā€¦ :frowning:

Havenā€™t you solved the problem? The pytorch0.4.0 is difficult to use ļ¼ļ¼ļ¼

How did you save the model?
This workflow works for me:

In PyTorch 0.3.1.post3:

model = nn.BatchNorm1d(3)
torch.save(model.state_dict(), 'test.pt')

In PyTorch 0.4.0:

model = nn.BatchNorm1d(3)
model.load_state_dict(torch.load('test.pt'))
x = torch.randn(1, 3, 2)
model(x)

Did you save the complete model rather than its state_dict?
If so, you should get a warning:

SourceChangeWarning: source code of class ā€˜torch.nn.modules.batchnorm.BatchNorm1dā€™ has changed. you can retrieve the original source code by accessing the objectā€™s source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the changes.

Yeah torch.save was used for saving model directly instead of state dict :sweat_smile: . It was someone elseā€™s model

But trained a model on pytorch 0.4 so no issues now.

Hello, did anyone here get already solution? I have a model is trained on Pytorch 0.3 and I couldnā€™t afford to retrain on 0.4. I have the same problem that it is complained that the BatchNorm2d doesnā€™t have the attribute: ā€œtracking_running_stateā€. Is this a way that I could filter out the module is BatchNorm and add this attribute myself? Or any better ideas? Thanks in advance. My model is saved the whole model.