Skip to content

Commit eadb210

Browse files
committed
Update OV Tokenizers Availability Check
1 parent ffcae81 commit eadb210

File tree

3 files changed

+35
-19
lines changed

3 files changed

+35
-19
lines changed

optimum/commands/export/openvino.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def parse_args_openvino(parser: "ArgumentParser"):
123123
optional_group.add_argument(
124124
"--convert-tokenizer",
125125
action="store_true",
126-
help="[Deprecated] Add converted tokenizer and detokenizer with OpenVINO Tokenizers.",
126+
help="[Deprecated] Add converted tokenizer and detokenizer with OpenVINO Tokenizers.",
127127
)
128128

129129

optimum/exporters/openvino/__main__.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,6 @@ def main_export(
192192
f"The task could not be automatically inferred as this is available only for models hosted on the Hugging Face Hub. Please provide the argument --task with the relevant task from {', '.join(TasksManager.get_all_tasks())}. Detailed error: {e}"
193193
)
194194

195-
if convert_tokenizer and not is_openvino_tokenizers_available():
196-
logger.warning(
197-
"`convert_tokenizer` requires openvino-tokenizers, please install it with `pip install optimum-intel[openvino-tokenizers]`"
198-
)
199-
convert_tokenizer = False
200-
201195
do_gptq_patching = False
202196
custom_architecture = False
203197
loading_kwargs = {}

optimum/intel/utils/import_utils.py

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,21 +94,43 @@
9494
_openvino_tokenizers_available = False
9595

9696
if _openvino_tokenizers_available and _openvino_tokenizers_version != "N/A":
97-
_compatible_openvino_version = next(
98-
(
99-
requirement.split("==")[-1]
100-
for requirement in importlib_metadata.requires("openvino-tokenizers")
101-
if requirement.startswith("openvino==")
102-
),
103-
"",
104-
)
105-
_openvino_tokenizers_available = _compatible_openvino_version == ov_major_version
97+
_is_ovt_dev_version = "dev" in _openvino_tokenizers_version
98+
_ov_version = importlib_metadata.version("openvino")
99+
_is_ov_dev_version = "dev" in _ov_version
100+
if _is_ovt_dev_version:
101+
_compatible_openvino_major_version, _, _dev_date = _openvino_tokenizers_version.rsplit(".", 2)
102+
_compatible_ov_version = _compatible_openvino_major_version + "." + _dev_date
103+
_compatible_ovt_version = _ov_version.replace("dev", "0.dev")
104+
else:
105+
_compatible_ov_version = _openvino_tokenizers_version.rsplit(".", 1)[0]
106+
_compatible_ovt_version = _ov_version + ".0"
107+
108+
_openvino_tokenizers_available = _ov_version == _compatible_ov_version
109+
106110
if not _openvino_tokenizers_available:
111+
_update_ov_command = (
112+
f"pip install {'--pre' if _is_ovt_dev_version else ''} -U openvino=={_compatible_ov_version} "
113+
+ (
114+
"--extra-index-url https://storage.openvinotoolkit.org/simple/wheels/nightly"
115+
if _is_ovt_dev_version
116+
else ""
117+
)
118+
).strip()
119+
_update_ovt_command = (
120+
f"pip install {'--pre' if _is_ov_dev_version else ''} -U openvino-tokenizers=={_compatible_ovt_version} "
121+
+ (
122+
"--extra-index-url https://storage.openvinotoolkit.org/simple/wheels/nightly"
123+
if _is_ov_dev_version
124+
else ""
125+
)
126+
).strip()
107127
logger.warning(
108128
"OpenVINO Tokenizer version is not compatible with OpenVINO version. "
109-
f"Installed OpenVINO version: {ov_major_version},"
110-
f"OpenVINO Tokenizers requires {_compatible_openvino_version}. "
111-
f"OpenVINO Tokenizers models will not be added during export."
129+
f"Installed OpenVINO version: {_ov_version}, "
130+
f"OpenVINO Tokenizers requires {_compatible_ov_version}. "
131+
"OpenVINO Tokenizers models will not be added during export. "
132+
f"Update OpenVINO with \n{_update_ov_command}\n"
133+
f"Or update OpenVINO Tokenizers with \n{_update_ovt_command}"
112134
)
113135

114136
_nncf_available = importlib.util.find_spec("nncf") is not None

0 commit comments

Comments
 (0)