Open ultrons opened 3 years ago
Any update on this issue? I have a similar issue, though when trying to run fairseq.checkpoint_utils.load_model_ensemble_and_task
on a wav2vec model that I fine tuned myself with fairseq-hydra-train
. My issue looks like this:
omegaconf.errors.ConfigKeyError: Key 'eval_wer' not in 'AudioPretrainingConfig'
full_key: eval_wer
reference_type=Optional[AudioPretrainingConfig]
object_type=AudioPretrainingConfig
Met the same issue when loading multilingual pre-trained wav2vec 2.0 (XLSR) models, and I used the sample code from documentation.
import torch
import fairseq
cp_path = './ckpt/xlsr_53_56k.pt'
model, cfg, task = fairseq.checkpoint_utils.load_model_ensemble_and_task([cp_path])
model = model[0]
model.eval()
wav_input_16khz = torch.randn(1,10000)
z = model.feature_extractor(wav_input_16khz)
c = model.feature_aggregator(z)
Errors show:
omegaconf.errors.ConfigKeyError: Key 'eval_wer' not in 'AudioPretrainingConfig'
full_key: eval_wer
reference_type=Optional[AudioPretrainingConfig]
object_type=AudioPretrainingConfig
Any update on this issue? I have a similar issue, though when trying to run
fairseq.checkpoint_utils.load_model_ensemble_and_task
on a wav2vec model that I fine tuned myself withfairseq-hydra-train
. My issue looks like this:omegaconf.errors.ConfigKeyError: Key 'eval_wer' not in 'AudioPretrainingConfig' full_key: eval_wer reference_type=Optional[AudioPretrainingConfig] object_type=AudioPretrainingConfig
@kaleko I've solved this issue manually by dropping some keys in the state_dict. See : https://github.com/facebookresearch/fairseq/issues/4585
@xjtupanda Awesome your code solves the eval_wer
key issue for me. However, now I encounter a new one which I haven't been able to solve by dropping keys. Have you encountered this before?
omegaconf.errors.ConfigKeyError: Key 'target_dict' not in 'AudioPretrainingConfig'
full_key: target_dict
reference_type=Optional[AudioPretrainingConfig]
object_type=AudioPretrainingConfig
@kaleko Basically this is because there are some keys missing in the AudioPretrainingConfig and leads to inconsistency. I guess by dropping those keys may solve your problem, but I don't find the key 'target_dict' in my Config. But you can reference this for how to locate those keys and drop them.
Make sure you have installed omegaconf package. pip install omegaconf
from omegaconf import DictConfig, OmegaConf, open_dict
cp_path = './ckpt/xlsr_53_56k.pt'
cp = torch.load(cp_path)
cfg = DictConfig(cp['cfg'])
dd = OmegaConf.to_container(cfg, resolve=True)
for k,v in dd.items():
if not isinstance(v, dict):
continue
for key, _ in v.items():
if key == 'eval_wer':
print(k)
break
The result shows it's in the sub-dict 'task'.
with open_dict(cfg):
cfg.task.pop('eval_wer')
cp['cfg'] = cfg
torch.save(cp, './ckpt/xlsr_53_56k_new.pt')
@xjtupanda Great code! This also solves the issue for me. Did you manage to figure out whether dropping keys will have any negative impact on model performance?
@KiriKoppelgaard I suppose not since I was just trying to extract features using pretrained models. But to work around this, in the end I used transformers package and loaded the pretrained model from faecbook's Hugging Face pages, and it worked just fine without any error or warning.
A) wav2vec example when executed on TPU via using fairseq cli arguments leads to the following error:
Commandline used is:
B) When using hydra config file:
We see the following error:
This can be reproduced using: