Skip to main content

Extensions Property

Overview

The extensions property allows OpenVINO GenAI pipelines to register custom operations for models that OpenVINO™ does not support out of the box. Use it when a model requires custom operations or when you want to provide operations through OpenVINO extension mechanisms.

Custom operations can be implemented in both C++ and Python. To define a custom operation class, refer to the Custom Operation Guide. You can also create a shared library that contains custom operations implemented in C++. Refer to Create library with extensions for more details on library creation.

You can pass extensions to pipeline constructors in both Python and C++.

Using the extensions Property

Accepted item types in the Python extensions list:

  • str, bytes, or pathlib.Path pointing to a compiled extension library
  • openvino.Extension objects such as ov.OpExtension(...)
  • Python custom operation classes, which are automatically wrapped as openvino.OpExtension(...)
from pathlib import Path

import openvino as ov
import openvino_genai as ov_genai

# Minimal custom operation stub for registration through ov.OpExtension.
# Replace the type info and implementation with the actual custom operation.
class CustomAdd(ov.Op):
class_type_info = ov.DiscreteTypeInfo("CustomAdd", "extension")

model_path = "path/to/model_with_custom_ops"

# Option 1: pass extension library paths
llm_pipe_path = ov_genai.LLMPipeline(
model_path,
"CPU",
extensions=[Path("/path/to/libopenvino_custom_extension.so")],
)

# Option 2: register a Python custom operation.
llm_pipe_obj = ov_genai.LLMPipeline(
model_path,
"CPU",
extensions=[ov.OpExtension(CustomAdd)],
)

# Generate with custom ops via extension library path registration
llm_pipe_path.generate("Generate story about", max_new_tokens=100)

# Generate with custom ops via extension object registration
llm_pipe_obj.generate("Generate story about", max_new_tokens=100)

Notes

  • Extensions are loaded into the underlying OpenVINO Core before the pipeline loads the model.
  • If you use Python custom ops, register them through ov.OpExtension(...) or pass the custom operation class directly where supported.