Repository: huggingface/optimum

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.


Discussion:

Resolving patch:
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 @@ def _is_package_available(pkg_name: str, return_version: bool = False) -> Union[
     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 @@ def _is_package_available(pkg_name: str, return_version: bool = False) -> Union[
 
 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_sentence_transformers_available():
 
 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 @@ def check_if_pytorch_greater(target_version: str, message: str):
     """
     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 @@ def check_if_pytorch_greater(target_version: str, message: str):
         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 @@ def check_if_transformers_greater(target_version: Union[str, packaging.version.V
     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 @@ def check_if_diffusers_greater(target_version: str) -> bool:
     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}"
         )


Test patch:
diff --git a/tests/exporters/onnx/test_onnx_config_loss.py b/tests/exporters/onnx/test_onnx_config_loss.py
--- a/tests/exporters/onnx/test_onnx_config_loss.py
+++ b/tests/exporters/onnx/test_onnx_config_loss.py
@@ -48,8 +48,9 @@ def test_onnx_config_with_loss(self):
         model_checkpoint = "hf-internal-testing/tiny-random-bert"
         models = {
             AutoModelForSequenceClassification.from_pretrained(model_checkpoint),
-            TFAutoModelForSequenceClassification.from_pretrained(model_checkpoint),
         }
+        if is_tf_available():
+            models.add(TFAutoModelForSequenceClassification.from_pretrained(model_checkpoint))
 
         for model in models:
             with self.subTest(model=model):