Skip to content

Commit

Permalink
Skip Tokenizers Tests If No Package Installed
Browse files Browse the repository at this point in the history
Check logs from tokneizers test
  • Loading branch information
apaniukov committed Jan 18, 2024
1 parent 2cf460d commit 57782d1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
10 changes: 7 additions & 3 deletions optimum/exporters/openvino/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,9 @@ def export_tokenizer(
try:
from openvino_tokenizers import convert_tokenizer
except ModuleNotFoundError:
logger.info("Run `pip install openvino-tokenizers` to get OpenVINO tokenizer/detokenizer models.")
logger.info(
"Run `pip install openvino-tokenizers[transformers]` to get OpenVINO tokenizer/detokenizer models."
)

if not isinstance(output, Path):
output = Path(output)
Expand All @@ -521,10 +523,12 @@ def export_tokenizer(
logger.warning("Detokenizer is not supported, convert tokenizer only.")
converted = convert_tokenizer(tokenizer, with_detokenizer=False)
except OVTypeError:
logger.warning(f"OpenVINO Tokenizer for {type(tokenizer).__name__} is not supported.")
logger.warning(f"OpenVINO Tokenizer export for {type(tokenizer).__name__} is not supported.")
return
except Exception as exception:
logger.warning(f"OpenVINO Tokenizer {type(tokenizer).__name__} is not supported. Exception: {exception}")
logger.warning(
f"OpenVINO Tokenizer export for {type(tokenizer).__name__} is not supported. Exception: {exception}"
)
return

if not isinstance(converted, tuple):
Expand Down
25 changes: 18 additions & 7 deletions tests/openvino/test_exporters_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@
from optimum.intel.openvino.utils import _HEAD_TO_AUTOMODELS


try:

OV_TOKENIZERS_NOT_AVAILABLE = False
except Exception:
OV_TOKENIZERS_NOT_AVAILABLE = True


class OVCLIExportTestCase(unittest.TestCase):
"""
Integration tests ensuring supported models are correctly exported.
Expand Down Expand Up @@ -117,18 +124,22 @@ def test_exporters_cli(self, task: str, model_type: str):
for arch in SUPPORTED_ARCHITECTURES
if not arch[0].endswith("-with-past") and not arch[1].endswith("-refiner")
)
@unittest.skipIf(OV_TOKENIZERS_NOT_AVAILABLE, reason="OpenVINO Tokenizers not available")
def test_exporters_cli_tokenizers(self, task: str, model_type: str):
with TemporaryDirectory() as tmpdir:
subprocess.run(
output = subprocess.check_output(
f"optimum-cli export openvino --model {MODEL_NAMES[model_type]} --task {task} {tmpdir}",
shell=True,
check=True,
)
stderr=subprocess.STDOUT,
).decode()
save_dir = Path(tmpdir)
self.assertEqual(
self.EXPECTED_NUMBER_OF_TOKENIZER_MODELS[model_type],
sum("tokenizer" in file for file in map(str, save_dir.rglob("*.xml"))),
)
number_of_tokenizers = sum("tokenizer" in file for file in map(str, save_dir.rglob("*.xml")))
self.assertEqual(self.EXPECTED_NUMBER_OF_TOKENIZER_MODELS[model_type], number_of_tokenizers)

if number_of_tokenizers == 1:
self.assertFalse("Detokenizer is not supported, convert tokenizer only." in output)
elif number_of_tokenizers == 0:
self.assertFalse("OpenVINO Tokenizer export for" in output and "is not supported." in output)

@parameterized.expand(SUPPORTED_ARCHITECTURES)
def test_exporters_cli_fp16(self, task: str, model_type: str):
Expand Down

0 comments on commit 57782d1

Please sign in to comment.