Skip to content

Commit

Permalink
Add warning for transformers>=4.38 and OpenVINO 2024.0 (#599)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
helena-intel authored Mar 12, 2024
1 parent 36459a1 commit d2d2d5d
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions optimum/exporters/openvino/model_patcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,24 @@
import logging as log

from optimum.intel.utils.import_utils import (
_openvino_version,
_torch_version,
_transformers_version,
is_openvino_version,
is_torch_version,
is_transformers_version,
)


def patch_model_with_bettertransformer(model):
COLOR_RED = "\033[1;31m"
COLOR_RESET = "\033[0m"

# check that the model has not yet been pathced
if hasattr(model, "use_bettertransformer") and model.use_bettertransformer is True:
return model

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

if (
getattr(model.config, "model_type") in {"gpt_bigcode", "llama"}
and is_transformers_version(">=", "4.38")
and is_openvino_version("<", "2024.1.0-14612")
):
# display commit-id only when a nightly/prerelease of OpenVINO is installed.
display_version = (
_openvino_version.split("-")[0] if is_openvino_version("<=", "2024.0.0-14509") else _openvino_version
)
log.warn(
COLOR_RED + f"[WARNING] Stateful models are not supported for Llama and GPTBigCode with Transformers "
f"{_transformers_version} and OpenVINO {display_version}. For good performance, consider using a nightly OpenVINO build: "
"https://docs.openvino.ai/2024/get-started/install-openvino.html. For models that do not need transformers "
"4.38+, it is also an option to downgrade transformers: `pip install transformers==4.37.2`" + COLOR_RESET
)

# model already has required SDPA implementation
if getattr(model, "_supports_sdpa", False) and getattr(model.config, "_attn_implementation", "eager") == "sdpa":
return model
Expand Down

0 comments on commit d2d2d5d

Please sign in to comment.