Issue when exporting SwinForImageClassification to ONNX format
Author: BenoitLeguay
Pull request: no

### System Info

### 1. Libraries version
transformers == 4.23.1 / torch == 1.12.1 / onnx = 1.12.0
### 2. Context
I trained an Image Classifier using `SwinForImageClassification` with a custom number of labels. I want to put it in production using the ONNX format. So I need to export my model in this format.
### Error
I used the `python -m transformers.onnx [...]` as recommended in [your documentation](https://huggingface.co/docs/transformers/serialization#exporting-a-model-to-onnx). 
Without considering some warning (available hereabove) during the ONNX creation, the model's creation works. However the test that compares values (`validate_model_outputs`) at the end fails:

```
$ python -m transformers.onnx --model='test_onnx/swin_classif/sources' test_onnx/swin_classif/ --feature='image-classification' --preprocessor=feature_extractor
[...]
Validating ONNX model...
	-[✓] ONNX model output names match reference model ({'logits'})
	- Validating ONNX Model output "logits":
		-[✓] (3, 160) matches (3, 160)
		-[x] values not close enough (atol: 0.0001)
[...]
```
I tried to use `torch.onnx.export` and `transformers.onnx.export`. The same behaviour happened. **BUT when I tried with the model ViT (`ViTForImageClassification`), everything worked well !!** 

### 3. How to reproduce the issue
_In the dedicated section._

I don't know if I miss something obvious here ? 
Thank you for your work 🤗 and I hope we can solve this ! 🚀 

### 4. Warning during ONNX creation
here is the different warning I have when creating the ONNX model: (Each happen multiple times for different operation)
```
- TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
- UserWarning: __floordiv__ is deprecated, and its behavior will change in a future version of pytorch. It currently rounds toward 0 (like the 'trunc' function NOT 'floor'). This results in incorrect rounding for negative values. To keep the current behavior, use torch.div(a, b, rounding_mode='trunc'), or for actual floor division, use torch.div(a, b, rounding_mode='floor').
- WARNING: The shape inference of prim::Constant type is missing, so it may result in wrong shape inference for the exported graph. Please consider adding it in symbolic function.
```


### Who can help?

@NielsRogge, @sgugger

### Information

- [X] The official example scripts
- [ ] My own modified scripts

### Tasks

- [X] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [ ] My own task or dataset (give details below)

### Reproduction

Here is the code to reproduce the issue:
**step 1: Save pretrained**
```
from transformers import SwinForImageClassification, AutoFeatureExtractor
pretrained_path = "microsoft/swin-tiny-patch4-window7-224"

swin_classif = SwinForImageClassification.from_pretrained(pretrained_path, ignore_mismatched_sizes=True, num_labels=160)
feat_extract = AutoFeatureExtractor.from_pretrained(pretrained_path)

swin_classif.save_pretrained('test_onnx/swin_classif/sources')
feat_extract.save_pretrained('test_onnx/swin_classif/sources')
```
**step 2: Build ONNX**
`python -m transformers.onnx --model='test_onnx/swin_classif/sources' test_onnx/swin_classif/ --feature='image-classification' --preprocessor=feature_extractor`

### Expected behavior

I would expect the ONNX creation for `SwinForImageClassification` to work: given the same input, SwinForImageClassification model produces the same output as its exported version in ONNX format.

Comments:
You can try a slightly less strict absolute difference, as explained here: https://github.com/huggingface/transformers/issues/15716#issuecomment-1044630255

Hello @NielsRogge, thank your for this quick response !
I was not clear, the test is not failing for a bad reason: the outputs are actually significantly different:
here is the full error message: 
```
Validating ONNX model...
	-[✓] ONNX model output names match reference model ({'logits'})
	- Validating ONNX Model output "logits":
		-[✓] (3, 160) matches (3, 160)
		-[x] values not close enough (atol: 0.0001)
Traceback (most recent call last):
  File "/Users/bleguay/.pyenv/versions/3.10.0/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/Users/bleguay/.pyenv/versions/3.10.0/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/Users/bleguay/.pyenv/versions/piraeus-model/lib/python3.10/site-packages/transformers/onnx/__main__.py", line 180, in <module>
    main()
  File "/Users/bleguay/.pyenv/versions/piraeus-model/lib/python3.10/site-packages/transformers/onnx/__main__.py", line 173, in main
    validate_model_outputs(onnx_config, preprocessor, model, args.output, onnx_outputs, args.atol)
  File "/Users/bleguay/.pyenv/versions/piraeus-model/lib/python3.10/site-packages/transformers/onnx/convert.py", line 455, in validate_model_outputs
    raise ValueError(
ValueError: Outputs values doesn't match between reference model and ONNX exported model: Got max absolute difference of: 1.3692436218261719 for [-0.06106845  0.12285465 -0.18921788  0.5049372  -0.1986409   0.34636068
 -0.1691071  -0.02217978 -0.6896293  -0.21974993 -0.76842034  0.00995809
 -0.11905045 -0.09523626 -0.17755091 -0.04897689  0.39708626  0.05108643
  0.06990042 -0.04949172 -0.15309443 -0.8103958   0.3775105  -0.45507845
 -0.05611497  0.05218322 -0.71096545 -0.38933533  0.06547274 -0.3132524
  0.26966637  0.02131431 -0.07573311  0.19405767 -0.16967274 -0.5358653
  0.83661413 -0.23051989 -0.33136314  0.28437945  0.23672453  0.1740103
 -0.30914858 -0.33530912  0.20119892  0.402417   -0.01951164 -0.5698619
 -0.35475633 -0.1181808  -0.4235557  -0.34506178 -0.12214591 -0.49559855
 -0.50011915  0.71717185 -0.23441991  0.3804775  -0.15777466  0.19934995
 -0.2813175  -0.16817626  0.1785079  -0.48286003 -0.1709578   0.2557745
 -0.01732143 -0.24144898 -0.15041552 -0.49435216 -0.10977422 -0.23015508
  0.40337044  0.13203782  0.45959228 -0.45770365  0.29646975 -0.02936734
  0.06572083 -0.14521742 -0.196341    0.4045911   0.10471516  0.23922467
  0.50704205  0.08659008 -0.02236488  0.3054718   0.30713248 -0.09301025
 -0.0402      0.11342324 -0.28109962  0.27469164 -0.10700954 -0.06830485
  0.4378688   0.15085813 -0.45130914  0.16799057  0.33943364  0.6166247
 -0.37087205 -0.32451615  0.13080192 -0.2465924   0.21146286  0.46603474
 -0.3899023   0.5917809   0.18371034 -0.4288618  -0.5969511  -0.11656356
  0.5030414   0.29792047 -0.33490264 -0.23519978  0.4783889  -0.17767602
 -0.19774103 -0.14759333  0.20283869 -0.33203778 -0.15488361  0.28006512
  0.01535628  0.6650907   0.31069627  0.1286084   0.49600935  0.34268755
 -0.04938671 -0.57014364  0.72736365 -0.10143891 -0.6347118   0.07822949
 -0.30062795 -0.54248583 -0.4074985  -0.3044052   0.18507619 -0.36234486
  0.46773177 -0.11254795  0.27562687 -0.10287824  0.1802718   0.01491091
 -0.41343385  0.17572625 -0.20250738 -0.43644306  0.41057307  0.1371599
  0.6772319  -0.49024868 -0.02152741 -0.3506258  -0.18412054  0.12870055
 -0.19661918  0.46798164  0.04501206  0.22052541 -0.17762536  0.06754559
 -0.6358628  -0.29670113 -0.73341167  0.09625536 -0.10944731 -0.14755067
 -0.14341569  0.11812273  0.29438084  0.02348799  0.034365   -0.03890094
 -0.32477033 -0.640104    0.30603072 -0.43583125 -0.01389889  0.05416113
 -0.679801   -0.45222676 -0.0023165  -0.41687882  0.22143522 -0.2897661
 -0.05619043  0.06813143 -0.09530576 -0.5496853   0.7789349  -0.14078154
 -0.35014948  0.2892362   0.18976417  0.05590723 -0.3260829  -0.40019906
  0.21867548  0.3817903  -0.00801944 -0.54762053 -0.3570432  -0.12390244
 -0.5746232  -0.32545304 -0.08603653 -0.58821917 -0.5115222   0.7171049
 -0.2543296   0.43015337 -0.06181256  0.11959662 -0.12665194 -0.17386276
  0.18951124 -0.29464567 -0.32482645  0.16736132 -0.13734964 -0.13887791
 -0.21936226 -0.5363412   0.00894417 -0.4345506   0.3795787   0.15755552
  0.40534687 -0.4798122   0.48428625 -0.11364223  0.12477627 -0.06477118
  0.01065597  0.27613276  0.20831317  0.26337263  0.56675375  0.20128776
 -0.07043616  0.34169155  0.2943419  -0.11713834 -0.07966733  0.0499542
 -0.348781    0.21979605 -0.28619874 -0.09100726  0.37456948  0.13946635
 -0.33606255  0.15814117  0.34456918  0.66328716 -0.34123376 -0.3316517
 -0.07244727 -0.17735815  0.19246355  0.6528053  -0.42591572  0.54325604
  0.21217923 -0.44543248 -0.5038978  -0.1207954   0.5446789   0.12648779
 -0.3198638  -0.30068278  0.5454049  -0.2828171  -0.19203103 -0.26519054
  0.22469468 -0.42633253 -0.12229709  0.24556151  0.01124579  0.64908105
  0.3516025   0.28168085  0.40130708  0.14279017 -0.11640775 -0.41997045
  0.61343706 -0.01251362 -0.6319312   0.03432515 -0.32933724 -0.5734776
 -0.41919896 -0.19220461  0.19410697 -0.36557207  0.28580746 -0.15460443
  0.36335593 -0.08719397  0.26283717  0.03314497 -0.3651286   0.10970266
 -0.25979558 -0.3208456   0.3499791   0.15752569  0.6617712  -0.4127711
  0.02931512 -0.35706407 -0.2145712   0.02474257 -0.17494626  0.60114133
 -0.06213076  0.1068871  -0.04108006  0.07552788 -0.6358697  -0.40869412
 -0.68531764  0.0760276  -0.12475098 -0.1669592  -0.16771694  0.14568909
  0.3728184   0.2728331  -0.11506456  0.02971141 -0.10832652 -0.78700745
  0.11165941 -0.42647707  0.13101816  0.01028017 -0.68079805 -0.5744518
  0.0489867  -0.21155152  0.2604037  -0.09611046 -0.02375504  0.22795928
 -0.1619378  -0.5631519   0.8423456  -0.00467771 -0.13729835  0.23964095
  0.14606774  0.12160218 -0.06164521 -0.5445323   0.33276808  0.49160522
  0.01048732 -0.6667893  -0.28605506 -0.31852537 -0.40799573 -0.4934004
 -0.25376865 -0.39825052 -0.6462982   0.8023047  -0.13846312  0.6053733
 -0.00777063  0.2746262  -0.21927634 -0.14655772  0.3084348  -0.35635483
 -0.22394183  0.13854408  0.01103184 -0.17685157 -0.16520068 -0.5759028
  0.21486142 -0.38122138  0.21948887  0.1675158   0.37934083 -0.42796057
  0.21204138 -0.05589592  0.13516527 -0.00360115 -0.00644675  0.26455837
  0.1864259   0.019116    0.74247843  0.04402375 -0.12179609  0.15354294
  0.3543662  -0.11259714  0.12143008 -0.07637051 -0.34425476  0.38279337
 -0.11939427 -0.14530821  0.5397643   0.21652104 -0.20089209  0.39749998
  0.45645627  0.47782743 -0.3020329  -0.15384908  0.21358004 -0.18617995
  0.31016254  0.54617953 -0.5179592   0.45387554  0.3203557  -0.32384175
 -0.46208858 -0.2512101   0.5824921   0.13412705 -0.215639   -0.4263451
  0.4956808  -0.29090098 -0.15356363 -0.06714268  0.3812586  -0.49488905
 -0.17332229  0.55745924 -0.15221891  0.83650666  0.36271864 -0.00793004
  0.4636365   0.46242952 -0.27560318 -0.3318567   0.6762064  -0.12277468
 -0.5726782   0.3396322  -0.56470525 -0.5560886  -0.3274095  -0.2678147
  0.06875373 -0.25510776  0.24946427 -0.04763301  0.27787483 -0.14732757
  0.27278543 -0.17570269 -0.3139099   0.10965091 -0.28918004 -0.16069773
  0.3428337   0.13698481  0.8861261  -0.23068875  0.0391845  -0.18411607] vs [ 1.28135830e-01  1.70594186e-01  6.14838600e-01  5.49140811e-01
  4.69820261e-01  1.11730479e-01 -3.14225554e-01  7.81431854e-01
 -7.78754950e-01 -6.38007522e-02  2.28893846e-01 -6.26583874e-01
 -2.50711739e-01 -4.85903800e-01 -3.10093999e-01  6.24564886e-01
 -5.28742313e-01  5.05275965e-01 -4.65409130e-01  6.56028330e-01
 -2.03518152e-01 -1.51091576e-01  3.00208390e-01 -2.97761351e-01
 -1.71665862e-01 -5.28911278e-02  2.03803942e-01  1.40974492e-01
 -1.21421896e-01  8.24191928e-01  3.42895120e-01  7.86975741e-01
 -5.23516983e-02 -3.52419317e-01  3.02186906e-01  2.88510144e-01
  3.51488084e-01  7.02708364e-02 -1.15866810e-01 -2.68891037e-01
  8.08803618e-01 -5.92842326e-02  6.99101463e-02  8.97745937e-02
  1.39535978e-01 -3.86431873e-01  6.02225512e-02  4.87125576e-01
  6.85935169e-02 -4.39252973e-01 -1.72007129e-01  5.41739464e-01
  1.04485273e-01  2.95256585e-01 -2.49259204e-01  8.35965753e-01
 -3.85174900e-01  1.60440445e-01  5.23748919e-02 -2.11794093e-01
 -3.98029804e-01 -3.30731153e-01 -4.34303999e-01 -2.86957264e-01
  2.27841839e-01 -4.76897717e-01  9.08873975e-02 -2.30960101e-02
 -1.24389812e-01 -3.04996610e-01 -7.26581812e-02  8.28876942e-02
 -3.23720336e-01  1.00407183e-01  7.57869110e-02 -4.93685246e-01
  1.62461221e-01  3.72860581e-02  1.72318250e-01  4.84319180e-01
  3.54439080e-01  2.43036404e-01  4.60274130e-01 -1.69880912e-01
 -9.97056365e-02  7.78566450e-02 -4.69432414e-01  1.40246347e-01
  1.33542120e-01 -7.03689381e-02 -1.00386068e-01  7.72113204e-02
 -1.47819608e-01 -5.82554340e-02 -2.82135569e-02  2.54881173e-01
 -1.36251241e-01  8.71378422e-01 -4.29740548e-01 -1.30290717e-01
 -1.91676959e-01 -7.64316134e-03  1.98935851e-01 -5.97431183e-01
 -2.06617534e-01 -3.22597101e-02 -2.79274642e-01  7.76519418e-01
 -9.51622844e-01 -2.75189161e-01  6.74007177e-01  9.40381885e-01
 -9.32118535e-01 -3.05536866e-01  7.94740081e-01  2.92763114e-03
  3.38176519e-01  3.78656387e-01  3.12738180e-01  9.91565406e-01
  1.87288716e-01  2.43043900e-02  4.11912024e-01  5.47892213e-01
  2.22662203e-02 -6.54011011e-01  5.97522743e-02 -1.50490522e-01
 -5.57740033e-03 -1.17180705e+00 -5.18481553e-01  2.62342155e-01
  6.85439408e-02  4.19662029e-01 -3.49796116e-02 -2.48095900e-01
  8.43257308e-02  6.76371306e-02 -1.49092495e-01  3.83319199e-01
  2.13684678e-01 -6.26890957e-01 -2.54286230e-01 -3.43747616e-01
  7.39749193e-01 -9.40448791e-02  3.17870259e-01  2.62159199e-01
  3.28509994e-02 -2.41731316e-01 -1.90109000e-01  2.16163784e-01
 -9.76384804e-02 -1.72702849e-01  7.67504573e-01 -9.20159459e-01
  6.19455040e-01 -5.25325775e-01 -6.09292686e-02 -8.52263391e-01
  3.49729359e-02  2.97759563e-01  4.74937022e-01  4.12648469e-01
  3.74721527e-01  1.21058494e-01 -2.41388261e-01  5.22115350e-01
 -6.32577777e-01 -2.46033400e-01  1.91389874e-01 -5.35460591e-01
 -1.25709504e-01 -2.99965620e-01 -3.21753263e-01  6.38255298e-01
 -4.51283753e-01  3.47820938e-01 -3.67054909e-01  7.22098470e-01
 -7.49995261e-02 -2.69949436e-04  1.94670975e-01 -3.32899958e-01
 -1.89728126e-01 -8.35971460e-02  1.95707992e-01  3.98901105e-02
 -1.33678481e-01  7.17000544e-01  2.51645386e-01  6.28485441e-01
 -4.08213362e-02 -2.41552234e-01  2.71573693e-01  1.91486299e-01
  2.80226946e-01  1.29383892e-01 -7.03004003e-03 -2.07323164e-01
  7.42809296e-01  6.88267723e-02  1.41356453e-01  8.76589119e-03
 -7.38414377e-02 -2.32301414e-01 -3.41140553e-02  3.97274435e-01
  1.06192134e-01 -3.51829886e-01 -1.51566312e-01  3.19048643e-01
  1.42810777e-01  3.39679480e-01 -1.44272953e-01  7.85561681e-01
 -3.36977839e-01  2.64188260e-01  1.31466910e-01 -1.54473707e-01
 -3.54027689e-01 -1.93621725e-01 -3.35431397e-01 -4.76616234e-01
  2.06029937e-02 -3.50014389e-01  1.81897417e-01  8.24268311e-02
 -2.30000913e-02 -2.42241010e-01  4.12289798e-02  7.83494562e-02
 -1.72393918e-01  2.17643529e-01 -2.60747671e-02 -4.16156232e-01
  3.03777814e-01 -5.40386960e-02  6.67198151e-02  4.56765771e-01
  3.69238377e-01  1.72009140e-01  3.90102506e-01 -2.16501951e-03
 -3.63569856e-02  1.27335161e-01 -4.36197102e-01  6.97868913e-02
  1.27704307e-01 -4.65597659e-02 -2.03634501e-02 -8.04828554e-02
 -2.23698825e-01  9.33380425e-02  2.99127866e-02  1.32678315e-01
 -4.50977460e-02  5.54340482e-01 -4.47369814e-01 -1.33852601e-01
 -2.27702424e-01 -5.08142710e-02  3.23214084e-02 -4.97159541e-01
 -6.76678792e-02 -1.18632764e-02 -3.19975317e-01  6.18933976e-01
 -8.35424006e-01 -2.17268616e-01  5.38547099e-01  7.82708168e-01
 -7.28415847e-01 -3.76167625e-01  7.20639646e-01 -2.98585370e-02
  3.13809663e-01  3.75187397e-01  2.95831412e-01  7.43884027e-01
  2.41576448e-01 -3.37805748e-02  3.47715080e-01  3.96632254e-01
  1.10012099e-01 -6.08244777e-01  2.12903321e-01 -1.63437888e-01
 -7.51893967e-02 -9.13728237e-01 -4.68309462e-01  3.74763846e-01
  2.36880124e-01  4.99360204e-01 -1.27683178e-01 -1.62899733e-01
 -4.91339564e-02  1.81253344e-01 -2.63938606e-01  3.13691497e-01
  1.07467033e-01 -7.42356539e-01 -2.58050889e-01 -3.22008431e-01
  6.78506076e-01 -1.45394772e-01  2.70696759e-01  3.50923687e-01
 -7.57573247e-02 -1.38874620e-01 -1.54216737e-01  1.37292415e-01
 -7.87530318e-02 -5.00483513e-02  5.29465675e-01 -7.31449962e-01
  5.23882926e-01 -4.19330299e-01 -9.64103192e-02 -7.04261661e-01
  3.08752805e-02  3.94386828e-01  2.87204802e-01  4.62714702e-01
  5.20519018e-01  2.81967223e-03 -1.11178473e-01  3.29341650e-01
 -4.91796076e-01 -1.48085549e-01  3.37434769e-01 -5.45709729e-01
 -2.42450729e-01 -2.33173251e-01 -1.59645155e-01  5.44530272e-01
 -2.20042616e-01  4.29684460e-01 -2.49880582e-01  6.03968561e-01
 -3.21873307e-01 -1.12634033e-01  1.81830376e-01 -3.89184594e-01
 -8.15919116e-02 -6.89003021e-02  7.63039812e-02  1.95880234e-02
 -1.96111768e-01  3.62800628e-01  4.66887712e-01  5.83167613e-01
 -1.32455155e-01 -1.76099494e-01  1.39247552e-01  2.91690230e-04
  2.45634049e-01  7.26491213e-04 -2.00259775e-01 -2.07394928e-01
  5.47502339e-01  1.02231331e-01  1.24914005e-01 -9.48404223e-02
  2.15078831e-01 -2.26227790e-01 -5.45244068e-02  5.22263587e-01
  1.91077724e-01 -3.76865506e-01 -2.76545167e-01 -1.89595520e-02
  1.13320798e-01  4.43316698e-01 -7.80223310e-03  6.66806459e-01
 -3.06726873e-01  2.46964782e-01  7.84370899e-02 -1.28809810e-01
 -5.39565802e-01 -1.98737055e-01 -1.61629170e-01 -3.02407473e-01
 -9.33168381e-02 -3.91638517e-01  1.05690464e-01  1.98325083e-01
  1.73466951e-02 -1.78393722e-01  1.25586331e-01  1.71870857e-01
 -1.55802384e-01  2.79657423e-01  8.37599337e-02 -5.50163031e-01
  2.16353491e-01 -1.55411944e-01  3.19299370e-01  3.90772939e-01
  3.30768943e-01  3.21978390e-01  3.36048454e-01 -8.26082975e-02
 -2.19058156e-01  1.17783785e-01 -4.63917285e-01  1.32965475e-01
  3.70263979e-02  4.70926464e-02 -1.88485935e-01  3.04759294e-02
 -4.24536645e-01 -1.19624823e-01  6.26472831e-02  7.19535574e-02
 -1.17991343e-01  7.79137611e-01 -3.08348000e-01 -2.85789147e-02
 -1.23305023e-01 -8.19939896e-02 -1.82029188e-01 -4.57080245e-01
 -1.45158798e-01  2.03296900e-01 -3.76549602e-01  8.43308747e-01
 -6.78866088e-01 -2.71210581e-01  3.46639276e-01  5.15377283e-01
 -7.02733040e-01 -3.25193912e-01  7.90245235e-01  1.20106429e-01
  1.75307781e-01  4.03955936e-01  2.31727779e-01  4.24922645e-01
  3.54552150e-01 -7.68869817e-02  2.86569037e-02  2.98314989e-01
  1.87978402e-01 -3.57333481e-01 -5.52355777e-03  1.02877691e-01
  2.87557989e-02 -7.47255445e-01 -2.54889637e-01  2.26086974e-01
  1.32456273e-01  3.13082397e-01  1.53662413e-02 -2.44875416e-01
  5.08328080e-02 -3.98641359e-03 -2.89956808e-01  2.00657517e-01
 -6.49997815e-02 -6.43398166e-01 -2.27469847e-01 -2.91537702e-01
  5.35060704e-01 -1.61430389e-01  2.72467971e-01  1.79417342e-01
 -9.78902429e-02 -1.58466801e-01 -9.94352624e-02  2.16749936e-01
 -3.77055258e-03  1.51243865e-01  3.97949338e-01 -7.20643342e-01
  5.21070600e-01 -2.63261348e-01 -1.96940526e-01 -5.89750171e-01]
```

A quicker way to reproduce the error is actually to do 
```
$ python -m transformers.onnx --model=microsoft/swin-base-patch4-window12-384-in22k test_onnx/from_hub/ --feature='image-classification' --preprocessor=feature_extractor
Validating ONNX model...
	-[✓] ONNX model output names match reference model ({'logits'})
	- Validating ONNX Model output "logits":
		-[✓] (3, 21841) matches (3, 21841)
		-[x] values not close enough (atol: 0.0001)
Traceback (most recent call last):
  File "/Users/bleguay/.pyenv/versions/3.10.0/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/Users/bleguay/.pyenv/versions/3.10.0/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/Users/bleguay/.pyenv/versions/piraeus-model/lib/python3.10/site-packages/transformers/onnx/__main__.py", line 180, in <module>
    main()
  File "/Users/bleguay/.pyenv/versions/piraeus-model/lib/python3.10/site-packages/transformers/onnx/__main__.py", line 173, in main
    validate_model_outputs(onnx_config, preprocessor, model, args.output, onnx_outputs, args.atol)
  File "/Users/bleguay/.pyenv/versions/piraeus-model/lib/python3.10/site-packages/transformers/onnx/convert.py", line 455, in validate_model_outputs
    raise ValueError(
ValueError: Outputs values doesn't match between reference model and ONNX exported model: Got max absolute difference of: 5.501317977905273 for [-0.7436858   1.7425342  -0.70307475 ... -0.6807119  -0.511953
 -0.6309131 ] vs [-1.0538013   1.1691334  -1.2402858  ...  0.5939584  -0.33656883
 -1.2150081 ]
```
I also found that: https://github.com/huggingface/transformers/pull/19390/
Hope this helps.

Hello everyone, 
any news on this topic ?
I don't want to be too pushy, but could I have a quick follow up ?

Thanks 🤗 

cc @lewtun would be great if you could take a look at this

Thank you @NielsRogge 

I fully understand that this might not be your current priority. Though, could I have some information about when should I expect some follow up on this ? 
I count on this ONNX format for production deployment purposes and I'd like to be able to organize and communicate regarding my roadmap. 

Thanks again for you work.  🤗 

@BenoitLeguay Let me have a look.

@BenoitLeguay I can't reproduce the issue with `python -m transformers.onnx --model microsoft/swin-base-patch4-window12-384-in22k swin-bas-onnx/ --feature image-classification`. Is it always failing for you?

With:
```
transformers==4.24.0
torch==1.12.1+cu113
onnx==1.12.0
onnxruntime==1.12.0
```

Could you try with these versions? Or give more details on your setup / a dockerfile to reproduce?

I notice that the ONNX export gives a lot of warnings, so it could be the exported models can not handle certain dynamic cases. It is part of https://github.com/huggingface/optimum/issues/503 to have a better user experience with exported ONNX models and the case they support / dont' support. You can expect more work being put on the ONNX export in the Optimum lib (doc [here](https://huggingface.co/docs/optimum/main/en/exporters/onnx/usage_guides/export_a_model)), notably a stronger test suite for the exported models.

First, thanks a lot @fxmarty ! 
Indeed, on my new computer (not the one I used from the time I had this issue) it works with the libraries versions you specified. I'm currently not able to access my old computer but I'll share more information about my setup whenever I can. 
I'm looking forward to check optimum improvements, thanks for sharing !

Ok great! Don't hesitate to share if with your old laptop + `transformers==4.24.0` you can reproduce the issue. Otherwise it could be that it has been fixed in this version (maybe https://github.com/huggingface/transformers/pull/19475 )

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md) are likely to be ignored.

Hello, sorry for late response. 
As I returned my old laptop, I cannot reproduce the issue. 
Though, I was able to retrieve the set up that was causing this issue 🔴 :
`transformers == 4.23.1 / torch == 1.12.1 / onnx = 1.12.0` MacBookPro 2016, MacOS Monterrey 12.5. 
It's now working well on this set up 🟢 :
`transformers == 4.25.1 / torch == 1.12.1 / onnx = 1.13.0` MacBookPro 2021, MacOS Monterrey 12.5. 

Thank you for your time huggingface team :)