Inconsistency in the load of the Wav2vec model
🐛 Bug
The Commit 032a404d389307a0e8f7dd2a0d501c78afa78f39 broke the load structure of the wav2vec multilingual model (trained before this commit).
Before the commit the models load normally occur after the following error occurs during the inference (more specifically during the model load):
INFO:main:| decoding with criterion ctc INFO:main:| loading model(s) from wav2vec/checkpoint_best_multilingual.pt Traceback (most recent call last): File "infer_multi.py", line 764, in
cli_main() File "infer_multi.py", line 760, in cli_main main(args) File "infer_multi.py", line 238, in main state=model_state, File "/root/fairseq/fairseq/checkpoint_utils.py", line 269, in load_model_ensemble state, File "/root/fairseq/fairseq/checkpoint_utils.py", line 318, in load_model_ensemble_and_task model = task.build_model(cfg.model) File "/root/fairseq/fairseq/tasks/audio_pretraining.py", line 201, in build_model model = super().build_model(model_cfg) File "/root/fairseq/fairseq/tasks/fairseq_task.py", line 282, in build_model model = models.build_model(cfg, self) File "/root/fairseq/fairseq/models/init.py", line 96, in build_model return model.build_model(cfg, task) File "/root/fairseq/fairseq/models/wav2vec/wav2vec2_asr.py", line 147, in build_model w2v_encoder = Wav2VecEncoder(cfg, task.target_dictionary) File "/root/fairseq/fairseq/models/wav2vec/wav2vec2_asr.py", line 298, in init task = tasks.setup_task(w2v_args.task) File "/root/fairseq/fairseq/tasks/init.py", line 39, in setup_task cfg = merge_with_parent(dc(), cfg) File "/root/fairseq/fairseq/dataclass/utils.py", line 448, in merge_with_parent merged_cfg = OmegaConf.merge(dc, cfg) File "/usr/local/lib/python3.6/dist-packages/omegaconf/omegaconf.py", line 321, in merge target.merge_with(*others[1:]) File "/usr/local/lib/python3.6/dist-packages/omegaconf/basecontainer.py", line 331, in merge_with self._format_and_raise(key=None, value=None, cause=e) File "/usr/local/lib/python3.6/dist-packages/omegaconf/base.py", line 101, in _format_and_raise type_override=type_override, File "/usr/local/lib/python3.6/dist-packages/omegaconf/_utils.py", line 629, in format_and_raise _raise(ex, cause) File "/usr/local/lib/python3.6/dist-packages/omegaconf/_utils.py", line 610, in _raise raise ex # set end OC_CAUSE=1 for full backtrace File "/usr/local/lib/python3.6/dist-packages/omegaconf/basecontainer.py", line 329, in merge_with self._merge_with(*others) File "/usr/local/lib/python3.6/dist-packages/omegaconf/basecontainer.py", line 347, in _merge_with BaseContainer._map_merge(self, other) File "/usr/local/lib/python3.6/dist-packages/omegaconf/basecontainer.py", line 294, in _map_merge dest_node._merge_with(src_value) File "/usr/local/lib/python3.6/dist-packages/omegaconf/basecontainer.py", line 347, in _merge_with BaseContainer._map_merge(self, other) File "/usr/local/lib/python3.6/dist-packages/omegaconf/basecontainer.py", line 305, in _map_merge dest._format_and_raise(key=key, value=src_value, cause=e) File "/usr/local/lib/python3.6/dist-packages/omegaconf/base.py", line 101, in _format_and_raise type_override=type_override, File "/usr/local/lib/python3.6/dist-packages/omegaconf/_utils.py", line 694, in format_and_raise _raise(ex, cause) File "/usr/local/lib/python3.6/dist-packages/omegaconf/_utils.py", line 610, in _raise raise ex # set end OC_CAUSE=1 for full backtrace omegaconf.errors.ValidationError: Invalid value 'False', expected one of [hard, soft] full_key: eval_wer_config.print_alignment reference_type=GenerationConfig object_type=GenerationConfig
I believe it is interesting to maintain compatibility with old models.
I'm having the same issue.
@Edresson I am facing the same issue while finetuning. Were you able to solve it?
I solved it by manually adjusting the parameter in the saved model from False to 'hard'. You need to do that for all occurrences of the parameter in the saved checkpoint from my experience
I solved it by manually adjusting the parameter in the saved model from False to 'hard'. You need to do that for all occurrences of the parameter in the saved checkpoint from my experience
Could you please share how to solve it ? I had tried by the following:
cp_path = "path/to/xlsr_53_56k.pt"
model = torch.load(cp_path)
model["last_optimizer_state"]["param_groups"][0]["amsgrad"]="hard"
torch.save(model,"path/to/xlsr_53_56k_modified.pt")
but it still doesn't work.
I solved it by manually adjusting the parameter in the saved model from False to 'hard'. You need to do that for all occurrences of the parameter in the saved checkpoint from my experience
Could you please share how to solve it ? I had tried by the following:
cp_path = "path/to/xlsr_53_56k.pt" model = torch.load(cp_path) model["last_optimizer_state"]["param_groups"][0]["amsgrad"]="hard" torch.save(model,"path/to/xlsr_53_56k_modified.pt")but it still doesn't work.
You got the right idea. You just need to find all the occurrences of 'print_alignment' in the saved model and change them. There are four occurrences if I'm not mistaken. I don't have my code at hand unfortunately.
I solved it by manually adjusting the parameter in the saved model from False to 'hard'. You need to do that for all occurrences of the parameter in the saved checkpoint from my experience
Could you please share how to solve it ? I had tried by the following:
cp_path = "path/to/xlsr_53_56k.pt" model = torch.load(cp_path) model["last_optimizer_state"]["param_groups"][0]["amsgrad"]="hard" torch.save(model,"path/to/xlsr_53_56k_modified.pt")but it still doesn't work.
You got the right idea. You just need to find all the occurrences of 'print_alignment' in the saved model and change them. There are four occurrences if I'm not mistaken. I don't have my code at hand unfortunately.
That solved it for me. I had to change 3 values, saved the model again, and loaded it using fairseq.checkpoint_utils. I'm not sure what the changed values mean, but it loads without errors.
cp = torch.load(model_path, map_location=torch.device('cpu'))
cp['last_optimizer_state']['param_groups'][0]['amsgrad']='hard'
cp['cfg']['generation']['print_alignment'] = 'hard'
cp['cfg']['task']['eval_wer_config']['print_alignment'] = 'hard'
torch.save(cp,new_model_path)
model = fairseq.checkpoint_utils.load_model_ensemble_and_task([new_model_path])[0][0]
@rokasgie @assafmu Thank you for your reply and help, I successfully load the pre-trained model and extract the feature.
Hey all, thanks for spotting this and apologies for the late fix. I just re-uploaded the model there: https://dl.fbaipublicfiles.com/fairseq/wav2vec/xlsr_53_56k.pt (same address than before) after following @assafmu's quick fix. I tried finetuning and it fixed it, please comment here if you still have this issue. Thank you.