RuntimeError when loading model checkpoint
See original GitHub issueWhen I am trying to load the model state dict for my pytorch model, I am getting the following error:
File "/opt/conda/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1406, in load_state_dict
raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format(
RuntimeError: Error(s) in loading state_dict for CustomModel:
size mismatch for extractor_s3prl.extracter._melscale.fb: copying a param with shape torch.Size([513, 64]) from checkpoint, the shape in current model is torch.Size([0]).
Can you guide me on how to resolve the same?
Below is just a snippet roughly representing my model code for your reference. After training my model, I saved its model state.
class CustomModel(nn.Module):
def __init__(self, ...):
super(CustomModel, self).__init__()
self.s3prl_feature_type = 'baseline_local'
self.extractor_s3prl = torch.hub.load('s3prl/s3prl', self.s3prl_feature_type, model_config='path_to_custom_mel.yaml').to('cuda')
Sincerely, Soham Tiwari
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
Error on loading checkpoint when training · Issue #26 - GitHub
Loading a model checkpoint as so: !python train.py --ckpt ... __name__, "\n\t".join(error_msgs))) RuntimeError: Error(s) in loading ...
Read more >OSError: Unable to load weights from pytorch checkpoint file
4 while the torch version I used when pretraining my model and saving my checkpoint was v1.9 (I pretrained my models on one...
Read more >Size Mismatch Runtime Error When Trying to Load a PyTorch ...
It seems to me that your model configuration does not match the content of the model checkpoint. I imagine your model has parameters...
Read more >RuntimeError when loading model - vision - PyTorch Forums
Hello,. I got the following error when I tried to load my model: RuntimeError: Error(s) in loading state_dict for VGG:.
Read more >Loading checkpoints when models built using a 'setup' block
I've found two especially troublesome issues. First, the load_from_checkpoint staticmethod fails. Second, when I manually load weights by first ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@leo19941227 I found this part in the source code:
Should we pass an
n_stft
value when we initializeMelScale
?Hey actually this is torchaudio’s bug and will be resolved after
torchaudio==v0.10.0
You can refer to this issue and I provide a workaround below with adding just one line: