Skip to content
Draft
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
58 changes: 58 additions & 0 deletions .github/workflows/test_openvino_hf.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: OpenVINO HF Exporter (experimental) - Test

on:
workflow_dispatch:
pull_request:
branches:
- main
paths:
- "optimum/exporters/openvino_hf/**"
- "optimum/commands/export/openvino.py"
- "tests/openvino/test_export_hf.py"
- ".github/workflows/test_openvino_hf.yml"

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

permissions:
contents: read

env:
UV_TORCH_BACKEND: cpu
UV_SYSTEM_PYTHON: true
TRANSFORMERS_IS_CI: true
HF_TOKEN: ${{ secrets.HF_HUB_READ_TOKEN }}

jobs:
build:
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: actions/checkout@v7.0.0

- name: Setup Python
uses: actions/setup-python@v6
with:
python-version: "3.10"

- name: Install dependencies
run: |
pip install --upgrade pip uv
uv pip install .[tests] pillow librosa openvino-genai openvino-tokenizers pytest-xdist

# The `openvino-hf` path relies on `transformers.exporters.OpenVINOExporter` (+ multi-token
# decode), which isn't in a release yet — pin Transformers to the branch here (not in setup.py,
# so the rest of optimum-intel's CI keeps using the released Transformers).
- name: Install Transformers (openvino-exporter branch)
run: |
uv pip install "git+https://github.com/huggingface/transformers.git@openvino-exporter"

- name: Login with fork PRs CI token
if: ${{ env.HF_TOKEN == '' }}
run: |
python tests/scripts/login_with_ci_token.py

- name: Test with Pytest
run: |
pytest tests/openvino/test_export_hf.py --durations=0 -v -n auto
47 changes: 47 additions & 0 deletions optimum/commands/export/openvino.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,3 +532,50 @@ def prepare_q_config(args):
"num_samples": args.num_samples,
"smooth_quant_alpha": args.smooth_quant_alpha,
}


class OVHfExportCommand(BaseOptimumCLICommand):
COMMAND = CommandInfo(
name="openvino-hf",
help="[Experimental] Export PyTorch models to OpenVINO IR via the Transformers (HF) exporter.",
)

@staticmethod
def parse_args(parser: "ArgumentParser"):
# Reuse the `openvino` argument surface so the two paths feel identical on the CLI; this
# experimental path only honors a subset (see `run` — no quantization yet).
result = parse_args_openvino(parser)
parser.add_argument(
"--subfolder",
type=str,
default="",
help="Subfolder within the model repo or path holding the model and processor files.",
)
return result

def run(self):
from ...exporters.openvino_hf import export_openvino_hf

if self.args.framework != "pt":
raise ValueError("`optimum-cli export openvino-hf` only supports `--framework pt`.")

# No quantization on this path yet — warn instead of silently ignoring compression options.
if self.args.weight_format not in (None, "fp16", "fp32") or self.args.quant_mode is not None:
logger.warning(
"`export openvino-hf` is experimental and does not support quantization yet; "
"`--weight-format`/`--quant-mode` are ignored (weights exported in %s).",
"fp32" if self.args.weight_format == "fp32" else "fp16",
)

# `export_openvino_hf` infers `auto` itself; just strip the `openvino`-style `-with-past` suffix.
task = "auto" if self.args.task == "auto" else self.args.task.replace("-with-past", "")

export_openvino_hf(
model_id=self.args.model,
output=self.args.output,
task=task,
stateful=not self.args.disable_stateful,
fp16=self.args.weight_format != "fp32",
trust_remote_code=self.args.trust_remote_code,
subfolder=self.args.subfolder,
)
3 changes: 2 additions & 1 deletion optimum/commands/register/register_openvino.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@

from optimum.commands.export.base import ExportCommand

from ..export.openvino import OVExportCommand
from ..export.openvino import OVExportCommand, OVHfExportCommand


REGISTER_COMMANDS = [
(OVExportCommand, ExportCommand),
(OVHfExportCommand, ExportCommand),
]
23 changes: 23 additions & 0 deletions optimum/exporters/openvino_hf/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2025 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Experimental OpenVINO export built directly on the Transformers (HF) exporter.

See :mod:`optimum.exporters.openvino_hf.export` for details. Exposed on the CLI as
``optimum-cli export openvino-hf``.
"""

from .export import export_openvino_hf


__all__ = ["export_openvino_hf"]
Loading
Loading