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

disable warning about tokenizers version for ov tokenizers >= 2024.5 #962

Merged
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion optimum/exporters/openvino/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@

logger = logging.getLogger(__name__)

# init core before import openvino tokenizers to prevent failed attempt loading extension
core = Core()


def infer_task(
task,
Expand Down Expand Up @@ -413,7 +416,6 @@ class StoreAttr(object):
del model
gc.collect()

core = Core()
for submodel_path in submodel_paths:
submodel_path = Path(output) / submodel_path
submodel = core.read_model(submodel_path)
Expand Down
5 changes: 3 additions & 2 deletions optimum/exporters/openvino/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
_torch_version,
_transformers_version,
compare_versions,
is_openvino_tokenizers_version,
is_tokenizers_version,
is_transformers_version,
)
Expand Down Expand Up @@ -734,9 +735,9 @@ def export_tokenizer(
except ModuleNotFoundError:
return

if is_tokenizers_version(">", "0.19"):
if is_tokenizers_version(">", "0.19") and is_openvino_tokenizers_version("<", "2024.5.0.0"):
logger.warning(
"Exporting tokenizers to OpenVINO is not supported for tokenizers version > 0.19. "
"Exporting tokenizers to OpenVINO is not supported for tokenizers version > 0.19 and openvino version <= 2024.4. "
"Please downgrade to tokenizers version <= 0.19 to export tokenizers to OpenVINO."
)

Expand Down
18 changes: 18 additions & 0 deletions optimum/intel/utils/import_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,24 @@ def is_openvino_version(operation: str, version: str):
return compare_versions(parse(_openvino_version), operation, version)


def is_openvino_tokenizers_version(operation: str, version: str):
if not is_openvino_available():
return False
if not is_openvino_tokenizers_available():
return False
import openvino_tokenizers

tokenizers_version = openvino_tokenizers.__version__

if tokenizers_version == "0.0.0.0":
try:
tokenizers_version = importlib_metadata.version("openvino_tokenizers") or tokenizers_version
except importlib_metadata.PackageNotFoundError:
pass

return compare_versions(parse(tokenizers_version), operation, version)


def is_diffusers_version(operation: str, version: str):
"""
Compare the current diffusers version to a given reference with an operation.
Expand Down
2 changes: 1 addition & 1 deletion tests/openvino/test_exporters_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def test_exporters_cli(self, task: str, model_type: str):
def test_exporters_cli_tokenizers(self, task: str, model_type: str):
with TemporaryDirectory() as tmpdir:
output = subprocess.check_output(
f"optimum-cli export openvino --model {MODEL_NAMES[model_type]} --task {task} {tmpdir}",
f"TRANSFORMERS_VERBOSITY=debug optimum-cli export openvino --model {MODEL_NAMES[model_type]} --task {task} {tmpdir}",
shell=True,
stderr=subprocess.STDOUT,
).decode()
Expand Down
Loading