Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add warning for transformers>=4.38 and OpenVINO 2024.0 #599

Merged
merged 5 commits into from
Mar 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading