microsoft / ProphetNet

A research project for natural language generation, containing the official implementations by MSRA NLC team.
MIT License
651 stars 104 forks source link

KeyError: 'best_loss' at inference while using prophetnet code pretrained checkpoints. #44

Open anks12297 opened 2 years ago

anks12297 commented 2 years ago

I wanted to generated output for test file with pretrained weights without finetuning the model. I have preprocessed test.src and test.tgt. At inference time, I am encountering an error "KeyError: 'best_loss' "

Traceback (most recent call last): File "/home/ankita-sontakke/anaconda3/bin/fairseq-generate", line 8, in <module> sys.exit(cli_main()) File "/home/ankita-sontakke/anaconda3/lib/python3.8/site-packages/fairseq_cli/generate.py", line 379, in cli_main main(args) File "/home/ankita-sontakke/anaconda3/lib/python3.8/site-packages/fairseq_cli/generate.py", line 41, in main return _main(args, sys.stdout) File "/home/ankita-sontakke/anaconda3/lib/python3.8/site-packages/fairseq_cli/generate.py", line 88, in _main models, _model_args = checkpoint_utils.load_model_ensemble( File "/home/ankita-sontakke/anaconda3/lib/python3.8/site-packages/fairseq/checkpoint_utils.py", line 250, in load_model_ensemble ensemble, args, _task = load_model_ensemble_and_task( File "/home/ankita-sontakke/anaconda3/lib/python3.8/site-packages/fairseq/checkpoint_utils.py", line 279, in load_model_ensemble_and_task state = load_checkpoint_to_cpu(filename, arg_overrides) File "/home/ankita-sontakke/anaconda3/lib/python3.8/site-packages/fairseq/checkpoint_utils.py", line 232, in load_checkpoint_to_cpu state = _upgrade_state_dict(state) File "/home/ankita-sontakke/anaconda3/lib/python3.8/site-packages/fairseq/checkpoint_utils.py", line 374, in _upgrade_state_dict {"criterion_name": "CrossEntropyCriterion", "best_loss": state["best_loss"]} KeyError: 'best_loss'

S1s-Z commented 2 years ago

I have the same problem. Have you solved it?

S1s-Z commented 2 years ago

I guess they remove the useless logs from the model to reduce the file size, but I am not familiar with fairseq.

S1s-Z commented 2 years ago

` BEAM=5 LENPEN=1.5 CHECK_POINT=./model/checkpoint5.pt TEMP_FILE=fairseq_outputs.txt OUTPUT_FILE=sorted_outputs.txt

fairseq-generate processed --path $CHECK_POINT --user-dir prophetnet --task translation_prophetnet --batch-size 80 --gen-subset test --beam $BEAM --num-workers 4 --no-repeat-ngram-size 3 --lenpen $LENPEN 2>&1 > $TEMP_FILE grep ^H $TEMP_FILE | cut -c 3- | sort -n | cut -f3- | sed "s/ ##//g" > $OUTPUT_FILE

` so, how to load the model without finetuning in this way?