SAM 2.1 Hiera Small Intel® OpenVINO AITK Recipe#456
SAM 2.1 Hiera Small Intel® OpenVINO AITK Recipe#456Anirudh-Swaminathan wants to merge 8 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR adds an Intel® OpenVINO-based Olive workflow for optimizing and running SAM 2.1 Hiera Small (vision encoder + mask decoder), plus utilities and docs updates to support OpenVINO/WinML execution provider registration and inference samples.
Changes:
- Add SAM 2.1 OpenVINO Olive workflows (configs + Python scripts) including calibration data preparation and ONNX encapsulated OVIR generation.
- Add OpenVINO/WinML EP registration helper and inference utilities + notebooks for running OVIR models in ONNX Runtime.
- Update repository documentation/config indices to surface the new OpenVINO recipes and runtime support.
Reviewed changes
Copilot reviewed 33 out of 34 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| sd-legacy-stable-diffusion-v1-5/aitk/sd_utils/ov.py | Adds a helper to register ORT execution providers via a WinML worker script. |
| sam2.1-hiera-small/aitk/sam2_ov_workflow.py | Adds a one-shot script to run data prep + both Olive workflows. |
| sam2.1-hiera-small/aitk/sam2_ov_workflow.json.config | Adds AITK template metadata for the OpenVINO conversion workflow. |
| sam2.1-hiera-small/aitk/sam2_ov_workflow.json | Adds Olive workflow wrapper config that runs the AitkPython script. |
| sam2.1-hiera-small/aitk/sam21_vision_encoder_ov.json | Adds OpenVINO conversion + quantization + encapsulation recipe for the vision encoder. |
| sam2.1-hiera-small/aitk/sam21_mask_decoder_ov.json | Adds OpenVINO conversion + quantization + encapsulation recipe for the mask decoder. |
| sam2.1-hiera-small/aitk/prep_ov_quant_data.py | Adds COCO128 download/extract and decoder input generation for calibration. |
| sam2.1-hiera-small/aitk/ov_model_utils.py | Adds PyTorch wrapper modules + example inputs for exporting/quantizing SAM2.1 submodels. |
| sam2.1-hiera-small/aitk/ov_inference_utils.py | Adds ORT inference utilities for prompted segmentation using encoder+decoder OVIR models. |
| sam2.1-hiera-small/aitk/ov_encoder_quant.py | Adds Olive dataset + transform for encoder calibration. |
| sam2.1-hiera-small/aitk/ov_decoder_quant.py | Adds Olive dataset + transform for decoder calibration. |
| sam2.1-hiera-small/aitk/model_project.config | Registers the new OpenVINO workflow template in the project. |
| sam2.1-hiera-small/aitk/info.yml | Exposes an OpenVINO recipe entry and marks status as Ready. |
| sam2.1-hiera-small/aitk/inference_sample.ipynb | Updates the inference notebook to support both QNN and OpenVINO paths. |
| sam2.1-hiera-small/aitk/README.md | Documents OpenVINO quantization + inference environment setup and usage. |
| sam2.1-hiera-small/aitk/.gitignore | Ignores the downloaded sample image. |
| sam2.1-hiera-small/OpenVINO/winml.py | Adds WinML-based EP discovery and ORT provider library registration. |
| sam2.1-hiera-small/OpenVINO/sam2_ov_workflow.py | Adds OpenVINO-specific wrapper script for data prep + Olive runs. |
| sam2.1-hiera-small/OpenVINO/sam21_vision_encoder_ov.json | Adds OpenVINO recipe for vision encoder in the OpenVINO subfolder. |
| sam2.1-hiera-small/OpenVINO/sam21_mask_decoder_ov.json | Adds OpenVINO recipe for mask decoder in the OpenVINO subfolder. |
| sam2.1-hiera-small/OpenVINO/prep_ov_quant_data.py | Adds COCO128 data prep (OpenVINO folder variant). |
| sam2.1-hiera-small/OpenVINO/ov_model_utils.py | Adds model wrappers (OpenVINO folder variant). |
| sam2.1-hiera-small/OpenVINO/ov_inference_utils.py | Adds inference utilities (OpenVINO folder variant). |
| sam2.1-hiera-small/OpenVINO/ov_encoder_quant.py | Adds encoder calibration dataset/transform (OpenVINO folder variant). |
| sam2.1-hiera-small/OpenVINO/ov_decoder_quant.py | Adds decoder calibration dataset/transform (OpenVINO folder variant). |
| sam2.1-hiera-small/OpenVINO/info.yml | Adds OpenVINO recipe metadata for the OpenVINO folder. |
| sam2.1-hiera-small/OpenVINO/inference_sample.ipynb | Adds an OpenVINO-only inference notebook. |
| sam2.1-hiera-small/OpenVINO/README.md | Documents how to run OpenVINO quantization + inference in the OpenVINO folder. |
| sam2.1-hiera-small/OpenVINO/.gitignore | Ignores sample image and COCO artifacts in the OpenVINO folder. |
| README.md | Updates top-level model/recipe listings to include the new SAM2.1 OpenVINO path(s). |
| .aitk/requirements/requirements-IntelNPU-SAM.txt | Adds dependencies used for SAM2.1 OpenVINO/SAM tooling. |
| .aitk/docs/guide/ModelList.md | Adds Intel CPU/GPU/NPU options for SAM2.1 Hiera Small. |
| .aitk/configs/model_list.json | Adds Intel runtime tags for the SAM2.1 Hiera Small model entry. |
| .aitk/configs/checks.json | Updates check counters to reflect added configs/files. |
Comments suppressed due to low confidence (2)
sd-legacy-stable-diffusion-v1-5/aitk/sd_utils/ov.py:1
register_execution_providers()usesos.path.abspath(...)butosis not imported in the shown module imports, which will raiseNameErrorat runtime. Add animport os(module-level or inside the function) consistent with the file’s import style.
sam2.1-hiera-small/aitk/sam2_ov_workflow.py:1- There appear to be two parallel copies of the OpenVINO workflow implementation (under
sam2.1-hiera-small/aitk/andsam2.1-hiera-small/OpenVINO/) with extremely similar scripts/configs. This duplication increases the risk of drift and inconsistent bug fixes. If both entry points are required, consider consolidating the shared implementation into one module and having the other location import/call into it, or generate one set from the other during packaging.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
0f579c0 to
bebd5c4
Compare
This commit contains the SAM 2.1 Hiera Small Intel® OpenVINO AITK Recipe for generating ONNX Encapsulated OVIR models --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Autogen README with latest main. Autogen checks.json Autoformat ov.py in sd-legacy-stable-diffusion-v1.5\aitk
winml.py already provides register_execution_providers() function. Removing redefinition from OVStableDiffusionPipeline
bebd5c4 to
bfae07b
Compare
…book Restore original inference_sample.ipynb that contains only QNN sample. Update checks.json and sam2_ov_workflow.json for consistency.
Also remove debug print statement for prediction mask shape in inference sample notebooks for both AITK and OpenVINO folders
| @@ -0,0 +1,70 @@ | |||
| { | |||
| "$schema": "https://github.com/microsoft/olive-recipes/raw/refs/heads/main/.aitk/configs/config_schema.json", | |||
| "name": "Convert to Intel OpenVINO", | |||
There was a problem hiding this comment.
Please follow others using Convert to Intel CPU/NPU/GPU
| "outputs": [], | ||
| "source": [ | ||
| "from winml import register_execution_providers\n", | ||
| "register_execution_providers()" |
There was a problem hiding this comment.
Please define ExecutionProvider earlier to pass it into this
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "from ov_inference_utils import FacebookSam2_1HieraSmall, IPromptedImageSegmentationModel\n", |
There was a problem hiding this comment.
Add
import sys
NOTEBOOK_DIR = Path(__file__).parent if "__file__" in globals() else Path.cwd()
PROJECT_ROOT = NOTEBOOK_DIR.parents[1]
sys.path.insert(0, str(PROJECT_ROOT))
since the inference_sample will be copied into history folder to run
| def main(): | ||
| # define script and config file paths | ||
| data_prep_script = "prep_ov_quant_data.py" | ||
| vision_encoder_config = "sam21_vision_encoder_ov.json" |
There was a problem hiding this comment.
please follow
to- copy config into history folder
- update cache_dir to a shared cache folder
- update output_dir to save model into history folder
There was a problem hiding this comment.
To keep it workable from Readme, you could check if the arguments exist or not
Update dataset paths to use quantization_dataset directory inside OpenVINO folder
Also fix local imports in history folder by exposing project root containing support scripts to sys.path Refactor inference sample notebooks to consolidate model path definitions and execution provider setup
Enhance SAM 2.1 workflow: add argument parsing, config loading, and history folder management
This commit contains the SAM 2.1 Hiera Small Intel® OpenVINO AITK Recipe for generating ONNX Encapsulated OVIR models