Skip to content

Commit

Permalink
add helper for export models via optimum cli (#2471)
Browse files Browse the repository at this point in the history
  • Loading branch information
eaidova authored Oct 24, 2024
1 parent bf0f533 commit ae963a7
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions utils/cmd_helper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import subprocess # nosec - disable B404:import-subprocess check
import sys
from pathlib import Path
from typing import Dict
import platform


def clone_repo(repo_url: str, revision: str = None, add_to_sys_path: bool = True) -> Path:
Expand All @@ -19,3 +21,20 @@ def clone_repo(repo_url: str, revision: str = None, add_to_sys_path: bool = True
sys.path.insert(0, str(repo_path))

return repo_path


def optimum_cli(model_id, output_dir, show_command=True, additionl_args: Dict[str, str] = None):
export_command = f"optimum-cli export openvino --model {model_id} {output_dir}"
if additionl_args is not None:
for arg, value in additionl_args.items():
export_command += f" --{arg}"
if value:
export_command += f" {value}"

if show_command:
from IPython.display import Markdown, display

display(Markdown("**Export command:**"))
display(Markdown(f"`{export_command}`"))

subprocess.run(export_command.split(" "), shell=(platform.system() == "Windows"), check=True)

0 comments on commit ae963a7

Please sign in to comment.