Skip to content

Commit d2d2d5d

Browse files
authored
Add warning for transformers>=4.38 and OpenVINO 2024.0 (#599)
* Add warning for transformers>=4.38 and OpenVINO 2024.0 * Use is_openvino_version to compare versions * Show version warning only for llama and gpt-bigcode * Fix style, show OpenVINO version * Include affected model types in warning message
1 parent 36459a1 commit d2d2d5d

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

optimum/exporters/openvino/model_patcher.py

+21-2
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,24 @@
1515
import logging as log
1616

1717
from optimum.intel.utils.import_utils import (
18+
_openvino_version,
1819
_torch_version,
1920
_transformers_version,
21+
is_openvino_version,
2022
is_torch_version,
2123
is_transformers_version,
2224
)
2325

2426

2527
def patch_model_with_bettertransformer(model):
28+
COLOR_RED = "\033[1;31m"
29+
COLOR_RESET = "\033[0m"
30+
2631
# check that the model has not yet been pathced
2732
if hasattr(model, "use_bettertransformer") and model.use_bettertransformer is True:
2833
return model
2934

3035
if is_transformers_version("<", "4.36") or is_torch_version("<", "2.1.1"):
31-
COLOR_RED = "\033[1;31m"
32-
COLOR_RESET = "\033[0m"
3336
log.warn(
3437
COLOR_RED
3538
+ "[WARNING] For good performance with stateful models, transformers>=4.36.2 and PyTorch>=2.1.1 are required. "
@@ -39,6 +42,22 @@ def patch_model_with_bettertransformer(model):
3942
+ COLOR_RESET
4043
)
4144

45+
if (
46+
getattr(model.config, "model_type") in {"gpt_bigcode", "llama"}
47+
and is_transformers_version(">=", "4.38")
48+
and is_openvino_version("<", "2024.1.0-14612")
49+
):
50+
# display commit-id only when a nightly/prerelease of OpenVINO is installed.
51+
display_version = (
52+
_openvino_version.split("-")[0] if is_openvino_version("<=", "2024.0.0-14509") else _openvino_version
53+
)
54+
log.warn(
55+
COLOR_RED + f"[WARNING] Stateful models are not supported for Llama and GPTBigCode with Transformers "
56+
f"{_transformers_version} and OpenVINO {display_version}. For good performance, consider using a nightly OpenVINO build: "
57+
"https://docs.openvino.ai/2024/get-started/install-openvino.html. For models that do not need transformers "
58+
"4.38+, it is also an option to downgrade transformers: `pip install transformers==4.37.2`" + COLOR_RESET
59+
)
60+
4261
# model already has required SDPA implementation
4362
if getattr(model, "_supports_sdpa", False) and getattr(model.config, "_attn_implementation", "eager") == "sdpa":
4463
return model

0 commit comments

Comments
 (0)