Fix bugs of s2t fairseq model converting
Author: beomseok-lee
Pull request: yes

# What does this PR do?

<!--
Congratulations! You've made it this far! You're not quite done yet though.

Once merged, your PR is going to appear in the release notes with the title you set, so make sure it's a great title that fully reflects the extent of your awesome contribution.

Then, please replace this with a description of the change and which issue is fixed (if applicable). Please also include relevant motivation and context. List any dependencies (if any) that are required for this change.

Once you're done, someone will review your PR shortly (see the section "Who can review?" below to tag some potential reviewers). They may suggest changes to make the code even better. If no one reviewed your PR after a week has passed, don't hesitate to post a new comment @-mentioning the same persons---sometimes notifications get lost.
-->

<!-- Remove if not applicable -->
This fix bugs in s2t fairseq model converting into HF one.

Fixes
- Fix typo in add_argument
- Fix `_Missing key(s) in state_dict_` error while loading fairseq model weights into HF model. This specifcally fixes issue cased by fairseq model's fixed positional embedding in both encoder and decoder.

## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [x] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/master/CONTRIBUTING.md#start-contributing-pull-requests),
      Pull Request section?
- [ ] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? Please add a link
      to it if that's the case.
- [ ] Did you make sure to update the documentation with your changes? Here are the
      [documentation guidelines](https://github.com/huggingface/transformers/tree/master/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/master/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?


## Who can review?
@patrickvonplaten 

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

<!-- Your PR will be replied to more quickly if you can figure out the right person to tag with @

 If you know how to use git blame, that is the easiest way, otherwise, here is a rough guide of **who to tag**.
 Please tag fewer than 3 people.

Models:

- albert, bert, xlm: @LysandreJik
- blenderbot, bart, marian, pegasus, encoderdecoder,  t5: @patrickvonplaten, @patil-suraj
- longformer, reformer, transfoxl, xlnet: @patrickvonplaten
- fsmt: @stas00
- funnel: @sgugger
- gpt2: @patrickvonplaten, @LysandreJik
- rag: @patrickvonplaten, @lhoestq
- tensorflow: @LysandreJik

Library:

- benchmarks: @patrickvonplaten
- deepspeed: @stas00
- ray/raytune: @richardliaw, @amogkam
- text generation: @patrickvonplaten
- tokenizers: @n1t0, @LysandreJik
- trainer: @sgugger
- pipelines: @LysandreJik

Documentation: @sgugger

HF projects:

- datasets: [different repo](https://github.com/huggingface/datasets)
- rust tokenizers: [different repo](https://github.com/huggingface/tokenizers)

Examples:

- maintained examples (not research project or legacy): @sgugger, @patil-suraj
- research_projects/bert-loses-patience: @JetRunner
- research_projects/distillation: @VictorSanh

 -->


Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_15593). All of your documentation changes will be reflected on that endpoint.

>  @patil-suraj it's also possible that the position embedding weights are present when converting from Fairseq no? Or are they always missing?

Sinusoidal embeddings in fairseq are not registered as parameters, so they are always missing from the `state_dict`

> > @patil-suraj it's also possible that the position embedding weights are present when converting from Fairseq no? Or are they always missing?
> 
> Sinusoidal embeddings in fairseq are not registered as parameters, so they are always missing from the `state_dict`

@patrickvonplaten good point, technically positional embedding weights can be present if fairseq model is trained using learned embedding. Say if you give `learned=True`  as a 4th argument in [PositionalEmbedding function](https://github.com/pytorch/fairseq/blob/5f2515e676985efd2944f6c87fe1b086cb94bdee/fairseq/modules/positional_embedding.py#L12~L16)  which is being called in [encoder](https://github.com/pytorch/fairseq/blob/5f2515e676985efd2944f6c87fe1b086cb94bdee/fairseq/models/speech_to_text/s2t_transformer.py#L331~#L333) and [decoder](https://github.com/pytorch/fairseq/blob/5f2515e676985efd2944f6c87fe1b086cb94bdee/fairseq/models/transformer/transformer_decoder.py#L97~#L103).
@patil-suraj , kindly correct me if I am wrong.

So in short, depending on training h-parameter settings, `missing` lists can be 4 cases.
`[], ["encoder.embed_positions.weights"], ["decoder.embed_positions.weights"], ["encoder.embed_positions.weights", "decoder.embed_positions.weights"]`, although if the model is trained straight-forward way(using fixed positional embedding), both of encoder, decoder positional embedding weights must be missing.

Based on @patrickvonplaten suggestion, I have modifed to code to cover all thoses cases.
Thank you for suggestion.

Please review reflected changes @patil-suraj @patrickvonplaten 


hmm I kind of did something wrong with git by force-push ing it. Please let me know if it can be a problem :( 

@patil-suraj could you take a final look here and merge if ok?

Hey guys, I have trained s2t model with fairseq and for some reason conversion still fails. https://github.com/huggingface/transformers/blob/main/src/transformers/models/speech_to_text/convert_s2t_fairseq_to_tfms.py#L56 here it seems args is actually none. It seems that ['cfg']['model'] is a thing code actually requires. with this change conversion is successful but I am missing preprocessor_config.json can anyone help me with this one?

@patil-suraj could you take a quick look here?

Also while we are at it, conversion does not take into account about model.vocab file, the easiest way I find possible to successfully transcribe audio with hf was to copy spm_unigram10000.vocab and rename it to vocab.json, also grapped this one as a pre processor https://huggingface.co/facebook/s2t-small-librispeech-asr/blob/main/preprocessor_config.json. I think vocab should be saved with fairseq pt or script should require its path at least...  also Speech2TextForConditionalGeneration  generate function does not take input_ids it takes inputs. I will be happy to help in any way ;)