Add interpolation of positional embedding to swin2sr
Author: M-Ali-ML
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 PR add the `interpolate_pos_encoding` function to the [Swin2SR](https://huggingface.co/docs/transformers/en/model_doc/swin2sr#transformers.Swin2SRImageProcessor) transformer model, the purpose of it is to allow input images with resolution different than the pretrained resolution.

This is part of the [community contribution thread](https://github.com/huggingface/transformers/issues/30579).



## 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/main/CONTRIBUTING.md#create-a-pull-request),
      Pull Request section?
- [X] 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.
- [X] Did you make sure to update the documentation with your changes? Here are the
      [documentation guidelines](https://github.com/huggingface/transformers/tree/main/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [X] Did you write any new necessary tests?


## Usefulness

Swin2SR transformer by nature supports different input resolution that is due to the case of log-spaced continuous relative position bias which allows it to generalize to higher input resolution at inference time as stated in the [paper](https://arxiv.org/abs/2209.11345).
I'd say having `interpolate_pos_encoding` for Swin2SR is good for code consistency between it and other Visual transformers of the same nature, however its effectiveness is still to be reviewed.
Discussion about Swin family ability to support different resolution was made in this PR #30656.


## Who can review?

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.

@amyeroberts



Comments:
Hi @MightyStud, thanks for opening this PR and apologies for the delay in reviewing. As Swin2SR doesn't require this, then I don't think it makes sense to add to the model and we can close this PR. My bad for having it on the list of models to add on the issue - I'll update this now.

@amyeroberts 
Understable, I'll keep an eye on the next contribution thread, since I'd like to be part of huggingface contributors one day 😅