Load state_dict from old pytorch version

kkjh0723: <p>I recently updated my pytorch to v1.5 and try to load trained weights from previous version.<br>
I got the following error.</p>
<pre><code class="lang-auto">RuntimeError: Error(s) in loading state_dict for DistributedDataParallel:
	Missing key(s) in state_dict: "module.total_ops", "module.total_params", "module.layer1.total_ops", "module.layer1.total_params", "module.layer1.0.total_ops", "module.layer1.0.total_params", "module.layer1.0.downsample.total_ops", "module.layer1.0.downsample.total_params", "module.layer1.1.total_ops", "module.layer1.1.total_params", "module.layer1.2.total_ops", "module.layer1.2.total_params", "module.layer2.total_ops", "module.layer2.total_params", "module.layer2.0.total_ops", "module.layer2.0.total_params", "module.layer2.0.downsample.total_ops", "module.layer2.0.downsample.total_params", "module.layer2.1.total_ops", "module.layer2.1.total_params", "module.layer2.2.total_ops", "module.layer2.2.total_params", "module.layer2.3.total_ops", "module.layer2.3.total_params", "module.layer3.total_ops", "module.layer3.total_params", "module.layer3.0.total_ops", "module.layer3.0.total_params", "module.layer3.0.conv1.total_ops", "module.layer3.0.conv1.total_params", "module.layer3.0.downsample.total_ops", "module.layer3.0.downsample.total_params", "module.layer3.1.total_ops", "module.layer3.1.total_params", "module.layer3.1.conv1.total_ops", "module.layer3.1.conv1.total_params", "module.layer3.2.total_ops", "module.layer3.2.total_params", "module.layer3.2.conv1.total_ops", "module.layer3.2.conv1.total_params", "module.layer3.3.total_ops", "module.layer3.3.total_params", "module.layer3.3.conv1.total_ops", "module.layer3.3.conv1.total_params", "module.layer3.4.total_ops", "module.layer3.4.total_params", "module.layer3.4.conv1.total_ops", "module.layer3.4.conv1.total_params", "module.layer3.5.total_ops", "module.layer3.5.total_params", "module.layer3.5.conv1.total_ops", "module.layer3.5.conv1.total_params", "module.layer4.total_ops", "module.layer4.total_params", "module.layer4.0.total_ops", "module.layer4.0.total_params", "module.layer4.0.conv1.total_ops", "module.layer4.0.conv1.total_params", "module.layer4.0.downsample.total_ops", "module.layer4.0.downsample.total_params", "module.layer4.1.total_ops", "module.layer4.1.total_params", "module.layer4.1.conv1.total_ops", "module.layer4.1.conv1.total_params", "module.layer4.2.total_ops", "module.layer4.2.total_params", "module.layer4.2.conv1.total_ops", "module.layer4.2.conv1.total_params"
</code></pre>
<p>It seems each module has new states <code>total_params</code> and <code>total_ops</code>.<br>
Which value supposed to be in those states?<br>
Is there any best practice to load state_dict from previous version?<br>
If I change <code>strict=False</code> for the <code>load_state_dict</code>, it runs without error.<br>
But I cannot check whether other parameters are properly loaded or not.</p>

ptrblck: <p>Did you add these parameters manually to your model, as I cannot find them in the <code>DistributedDataParallel</code> <a href="https://github.com/pytorch/pytorch/blob/master/torch/nn/parallel/distributed.py">implementation</a>?</p>

kkjh0723: <p>No, I didn’t. I thought those are newly added in pytorch version 1.5.<br>
Then, it might be added by <code>thop</code> package (<a href="https://github.com/Lyken17/pytorch-OpCounter" rel="nofollow noopener">link</a>) because it counts ops and params.<br>
But I don’t know why those values are added as a member variable in each module in pytorch 1.5 and not in 1.1.</p>
<p>I found that it happens when I call <code>thop.profile</code> before loading state_dict.<br>
I could solve it by just moving <code>thop.profile</code> after the loading.</p>