supported dynamic batch for torchscript trace
Author: MenglingD
Pull request: yes

# What does this PR do?

Fixup for supporting dynamic batch for Swin-Transformer.

Fixes #18806


## 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#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/main/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?


## 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.

<!-- 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

 -->

@novice03
@sgugger
@NielsRogge


Comments:
Hi,

Thanks for your PR. Note that, when contributing, you need to run `make fixup` from the root of the repo, which will fix code style & checks quality of the code. Normally here, it will complain that you need to run `make fix-copies`, which ensures that other models that rely on Swin's implementation also get updated (in this case, Donut).

 Thanks! 

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

Hi, @MenglingD .

In order to make CircleCI tests run, could you follow [this instruction](https://support.circleci.com/hc/en-us/articles/360048210711-How-to-Refresh-User-Permissions-) to refresh your CircleCI token, and let's see if it fixes the test not running issue. 

Thank you!