Skip to content

Commit

Permalink
Fix compatibility causallm models export with optimum 1.15 (#487)
Browse files Browse the repository at this point in the history
  • Loading branch information
eaidova authored Dec 11, 2023
1 parent f32d501 commit 5dac93d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 5 additions & 3 deletions optimum/exporters/openvino/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from optimum.exporters.onnx.model_patcher import DecoderModelPatcher
from optimum.utils import is_diffusers_available

from ...intel.utils.import_utils import is_nncf_available
from ...intel.utils.import_utils import is_nncf_available, is_optimum_version
from .utils import (
OV_XML_FILE_NAME,
clear_class_registry,
Expand Down Expand Up @@ -307,8 +307,10 @@ def export_pytorch(
# model.config.torchscript = True can not be used for patching, because it overrides return_dict to Flase
if custom_patcher or dict_inputs:
patcher = config.patch_model_for_export(model, model_kwargs=model_kwargs)
# DecoderModelPatcher does not override model forward
if isinstance(patcher, DecoderModelPatcher) or patcher.orig_forward_name != "forward":
# DecoderModelPatcher does not override model forward in optimum < 1.15
if (
isinstance(patcher, DecoderModelPatcher) and is_optimum_version("<", "1.15.0")
) or patcher.orig_forward_name != "forward":
patch_model_forward = True
patched_forward = model.forward
else:
Expand Down
5 changes: 5 additions & 0 deletions optimum/intel/utils/import_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

STR_OPERATION_TO_FUNC = {">": op.gt, ">=": op.ge, "==": op.eq, "!=": op.ne, "<=": op.le, "<": op.lt}

_optimum_version = importlib_metadata.version("optimum")

_transformers_available = importlib.util.find_spec("transformers") is not None
_transformers_version = "N/A"
Expand Down Expand Up @@ -175,6 +176,10 @@ def is_transformers_version(operation: str, version: str):
return compare_versions(parse(_transformers_version), operation, version)


def is_optimum_version(operation: str, version: str):
return compare_versions(parse(_optimum_version), operation, version)


def is_neural_compressor_version(operation: str, version: str):
"""
Compare the current Neural Compressor version to a given reference with an operation.
Expand Down

0 comments on commit 5dac93d

Please sign in to comment.