Skip to content

Commit 83cb0cb

Browse files
committed
Add warning for transformers>=4.38 and OpenVINO 2024.0
1 parent e6ee88c commit 83cb0cb

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

optimum/exporters/openvino/model_patcher.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import logging as log
1616

1717
from optimum.intel.utils.import_utils import (
18+
_openvino_version,
1819
_torch_version,
1920
_transformers_version,
2021
is_torch_version,
@@ -23,13 +24,14 @@
2324

2425

2526
def patch_model_with_bettertransformer(model):
27+
COLOR_RED = "\033[1;31m"
28+
COLOR_RESET = "\033[0m"
29+
2630
# check that the model has not yet been pathced
2731
if hasattr(model, "use_bettertransformer") and model.use_bettertransformer is True:
2832
return model
2933

3034
if is_transformers_version("<", "4.36") or is_torch_version("<", "2.1.1"):
31-
COLOR_RED = "\033[1;31m"
32-
COLOR_RESET = "\033[0m"
3335
log.warn(
3436
COLOR_RED
3537
+ "[WARNING] For good performance with stateful models, transformers>=4.36.2 and PyTorch>=2.1.1 are required. "
@@ -39,6 +41,14 @@ def patch_model_with_bettertransformer(model):
3941
+ COLOR_RESET
4042
)
4143

44+
if is_transformers_version(">=", "4.38") and _openvino_version < "2024.1.0-14612":
45+
log.warn(
46+
COLOR_RED + f"[WARNING] Stateful models are not supported with Transformers {_transformers_version} and "
47+
"this OpenVINO version. For good performance, consider using a nightly OpenVINO build: "
48+
"https://docs.openvino.ai/2024/get-started/install-openvino.html. For models that do not need transformers "
49+
"4.38+, it is also an option to downgrade transformers: `pip install transformers==4.37.2`" + COLOR_RESET
50+
)
51+
4252
# model already has required SDPA implementation
4353
if getattr(model, "_supports_sdpa", False) and getattr(model.config, "_attn_implementation", "eager") == "sdpa":
4454
return model

0 commit comments

Comments
 (0)