Temporarily fix ONNX model exporting error
Author: SatyaJandhyalaAtMS
Pull request: yes

…issues/143

# What does this PR do?
Fix the following error while trying to export ONNX model
**TypeError: '<=' not supported between instances of 'tuple' and 'Tensor'**
<!--
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 -->

Fixes # (issue)


## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [ ] 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:

- text models: @ArthurZucker and @younesbelkada
- vision models: @amyeroberts
- speech models: @sanchit-gandhi
- graph models: @clefourrier

Library:

- flax: @sanchit-gandhi
- generate: @gante
- pipelines: @Narsil
- tensorflow: @gante and @Rocketknight1
- tokenizers: @ArthurZucker
- trainer: @sgugger

Integrations:

- deepspeed: HF Trainer: @stas00, Accelerate: @pacman100
- ray/raytune: @richardliaw, @amogkam

Documentation: @sgugger, @stevhliu and @MKhalusova

HF projects:

- accelerate: [different repo](https://github.com/huggingface/accelerate)
- datasets: [different repo](https://github.com/huggingface/datasets)
- diffusers: [different repo](https://github.com/huggingface/diffusers)
- rust tokenizers: [different repo](https://github.com/huggingface/tokenizers)

Maintained examples (not research project or legacy):

- Flax: @sanchit-gandhi
- PyTorch: @sgugger
- TensorFlow: @Rocketknight1

 -->


Comments:
_The documentation is not available anymore as the PR was closed or merged._

cc @amyeroberts 

Thanks for opening this PR @SatyaJandhyalaAtMS ! 

Could you share a link to the issue this resolves? I'm getting a 404 error for the link in the commit / PR title: https://github.com/microsoft/onnx-converters-private/issues/143

The python code to reproduce the error is:
```
import onnxruntime as ort
from transformers import AutoImageProcessor, AutoModelForImageClassification
from PIL import Image
import requests
import numpy as np
import torch.onnx

url = "http://images.cocodataset.org/val2017/000000039769.jpg"
image = Image.open(requests.get(url, stream=True).raw)
processor = AutoImageProcessor.from_pretrained("microsoft/swinv2-tiny-patch4-window8-256")
model = AutoModelForImageClassification.from_pretrained("microsoft/swinv2-tiny-patch4-window8-256")
inputs = processor(images=image, return_tensors="pt")
outputs = model(**inputs)
logits = outputs.logits
# model predicts one of the 1000 ImageNet classes
predicted_class_idx = logits.argmax(-1).item()
options = ort.SessionOptions()
# options.log_severity_level = 0
torch.onnx.export(model, inputs['pixel_values'],"swinv2.onnx", export_params=True, opset_version=11, do_constant_folding=True, input_names=["input"], output_names=["output"])
ort_sess = ort.InferenceSession("swinv2.onnx", providers=["CUDAExecutionProvider"], sess_options=options)
ort_outputs=ort_sess.run(None, {"input":inputs['pixel_values'].numpy()})
ort_prediction=int(np.argmax(np.array(ort_outputs[0]).squeeze(), axis=0))
if ort_prediction == predicted_class_idx:
    print("Test passed")
else:
    print("Test failed")
```
The error is as follows:

Traceback (most recent call last):
  File "test_with_ort.py", line 19, in <module>
    torch.onnx.export(model, inputs['pixel_values'],"swinv2.onnx", export_params=True, opset_version=11, do_constant_folding=True, input_names=["input"], output_names=["output"])
  File "/home/sajandhy/miniconda3/envs/py38/lib/python3.8/site-packages/torch/onnx/utils.py", line 504, in export
    _export(
  File "/home/sajandhy/miniconda3/envs/py38/lib/python3.8/site-packages/torch/onnx/utils.py", line 1529, in _export
    graph, params_dict, torch_out = _model_to_graph(
  File "/home/sajandhy/miniconda3/envs/py38/lib/python3.8/site-packages/torch/onnx/utils.py", line 1111, in _model_to_graph
    graph, params, torch_out, module = _create_jit_graph(model, args)
  File "/home/sajandhy/miniconda3/envs/py38/lib/python3.8/site-packages/torch/onnx/utils.py", line 987, in _create_jit_graph
    graph, torch_out = _trace_and_get_graph_from_model(model, args)
  File "/home/sajandhy/miniconda3/envs/py38/lib/python3.8/site-packages/torch/onnx/utils.py", line 891, in _trace_and_get_graph_from_model
    trace_graph, torch_out, inputs_states = torch.jit._get_trace_graph(
  File "/home/sajandhy/miniconda3/envs/py38/lib/python3.8/site-packages/torch/jit/_trace.py", line 1184, in _get_trace_graph
    outs = ONNXTracedModule(f, strict, _force_outplace, return_inputs, _return_inputs_states)(*args, **kwargs)
  File "/home/sajandhy/miniconda3/envs/py38/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1194, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/sajandhy/miniconda3/envs/py38/lib/python3.8/site-packages/torch/jit/_trace.py", line 127, in forward
    graph, out = torch._C._create_graph_by_tracing(
  File "/home/sajandhy/miniconda3/envs/py38/lib/python3.8/site-packages/torch/jit/_trace.py", line 118, in wrapper
    outs.append(self.inner(*trace_inputs))
  File "/home/sajandhy/miniconda3/envs/py38/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1194, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/sajandhy/miniconda3/envs/py38/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1182, in _slow_forward
    result = self.forward(*input, **kwargs)
  File "/home/sajandhy/miniconda3/envs/py38/lib/python3.8/site-packages/transformers/models/swinv2/modeling_swinv2.py", line 1274, in forward
    outputs = self.swinv2(
  File "/home/sajandhy/miniconda3/envs/py38/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1194, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/sajandhy/miniconda3/envs/py38/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1182, in _slow_forward
    result = self.forward(*input, **kwargs)
  File "/home/sajandhy/miniconda3/envs/py38/lib/python3.8/site-packages/transformers/models/swinv2/modeling_swinv2.py", line 1078, in forward
    encoder_outputs = self.encoder(
  File "/home/sajandhy/miniconda3/envs/py38/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1194, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/sajandhy/miniconda3/envs/py38/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1182, in _slow_forward
    result = self.forward(*input, **kwargs)
  File "/home/sajandhy/miniconda3/envs/py38/lib/python3.8/site-packages/transformers/models/swinv2/modeling_swinv2.py", line 907, in forward
    layer_outputs = layer_module(
  File "/home/sajandhy/miniconda3/envs/py38/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1194, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/sajandhy/miniconda3/envs/py38/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1182, in _slow_forward
    result = self.forward(*input, **kwargs)
  File "/home/sajandhy/miniconda3/envs/py38/lib/python3.8/site-packages/transformers/models/swinv2/modeling_swinv2.py", line 821, in forward
    layer_outputs = layer_module(
  File "/home/sajandhy/miniconda3/envs/py38/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1194, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/sajandhy/miniconda3/envs/py38/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1182, in _slow_forward
    result = self.forward(*input, **kwargs)
  File "/home/sajandhy/miniconda3/envs/py38/lib/python3.8/site-packages/transformers/models/swinv2/modeling_swinv2.py", line 723, in forward
    self.set_shift_and_window_size(input_dimensions)
  File "/home/sajandhy/miniconda3/envs/py38/lib/python3.8/site-packages/transformers/models/swinv2/modeling_swinv2.py", line 670, in set_shift_and_window_size
    if input_resolution
**TypeError: '<=' not supported between instances of 'tuple' and 'Tensor'**

My Python environment is 
onnxruntime              1.14.1
torch                    1.13.1+cu116
torchaudio               0.13.1+cu116
torchvision              0.14.1+cu116
transformers             4.26.1
My platform is
Ubuntu 22.04

Thanks for updating @SatyaJandhyalaAtMS ! 

The tests are currently failing on the code quality checks. As the lines of code that have been modified are in a class with a `# Copied from` header, the original code source the comment points to will need to be updated i.e. the equivalent line in `transformers.models.swin.modeling_swin.SwinOutput`. 

Then run `make fix-copies` to propogate the change across the repo. 

To get the other styling tests pass, run `make style` to have the code formatted in the expected style