We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Whisper-v3 ValueError: Transformers now supports natively BetterTransformer optimizations
### System Info

```shell
Nvidia Docker Container 23.12


xFormers 0.0.24+6600003.d20240116
memory_efficient_attention.cutlassF:               available
memory_efficient_attention.cutlassB:               available
memory_efficient_attention.decoderF:               available
memory_efficient_attention.flshattF@v2.3.6:        available
memory_efficient_attention.flshattB@v2.3.6:        available
memory_efficient_attention.smallkF:                available
memory_efficient_attention.smallkB:                available
memory_efficient_attention.tritonflashattF:        unavailable
memory_efficient_attention.tritonflashattB:        unavailable
memory_efficient_attention.triton_splitKF:         available
indexing.scaled_index_addF:                        available
indexing.scaled_index_addB:                        available
indexing.index_select:                             available
swiglu.dual_gemm_silu:                             available
swiglu.gemm_fused_operand_sum:                     available
swiglu.fused.p.cpp:                                available
is_triton_available:                               True
pytorch.version:                                   2.2.0a0+81ea7a4
pytorch.cuda:                                      available
gpu.compute_capability:                            8.9
gpu.name:                                          NVIDIA GeForce RTX 4090
dcgm_profiler:                                     unavailable
build.info:                                        available
build.cuda_version:                                1203
build.python_version:                              3.10.12
build.torch_version:                               2.2.0a0+81ea7a4
build.env.TORCH_CUDA_ARCH_LIST:                    5.2 6.0 6.1 7.0 7.2 7.5 8.0 8.6 8.7 9.0+PTX
build.env.XFORMERS_BUILD_TYPE:                     None
build.env.XFORMERS_ENABLE_DEBUG_ASSERTIONS:        None
build.env.NVCC_FLAGS:                              None
build.env.XFORMERS_PACKAGE_FROM:                   None
build.nvcc_version:                                12.3.107
source.privacy:                                    open source
```


### Who can help?

_No response_

### 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 (minimal, reproducible, runnable)

use code:

https://huggingface.co/spaces/primeline/whisper-german/blob/main/app.py

```bash
python app.py 
Traceback (most recent call last):
  File "/app/app.py", line 23, in <module>
    model = model.to_bettertransformer()
  File "/usr/local/lib/python3.10/dist-packages/transformers/modeling_utils.py", line 4314, in to_bettertransformer
    return BetterTransformer.transform(self)
  File "/usr/lib/python3.10/contextlib.py", line 79, in inner
    return func(*args, **kwds)
  File "/usr/local/lib/python3.10/dist-packages/optimum/bettertransformer/transformation.py", line 211, in transform
    raise ValueError(
ValueError: Transformers now supports natively BetterTransformer optimizations (torch.nn.functional.scaled_dot_product_attention) for the model type whisper. Please upgrade to transformers>=4.36 and torch>=2.1.1 to use it. Details: https://huggingface.co/docs/transformers/perf_infer_gpu_one#flashattention-and-memory-efficient-attention-through-pytorchs-scaleddotproductattention
```

### Expected behavior

everything is ok.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `optimum/utils/import_utils.py`
Content:
```
1 # Copyright 2022 The HuggingFace Team. All rights reserved.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 """Import utilities."""
15 
16 import importlib.util
17 import inspect
18 import sys
19 from collections import OrderedDict
20 from contextlib import contextmanager
21 from typing import Tuple, Union
22 
23 import numpy as np
24 import packaging
25 from transformers.utils import is_torch_available
26 
27 
28 def _is_package_available(pkg_name: str, return_version: bool = False) -> Union[Tuple[bool, str], bool]:
29     # Check we're not importing a "pkg_name" directory somewhere but the actual library by trying to grab the version
30     package_exists = importlib.util.find_spec(pkg_name) is not None
31     package_version = "N/A"
32     if package_exists:
33         try:
34             package_version = importlib.metadata.version(pkg_name)
35             package_exists = True
36         except importlib.metadata.PackageNotFoundError:
37             package_exists = False
38     if return_version:
39         return package_exists, package_version
40     else:
41         return package_exists
42 
43 
44 # The package importlib_metadata is in a different place, depending on the python version.
45 if sys.version_info < (3, 8):
46     import importlib_metadata
47 else:
48     import importlib.metadata as importlib_metadata
49 
50 
51 TORCH_MINIMUM_VERSION = packaging.version.parse("1.11.0")
52 TRANSFORMERS_MINIMUM_VERSION = packaging.version.parse("4.25.0")
53 DIFFUSERS_MINIMUM_VERSION = packaging.version.parse("0.18.0")
54 AUTOGPTQ_MINIMUM_VERSION = packaging.version.parse("0.4.99")  # Allows 0.5.0.dev0
55 
56 
57 # This is the minimal required version to support some ONNX Runtime features
58 ORT_QUANTIZE_MINIMUM_VERSION = packaging.version.parse("1.4.0")
59 
60 
61 _onnx_available = _is_package_available("onnx")
62 
63 # importlib.metadata.version seem to not be robust with the ONNX Runtime extensions (`onnxruntime-gpu`, etc.)
64 _onnxruntime_available = importlib.util.find_spec("onnxruntime") is not None
65 
66 _pydantic_available = _is_package_available("pydantic")
67 _accelerate_available = _is_package_available("accelerate")
68 _diffusers_available = _is_package_available("diffusers")
69 _auto_gptq_available = _is_package_available("auto_gptq")
70 _timm_available = _is_package_available("timm")
71 _sentence_transformers_available = _is_package_available("sentence_transformers")
72 
73 torch_version = None
74 if is_torch_available():
75     torch_version = packaging.version.parse(importlib_metadata.version("torch"))
76 
77 _is_torch_onnx_support_available = is_torch_available() and (
78     TORCH_MINIMUM_VERSION.major,
79     TORCH_MINIMUM_VERSION.minor,
80 ) <= (
81     torch_version.major,
82     torch_version.minor,
83 )
84 
85 
86 _diffusers_version = None
87 if _diffusers_available:
88     try:
89         _diffusers_version = importlib_metadata.version("diffusers")
90     except importlib_metadata.PackageNotFoundError:
91         _diffusers_available = False
92 
93 
94 def is_torch_onnx_support_available():
95     return _is_torch_onnx_support_available
96 
97 
98 def is_onnx_available():
99     return _onnx_available
100 
101 
102 def is_onnxruntime_available():
103     try:
104         # Try to import the source file of onnxruntime - if you run the tests from `tests` the function gets
105         # confused since there a folder named `onnxruntime` in `tests`. Therefore, `_onnxruntime_available`
106         # will be set to `True` even if not installed.
107         mod = importlib.import_module("onnxruntime")
108         inspect.getsourcefile(mod)
109     except Exception:
110         return False
111     return _onnxruntime_available
112 
113 
114 def is_pydantic_available():
115     return _pydantic_available
116 
117 
118 def is_accelerate_available():
119     return _accelerate_available
120 
121 
122 def is_diffusers_available():
123     return _diffusers_available
124 
125 
126 def is_timm_available():
127     return _timm_available
128 
129 
130 def is_sentence_transformers_available():
131     return _sentence_transformers_available
132 
133 
134 def is_auto_gptq_available():
135     if _auto_gptq_available:
136         version_autogptq = packaging.version.parse(importlib_metadata.version("auto_gptq"))
137         if AUTOGPTQ_MINIMUM_VERSION < version_autogptq:
138             return True
139         else:
140             raise ImportError(
141                 f"Found an incompatible version of auto-gptq. Found version {version_autogptq}, but only version above {AUTOGPTQ_MINIMUM_VERSION} are supported"
142             )
143 
144 
145 @contextmanager
146 def check_if_pytorch_greater(target_version: str, message: str):
147     r"""
148     A context manager that does nothing except checking if the PyTorch version is greater than `pt_version`
149     """
150     import torch
151 
152     if not packaging.version.parse(torch.__version__) >= packaging.version.parse(target_version):
153         raise ImportError(
154             f"Found an incompatible version of PyTorch. Found version {torch.__version__}, but only {target_version} and above are supported. {message}"
155         )
156     try:
157         yield
158     finally:
159         pass
160 
161 
162 def check_if_transformers_greater(target_version: Union[str, packaging.version.Version]) -> bool:
163     """
164     Checks whether the current install of transformers is greater than or equal to the target version.
165 
166     Args:
167         target_version (`Union[str, packaging.version.Version]`): version used as the reference for comparison.
168 
169     Returns:
170         bool: whether the check is True or not.
171     """
172     import transformers
173 
174     if isinstance(target_version, str):
175         target_version = packaging.version.parse(target_version)
176 
177     return packaging.version.parse(transformers.__version__) >= target_version
178 
179 
180 def check_if_diffusers_greater(target_version: str) -> bool:
181     """
182     Checks whether the current install of diffusers is greater than or equal to the target version.
183 
184     Args:
185         target_version (str): version used as the reference for comparison.
186 
187     Returns:
188         bool: whether the check is True or not.
189     """
190     if not _diffusers_available:
191         return False
192 
193     return packaging.version.parse(_diffusers_version) >= packaging.version.parse(target_version)
194 
195 
196 @contextmanager
197 def require_numpy_strictly_lower(version: str, message: str):
198     if not packaging.version.parse(np.__version__) < packaging.version.parse(version):
199         raise ImportError(
200             f"Found an incompatible version of numpy. Found version {np.__version__}, but expected numpy<{version}. {message}"
201         )
202     try:
203         yield
204     finally:
205         pass
206 
207 
208 DIFFUSERS_IMPORT_ERROR = """
209 {0} requires the diffusers library but it was not found in your environment. You can install it with pip: `pip install
210 diffusers`. Please note that you may need to restart your runtime after installation.
211 """
212 
213 TRANSFORMERS_IMPORT_ERROR = """requires the transformers>={0} library but it was not found in your environment. You can install it with pip: `pip install
214 -U transformers`. Please note that you may need to restart your runtime after installation.
215 """
216 
217 BACKENDS_MAPPING = OrderedDict(
218     [
219         ("diffusers", (is_diffusers_available, DIFFUSERS_IMPORT_ERROR)),
220         (
221             "transformers_431",
222             (lambda: check_if_transformers_greater("4.31"), "{0} " + TRANSFORMERS_IMPORT_ERROR.format("4.31")),
223         ),
224         (
225             "transformers_432",
226             (lambda: check_if_transformers_greater("4.32"), "{0} " + TRANSFORMERS_IMPORT_ERROR.format("4.32")),
227         ),
228         (
229             "transformers_434",
230             (lambda: check_if_transformers_greater("4.34"), "{0} " + TRANSFORMERS_IMPORT_ERROR.format("4.34")),
231         ),
232     ]
233 )
234 
235 
236 def requires_backends(obj, backends):
237     if not isinstance(backends, (list, tuple)):
238         backends = [backends]
239 
240     name = obj.__name__ if hasattr(obj, "__name__") else obj.__class__.__name__
241     checks = (BACKENDS_MAPPING[backend] for backend in backends)
242     failed = [msg.format(name) for available, msg in checks if not available()]
243     if failed:
244         raise ImportError("".join(failed))
245 
246 
247 # Copied from: https://github.com/huggingface/transformers/blob/v4.26.0/src/transformers/utils/import_utils.py#L1041
248 class DummyObject(type):
249     """
250     Metaclass for the dummy objects. Any class inheriting from it will return the ImportError generated by
251     `requires_backend` each time a user tries to access any method of that class.
252     """
253 
254     def __getattr__(cls, key):
255         if key.startswith("_"):
256             return super().__getattr__(cls, key)
257         requires_backends(cls, cls._backends)
258
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/optimum/utils/import_utils.py b/optimum/utils/import_utils.py
--- a/optimum/utils/import_utils.py
+++ b/optimum/utils/import_utils.py
@@ -21,7 +21,7 @@
 from typing import Tuple, Union
 
 import numpy as np
-import packaging
+from packaging import version
 from transformers.utils import is_torch_available
 
 
@@ -48,14 +48,14 @@
     import importlib.metadata as importlib_metadata
 
 
-TORCH_MINIMUM_VERSION = packaging.version.parse("1.11.0")
-TRANSFORMERS_MINIMUM_VERSION = packaging.version.parse("4.25.0")
-DIFFUSERS_MINIMUM_VERSION = packaging.version.parse("0.18.0")
-AUTOGPTQ_MINIMUM_VERSION = packaging.version.parse("0.4.99")  # Allows 0.5.0.dev0
+TORCH_MINIMUM_VERSION = version.parse("1.11.0")
+TRANSFORMERS_MINIMUM_VERSION = version.parse("4.25.0")
+DIFFUSERS_MINIMUM_VERSION = version.parse("0.18.0")
+AUTOGPTQ_MINIMUM_VERSION = version.parse("0.4.99")  # Allows 0.5.0.dev0
 
 
 # This is the minimal required version to support some ONNX Runtime features
-ORT_QUANTIZE_MINIMUM_VERSION = packaging.version.parse("1.4.0")
+ORT_QUANTIZE_MINIMUM_VERSION = version.parse("1.4.0")
 
 
 _onnx_available = _is_package_available("onnx")
@@ -72,7 +72,7 @@
 
 torch_version = None
 if is_torch_available():
-    torch_version = packaging.version.parse(importlib_metadata.version("torch"))
+    torch_version = version.parse(importlib_metadata.version("torch"))
 
 _is_torch_onnx_support_available = is_torch_available() and (
     TORCH_MINIMUM_VERSION.major,
@@ -133,7 +133,7 @@
 
 def is_auto_gptq_available():
     if _auto_gptq_available:
-        version_autogptq = packaging.version.parse(importlib_metadata.version("auto_gptq"))
+        version_autogptq = version.parse(importlib_metadata.version("auto_gptq"))
         if AUTOGPTQ_MINIMUM_VERSION < version_autogptq:
             return True
         else:
@@ -149,7 +149,7 @@
     """
     import torch
 
-    if not packaging.version.parse(torch.__version__) >= packaging.version.parse(target_version):
+    if not version.parse(torch.__version__) >= version.parse(target_version):
         raise ImportError(
             f"Found an incompatible version of PyTorch. Found version {torch.__version__}, but only {target_version} and above are supported. {message}"
         )
@@ -159,7 +159,7 @@
         pass
 
 
-def check_if_transformers_greater(target_version: Union[str, packaging.version.Version]) -> bool:
+def check_if_transformers_greater(target_version: Union[str, version.Version]) -> bool:
     """
     Checks whether the current install of transformers is greater than or equal to the target version.
 
@@ -172,9 +172,9 @@
     import transformers
 
     if isinstance(target_version, str):
-        target_version = packaging.version.parse(target_version)
+        target_version = version.parse(target_version)
 
-    return packaging.version.parse(transformers.__version__) >= target_version
+    return version.parse(transformers.__version__) >= target_version
 
 
 def check_if_diffusers_greater(target_version: str) -> bool:
@@ -190,12 +190,12 @@
     if not _diffusers_available:
         return False
 
-    return packaging.version.parse(_diffusers_version) >= packaging.version.parse(target_version)
+    return version.parse(_diffusers_version) >= version.parse(target_version)
 
 
 @contextmanager
-def require_numpy_strictly_lower(version: str, message: str):
-    if not packaging.version.parse(np.__version__) < packaging.version.parse(version):
+def require_numpy_strictly_lower(package_version: str, message: str):
+    if not version.parse(np.__version__) < version.parse(package_version):
         raise ImportError(
             f"Found an incompatible version of numpy. Found version {np.__version__}, but expected numpy<{version}. {message}"
         )

{"golden_diff": "diff --git a/optimum/utils/import_utils.py b/optimum/utils/import_utils.py\n--- a/optimum/utils/import_utils.py\n+++ b/optimum/utils/import_utils.py\n@@ -21,7 +21,7 @@\n from typing import Tuple, Union\n \n import numpy as np\n-import packaging\n+from packaging import version\n from transformers.utils import is_torch_available\n \n \n@@ -48,14 +48,14 @@\n     import importlib.metadata as importlib_metadata\n \n \n-TORCH_MINIMUM_VERSION = packaging.version.parse(\"1.11.0\")\n-TRANSFORMERS_MINIMUM_VERSION = packaging.version.parse(\"4.25.0\")\n-DIFFUSERS_MINIMUM_VERSION = packaging.version.parse(\"0.18.0\")\n-AUTOGPTQ_MINIMUM_VERSION = packaging.version.parse(\"0.4.99\")  # Allows 0.5.0.dev0\n+TORCH_MINIMUM_VERSION = version.parse(\"1.11.0\")\n+TRANSFORMERS_MINIMUM_VERSION = version.parse(\"4.25.0\")\n+DIFFUSERS_MINIMUM_VERSION = version.parse(\"0.18.0\")\n+AUTOGPTQ_MINIMUM_VERSION = version.parse(\"0.4.99\")  # Allows 0.5.0.dev0\n \n \n # This is the minimal required version to support some ONNX Runtime features\n-ORT_QUANTIZE_MINIMUM_VERSION = packaging.version.parse(\"1.4.0\")\n+ORT_QUANTIZE_MINIMUM_VERSION = version.parse(\"1.4.0\")\n \n \n _onnx_available = _is_package_available(\"onnx\")\n@@ -72,7 +72,7 @@\n \n torch_version = None\n if is_torch_available():\n-    torch_version = packaging.version.parse(importlib_metadata.version(\"torch\"))\n+    torch_version = version.parse(importlib_metadata.version(\"torch\"))\n \n _is_torch_onnx_support_available = is_torch_available() and (\n     TORCH_MINIMUM_VERSION.major,\n@@ -133,7 +133,7 @@\n \n def is_auto_gptq_available():\n     if _auto_gptq_available:\n-        version_autogptq = packaging.version.parse(importlib_metadata.version(\"auto_gptq\"))\n+        version_autogptq = version.parse(importlib_metadata.version(\"auto_gptq\"))\n         if AUTOGPTQ_MINIMUM_VERSION < version_autogptq:\n             return True\n         else:\n@@ -149,7 +149,7 @@\n     \"\"\"\n     import torch\n \n-    if not packaging.version.parse(torch.__version__) >= packaging.version.parse(target_version):\n+    if not version.parse(torch.__version__) >= version.parse(target_version):\n         raise ImportError(\n             f\"Found an incompatible version of PyTorch. Found version {torch.__version__}, but only {target_version} and above are supported. {message}\"\n         )\n@@ -159,7 +159,7 @@\n         pass\n \n \n-def check_if_transformers_greater(target_version: Union[str, packaging.version.Version]) -> bool:\n+def check_if_transformers_greater(target_version: Union[str, version.Version]) -> bool:\n     \"\"\"\n     Checks whether the current install of transformers is greater than or equal to the target version.\n \n@@ -172,9 +172,9 @@\n     import transformers\n \n     if isinstance(target_version, str):\n-        target_version = packaging.version.parse(target_version)\n+        target_version = version.parse(target_version)\n \n-    return packaging.version.parse(transformers.__version__) >= target_version\n+    return version.parse(transformers.__version__) >= target_version\n \n \n def check_if_diffusers_greater(target_version: str) -> bool:\n@@ -190,12 +190,12 @@\n     if not _diffusers_available:\n         return False\n \n-    return packaging.version.parse(_diffusers_version) >= packaging.version.parse(target_version)\n+    return version.parse(_diffusers_version) >= version.parse(target_version)\n \n \n @contextmanager\n-def require_numpy_strictly_lower(version: str, message: str):\n-    if not packaging.version.parse(np.__version__) < packaging.version.parse(version):\n+def require_numpy_strictly_lower(package_version: str, message: str):\n+    if not version.parse(np.__version__) < version.parse(package_version):\n         raise ImportError(\n             f\"Found an incompatible version of numpy. Found version {np.__version__}, but expected numpy<{version}. {message}\"\n         )\n", "issue": "Whisper-v3 ValueError: Transformers now supports natively BetterTransformer optimizations\n### System Info\n\n```shell\nNvidia Docker Container 23.12\r\n\r\n\r\nxFormers 0.0.24+6600003.d20240116\r\nmemory_efficient_attention.cutlassF:               available\r\nmemory_efficient_attention.cutlassB:               available\r\nmemory_efficient_attention.decoderF:               available\r\nmemory_efficient_attention.flshattF@v2.3.6:        available\r\nmemory_efficient_attention.flshattB@v2.3.6:        available\r\nmemory_efficient_attention.smallkF:                available\r\nmemory_efficient_attention.smallkB:                available\r\nmemory_efficient_attention.tritonflashattF:        unavailable\r\nmemory_efficient_attention.tritonflashattB:        unavailable\r\nmemory_efficient_attention.triton_splitKF:         available\r\nindexing.scaled_index_addF:                        available\r\nindexing.scaled_index_addB:                        available\r\nindexing.index_select:                             available\r\nswiglu.dual_gemm_silu:                             available\r\nswiglu.gemm_fused_operand_sum:                     available\r\nswiglu.fused.p.cpp:                                available\r\nis_triton_available:                               True\r\npytorch.version:                                   2.2.0a0+81ea7a4\r\npytorch.cuda:                                      available\r\ngpu.compute_capability:                            8.9\r\ngpu.name:                                          NVIDIA GeForce RTX 4090\r\ndcgm_profiler:                                     unavailable\r\nbuild.info:                                        available\r\nbuild.cuda_version:                                1203\r\nbuild.python_version:                              3.10.12\r\nbuild.torch_version:                               2.2.0a0+81ea7a4\r\nbuild.env.TORCH_CUDA_ARCH_LIST:                    5.2 6.0 6.1 7.0 7.2 7.5 8.0 8.6 8.7 9.0+PTX\r\nbuild.env.XFORMERS_BUILD_TYPE:                     None\r\nbuild.env.XFORMERS_ENABLE_DEBUG_ASSERTIONS:        None\r\nbuild.env.NVCC_FLAGS:                              None\r\nbuild.env.XFORMERS_PACKAGE_FROM:                   None\r\nbuild.nvcc_version:                                12.3.107\r\nsource.privacy:                                    open source\n```\n\n\n### Who can help?\n\n_No response_\n\n### Information\n\n- [X] The official example scripts\n- [ ] My own modified scripts\n\n### Tasks\n\n- [X] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)\n- [ ] My own task or dataset (give details below)\n\n### Reproduction (minimal, reproducible, runnable)\n\nuse code:\r\n\r\nhttps://huggingface.co/spaces/primeline/whisper-german/blob/main/app.py\r\n\r\n```bash\r\npython app.py \r\nTraceback (most recent call last):\r\n  File \"/app/app.py\", line 23, in <module>\r\n    model = model.to_bettertransformer()\r\n  File \"/usr/local/lib/python3.10/dist-packages/transformers/modeling_utils.py\", line 4314, in to_bettertransformer\r\n    return BetterTransformer.transform(self)\r\n  File \"/usr/lib/python3.10/contextlib.py\", line 79, in inner\r\n    return func(*args, **kwds)\r\n  File \"/usr/local/lib/python3.10/dist-packages/optimum/bettertransformer/transformation.py\", line 211, in transform\r\n    raise ValueError(\r\nValueError: Transformers now supports natively BetterTransformer optimizations (torch.nn.functional.scaled_dot_product_attention) for the model type whisper. Please upgrade to transformers>=4.36 and torch>=2.1.1 to use it. Details: https://huggingface.co/docs/transformers/perf_infer_gpu_one#flashattention-and-memory-efficient-attention-through-pytorchs-scaleddotproductattention\r\n```\n\n### Expected behavior\n\neverything is ok.\n", "before_files": [{"content": "# Copyright 2022 The HuggingFace Team. All rights reserved.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\"\"\"Import utilities.\"\"\"\n\nimport importlib.util\nimport inspect\nimport sys\nfrom collections import OrderedDict\nfrom contextlib import contextmanager\nfrom typing import Tuple, Union\n\nimport numpy as np\nimport packaging\nfrom transformers.utils import is_torch_available\n\n\ndef _is_package_available(pkg_name: str, return_version: bool = False) -> Union[Tuple[bool, str], bool]:\n    # Check we're not importing a \"pkg_name\" directory somewhere but the actual library by trying to grab the version\n    package_exists = importlib.util.find_spec(pkg_name) is not None\n    package_version = \"N/A\"\n    if package_exists:\n        try:\n            package_version = importlib.metadata.version(pkg_name)\n            package_exists = True\n        except importlib.metadata.PackageNotFoundError:\n            package_exists = False\n    if return_version:\n        return package_exists, package_version\n    else:\n        return package_exists\n\n\n# The package importlib_metadata is in a different place, depending on the python version.\nif sys.version_info < (3, 8):\n    import importlib_metadata\nelse:\n    import importlib.metadata as importlib_metadata\n\n\nTORCH_MINIMUM_VERSION = packaging.version.parse(\"1.11.0\")\nTRANSFORMERS_MINIMUM_VERSION = packaging.version.parse(\"4.25.0\")\nDIFFUSERS_MINIMUM_VERSION = packaging.version.parse(\"0.18.0\")\nAUTOGPTQ_MINIMUM_VERSION = packaging.version.parse(\"0.4.99\")  # Allows 0.5.0.dev0\n\n\n# This is the minimal required version to support some ONNX Runtime features\nORT_QUANTIZE_MINIMUM_VERSION = packaging.version.parse(\"1.4.0\")\n\n\n_onnx_available = _is_package_available(\"onnx\")\n\n# importlib.metadata.version seem to not be robust with the ONNX Runtime extensions (`onnxruntime-gpu`, etc.)\n_onnxruntime_available = importlib.util.find_spec(\"onnxruntime\") is not None\n\n_pydantic_available = _is_package_available(\"pydantic\")\n_accelerate_available = _is_package_available(\"accelerate\")\n_diffusers_available = _is_package_available(\"diffusers\")\n_auto_gptq_available = _is_package_available(\"auto_gptq\")\n_timm_available = _is_package_available(\"timm\")\n_sentence_transformers_available = _is_package_available(\"sentence_transformers\")\n\ntorch_version = None\nif is_torch_available():\n    torch_version = packaging.version.parse(importlib_metadata.version(\"torch\"))\n\n_is_torch_onnx_support_available = is_torch_available() and (\n    TORCH_MINIMUM_VERSION.major,\n    TORCH_MINIMUM_VERSION.minor,\n) <= (\n    torch_version.major,\n    torch_version.minor,\n)\n\n\n_diffusers_version = None\nif _diffusers_available:\n    try:\n        _diffusers_version = importlib_metadata.version(\"diffusers\")\n    except importlib_metadata.PackageNotFoundError:\n        _diffusers_available = False\n\n\ndef is_torch_onnx_support_available():\n    return _is_torch_onnx_support_available\n\n\ndef is_onnx_available():\n    return _onnx_available\n\n\ndef is_onnxruntime_available():\n    try:\n        # Try to import the source file of onnxruntime - if you run the tests from `tests` the function gets\n        # confused since there a folder named `onnxruntime` in `tests`. Therefore, `_onnxruntime_available`\n        # will be set to `True` even if not installed.\n        mod = importlib.import_module(\"onnxruntime\")\n        inspect.getsourcefile(mod)\n    except Exception:\n        return False\n    return _onnxruntime_available\n\n\ndef is_pydantic_available():\n    return _pydantic_available\n\n\ndef is_accelerate_available():\n    return _accelerate_available\n\n\ndef is_diffusers_available():\n    return _diffusers_available\n\n\ndef is_timm_available():\n    return _timm_available\n\n\ndef is_sentence_transformers_available():\n    return _sentence_transformers_available\n\n\ndef is_auto_gptq_available():\n    if _auto_gptq_available:\n        version_autogptq = packaging.version.parse(importlib_metadata.version(\"auto_gptq\"))\n        if AUTOGPTQ_MINIMUM_VERSION < version_autogptq:\n            return True\n        else:\n            raise ImportError(\n                f\"Found an incompatible version of auto-gptq. Found version {version_autogptq}, but only version above {AUTOGPTQ_MINIMUM_VERSION} are supported\"\n            )\n\n\n@contextmanager\ndef check_if_pytorch_greater(target_version: str, message: str):\n    r\"\"\"\n    A context manager that does nothing except checking if the PyTorch version is greater than `pt_version`\n    \"\"\"\n    import torch\n\n    if not packaging.version.parse(torch.__version__) >= packaging.version.parse(target_version):\n        raise ImportError(\n            f\"Found an incompatible version of PyTorch. Found version {torch.__version__}, but only {target_version} and above are supported. {message}\"\n        )\n    try:\n        yield\n    finally:\n        pass\n\n\ndef check_if_transformers_greater(target_version: Union[str, packaging.version.Version]) -> bool:\n    \"\"\"\n    Checks whether the current install of transformers is greater than or equal to the target version.\n\n    Args:\n        target_version (`Union[str, packaging.version.Version]`): version used as the reference for comparison.\n\n    Returns:\n        bool: whether the check is True or not.\n    \"\"\"\n    import transformers\n\n    if isinstance(target_version, str):\n        target_version = packaging.version.parse(target_version)\n\n    return packaging.version.parse(transformers.__version__) >= target_version\n\n\ndef check_if_diffusers_greater(target_version: str) -> bool:\n    \"\"\"\n    Checks whether the current install of diffusers is greater than or equal to the target version.\n\n    Args:\n        target_version (str): version used as the reference for comparison.\n\n    Returns:\n        bool: whether the check is True or not.\n    \"\"\"\n    if not _diffusers_available:\n        return False\n\n    return packaging.version.parse(_diffusers_version) >= packaging.version.parse(target_version)\n\n\n@contextmanager\ndef require_numpy_strictly_lower(version: str, message: str):\n    if not packaging.version.parse(np.__version__) < packaging.version.parse(version):\n        raise ImportError(\n            f\"Found an incompatible version of numpy. Found version {np.__version__}, but expected numpy<{version}. {message}\"\n        )\n    try:\n        yield\n    finally:\n        pass\n\n\nDIFFUSERS_IMPORT_ERROR = \"\"\"\n{0} requires the diffusers library but it was not found in your environment. You can install it with pip: `pip install\ndiffusers`. Please note that you may need to restart your runtime after installation.\n\"\"\"\n\nTRANSFORMERS_IMPORT_ERROR = \"\"\"requires the transformers>={0} library but it was not found in your environment. You can install it with pip: `pip install\n-U transformers`. Please note that you may need to restart your runtime after installation.\n\"\"\"\n\nBACKENDS_MAPPING = OrderedDict(\n    [\n        (\"diffusers\", (is_diffusers_available, DIFFUSERS_IMPORT_ERROR)),\n        (\n            \"transformers_431\",\n            (lambda: check_if_transformers_greater(\"4.31\"), \"{0} \" + TRANSFORMERS_IMPORT_ERROR.format(\"4.31\")),\n        ),\n        (\n            \"transformers_432\",\n            (lambda: check_if_transformers_greater(\"4.32\"), \"{0} \" + TRANSFORMERS_IMPORT_ERROR.format(\"4.32\")),\n        ),\n        (\n            \"transformers_434\",\n            (lambda: check_if_transformers_greater(\"4.34\"), \"{0} \" + TRANSFORMERS_IMPORT_ERROR.format(\"4.34\")),\n        ),\n    ]\n)\n\n\ndef requires_backends(obj, backends):\n    if not isinstance(backends, (list, tuple)):\n        backends = [backends]\n\n    name = obj.__name__ if hasattr(obj, \"__name__\") else obj.__class__.__name__\n    checks = (BACKENDS_MAPPING[backend] for backend in backends)\n    failed = [msg.format(name) for available, msg in checks if not available()]\n    if failed:\n        raise ImportError(\"\".join(failed))\n\n\n# Copied from: https://github.com/huggingface/transformers/blob/v4.26.0/src/transformers/utils/import_utils.py#L1041\nclass DummyObject(type):\n    \"\"\"\n    Metaclass for the dummy objects. Any class inheriting from it will return the ImportError generated by\n    `requires_backend` each time a user tries to access any method of that class.\n    \"\"\"\n\n    def __getattr__(cls, key):\n        if key.startswith(\"_\"):\n            return super().__getattr__(cls, key)\n        requires_backends(cls, cls._backends)\n", "path": "optimum/utils/import_utils.py"}], "after_files": [{"content": "# Copyright 2022 The HuggingFace Team. All rights reserved.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\"\"\"Import utilities.\"\"\"\n\nimport importlib.util\nimport inspect\nimport sys\nfrom collections import OrderedDict\nfrom contextlib import contextmanager\nfrom typing import Tuple, Union\n\nimport numpy as np\nfrom packaging import version\nfrom transformers.utils import is_torch_available\n\n\ndef _is_package_available(pkg_name: str, return_version: bool = False) -> Union[Tuple[bool, str], bool]:\n    # Check we're not importing a \"pkg_name\" directory somewhere but the actual library by trying to grab the version\n    package_exists = importlib.util.find_spec(pkg_name) is not None\n    package_version = \"N/A\"\n    if package_exists:\n        try:\n            package_version = importlib.metadata.version(pkg_name)\n            package_exists = True\n        except importlib.metadata.PackageNotFoundError:\n            package_exists = False\n    if return_version:\n        return package_exists, package_version\n    else:\n        return package_exists\n\n\n# The package importlib_metadata is in a different place, depending on the python version.\nif sys.version_info < (3, 8):\n    import importlib_metadata\nelse:\n    import importlib.metadata as importlib_metadata\n\n\nTORCH_MINIMUM_VERSION = version.parse(\"1.11.0\")\nTRANSFORMERS_MINIMUM_VERSION = version.parse(\"4.25.0\")\nDIFFUSERS_MINIMUM_VERSION = version.parse(\"0.18.0\")\nAUTOGPTQ_MINIMUM_VERSION = version.parse(\"0.4.99\")  # Allows 0.5.0.dev0\n\n\n# This is the minimal required version to support some ONNX Runtime features\nORT_QUANTIZE_MINIMUM_VERSION = version.parse(\"1.4.0\")\n\n\n_onnx_available = _is_package_available(\"onnx\")\n\n# importlib.metadata.version seem to not be robust with the ONNX Runtime extensions (`onnxruntime-gpu`, etc.)\n_onnxruntime_available = importlib.util.find_spec(\"onnxruntime\") is not None\n\n_pydantic_available = _is_package_available(\"pydantic\")\n_accelerate_available = _is_package_available(\"accelerate\")\n_diffusers_available = _is_package_available(\"diffusers\")\n_auto_gptq_available = _is_package_available(\"auto_gptq\")\n_timm_available = _is_package_available(\"timm\")\n_sentence_transformers_available = _is_package_available(\"sentence_transformers\")\n\ntorch_version = None\nif is_torch_available():\n    torch_version = version.parse(importlib_metadata.version(\"torch\"))\n\n_is_torch_onnx_support_available = is_torch_available() and (\n    TORCH_MINIMUM_VERSION.major,\n    TORCH_MINIMUM_VERSION.minor,\n) <= (\n    torch_version.major,\n    torch_version.minor,\n)\n\n\n_diffusers_version = None\nif _diffusers_available:\n    try:\n        _diffusers_version = importlib_metadata.version(\"diffusers\")\n    except importlib_metadata.PackageNotFoundError:\n        _diffusers_available = False\n\n\ndef is_torch_onnx_support_available():\n    return _is_torch_onnx_support_available\n\n\ndef is_onnx_available():\n    return _onnx_available\n\n\ndef is_onnxruntime_available():\n    try:\n        # Try to import the source file of onnxruntime - if you run the tests from `tests` the function gets\n        # confused since there a folder named `onnxruntime` in `tests`. Therefore, `_onnxruntime_available`\n        # will be set to `True` even if not installed.\n        mod = importlib.import_module(\"onnxruntime\")\n        inspect.getsourcefile(mod)\n    except Exception:\n        return False\n    return _onnxruntime_available\n\n\ndef is_pydantic_available():\n    return _pydantic_available\n\n\ndef is_accelerate_available():\n    return _accelerate_available\n\n\ndef is_diffusers_available():\n    return _diffusers_available\n\n\ndef is_timm_available():\n    return _timm_available\n\n\ndef is_sentence_transformers_available():\n    return _sentence_transformers_available\n\n\ndef is_auto_gptq_available():\n    if _auto_gptq_available:\n        version_autogptq = version.parse(importlib_metadata.version(\"auto_gptq\"))\n        if AUTOGPTQ_MINIMUM_VERSION < version_autogptq:\n            return True\n        else:\n            raise ImportError(\n                f\"Found an incompatible version of auto-gptq. Found version {version_autogptq}, but only version above {AUTOGPTQ_MINIMUM_VERSION} are supported\"\n            )\n\n\n@contextmanager\ndef check_if_pytorch_greater(target_version: str, message: str):\n    r\"\"\"\n    A context manager that does nothing except checking if the PyTorch version is greater than `pt_version`\n    \"\"\"\n    import torch\n\n    if not version.parse(torch.__version__) >= version.parse(target_version):\n        raise ImportError(\n            f\"Found an incompatible version of PyTorch. Found version {torch.__version__}, but only {target_version} and above are supported. {message}\"\n        )\n    try:\n        yield\n    finally:\n        pass\n\n\ndef check_if_transformers_greater(target_version: Union[str, version.Version]) -> bool:\n    \"\"\"\n    Checks whether the current install of transformers is greater than or equal to the target version.\n\n    Args:\n        target_version (`Union[str, packaging.version.Version]`): version used as the reference for comparison.\n\n    Returns:\n        bool: whether the check is True or not.\n    \"\"\"\n    import transformers\n\n    if isinstance(target_version, str):\n        target_version = version.parse(target_version)\n\n    return version.parse(transformers.__version__) >= target_version\n\n\ndef check_if_diffusers_greater(target_version: str) -> bool:\n    \"\"\"\n    Checks whether the current install of diffusers is greater than or equal to the target version.\n\n    Args:\n        target_version (str): version used as the reference for comparison.\n\n    Returns:\n        bool: whether the check is True or not.\n    \"\"\"\n    if not _diffusers_available:\n        return False\n\n    return version.parse(_diffusers_version) >= version.parse(target_version)\n\n\n@contextmanager\ndef require_numpy_strictly_lower(package_version: str, message: str):\n    if not version.parse(np.__version__) < version.parse(package_version):\n        raise ImportError(\n            f\"Found an incompatible version of numpy. Found version {np.__version__}, but expected numpy<{version}. {message}\"\n        )\n    try:\n        yield\n    finally:\n        pass\n\n\nDIFFUSERS_IMPORT_ERROR = \"\"\"\n{0} requires the diffusers library but it was not found in your environment. You can install it with pip: `pip install\ndiffusers`. Please note that you may need to restart your runtime after installation.\n\"\"\"\n\nTRANSFORMERS_IMPORT_ERROR = \"\"\"requires the transformers>={0} library but it was not found in your environment. You can install it with pip: `pip install\n-U transformers`. Please note that you may need to restart your runtime after installation.\n\"\"\"\n\nBACKENDS_MAPPING = OrderedDict(\n    [\n        (\"diffusers\", (is_diffusers_available, DIFFUSERS_IMPORT_ERROR)),\n        (\n            \"transformers_431\",\n            (lambda: check_if_transformers_greater(\"4.31\"), \"{0} \" + TRANSFORMERS_IMPORT_ERROR.format(\"4.31\")),\n        ),\n        (\n            \"transformers_432\",\n            (lambda: check_if_transformers_greater(\"4.32\"), \"{0} \" + TRANSFORMERS_IMPORT_ERROR.format(\"4.32\")),\n        ),\n        (\n            \"transformers_434\",\n            (lambda: check_if_transformers_greater(\"4.34\"), \"{0} \" + TRANSFORMERS_IMPORT_ERROR.format(\"4.34\")),\n        ),\n    ]\n)\n\n\ndef requires_backends(obj, backends):\n    if not isinstance(backends, (list, tuple)):\n        backends = [backends]\n\n    name = obj.__name__ if hasattr(obj, \"__name__\") else obj.__class__.__name__\n    checks = (BACKENDS_MAPPING[backend] for backend in backends)\n    failed = [msg.format(name) for available, msg in checks if not available()]\n    if failed:\n        raise ImportError(\"\".join(failed))\n\n\n# Copied from: https://github.com/huggingface/transformers/blob/v4.26.0/src/transformers/utils/import_utils.py#L1041\nclass DummyObject(type):\n    \"\"\"\n    Metaclass for the dummy objects. Any class inheriting from it will return the ImportError generated by\n    `requires_backend` each time a user tries to access any method of that class.\n    \"\"\"\n\n    def __getattr__(cls, key):\n        if key.startswith(\"_\"):\n            return super().__getattr__(cls, key)\n        requires_backends(cls, cls._backends)\n", "path": "optimum/utils/import_utils.py"}]}