Skip to content
Open
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
11 changes: 10 additions & 1 deletion src/bindings/python/src/openvino/tools/ovc/convert.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ from openvino.tools.ovc.logger import restore_logger_state
import openvino._ov_api
import pathlib as pathlib
__all__: list[str] = ['Model', 'convert_model', 'get_all_cli_parser', 'get_logger_state', 'pathlib', 'restore_logger_state']
def convert_model(input_model: [str, pathlib.Path, typing.Any, list], input: [list, dict, str] = None, output: [str, list] = None, example_input: typing.Any = None, extension: [str, pathlib.Path, list, typing.Any] = None, verbose: bool = False, share_weights: bool = True) -> openvino._ov_api.Model:
def convert_model(input_model: [str, pathlib.Path, typing.Any, list], input: [list, dict, str] = None, output: [str, list] = None, example_input: typing.Any = None, extension: [str, pathlib.Path, list, typing.Any] = None, verbose: bool = False, share_weights: bool = True, dynamo: bool = False) -> openvino._ov_api.Model:
"""

Converts the model from original framework to OpenVino Model.
Expand Down Expand Up @@ -83,6 +83,15 @@ def convert_model(input_model: [str, pathlib.Path, typing.Any, list], input: [li
then mmap is used to allocate weights directly from file. If input model is
runtime object, then original memory regions allocated in the original model
are reused for weights in the converted model.
:param dynamo:
Export a PyTorch torch.nn.Module using torch.export instead of
torch.jit.trace. Requires example_input and PyTorch >= 2.6.
Default is False.
The resulting model uses static shapes derived from example_input by default.
To enable dynamic dimensions, combine with the input parameter:
dimensions set to -1 or Dimension(-1) become fully dynamic
(torch.export.Dim.AUTO), and bounded dimensions such as Dimension(1, 10)
are exported with explicit min/max constraints.

Returns:
openvino.Model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,35 @@ from __future__ import annotations
from openvino._pyopenvino import PartialShape
from openvino._pyopenvino import Tensor
from openvino.tools.ovc.cli_parser import InputCutInfo as _InputCutInfo
from openvino.tools.ovc.cli_parser import input_to_input_cut_info
from openvino.tools.ovc.cli_parser import single_input_to_input_cut_info
from openvino.tools.ovc.error import Error
import logging as log
import numpy as np
import pathlib as pathlib
import sys as sys
__all__: list[str] = ['Error', 'PartialShape', 'Tensor', 'extract_input_info_from_example', 'extract_module_extensions', 'flatten_inputs', 'get_pytorch_decoder', 'get_pytorch_decoder_for_model_on_disk', 'get_value_from_list_or_dict', 'log', 'np', 'pathlib', 'prepare_torch_inputs', 'single_input_to_input_cut_info', 'sys', 'to_torch_tensor', 'update_list_or_dict']
__all__: list[str] = ['Error', 'PartialShape', 'Tensor', 'extract_input_info_from_example', 'extract_module_extensions', 'flatten_inputs', 'get_pytorch_decoder', 'get_pytorch_decoder_for_model_on_disk', 'get_value_from_list_or_dict', 'input_to_input_cut_info', 'log', 'np', 'pathlib', 'prepare_torch_inputs', 'single_input_to_input_cut_info', 'sys', 'to_torch_tensor', 'update_list_or_dict']
def _build_dynamic_shapes(inputs, input_specs = None):
"""
Build dynamic_shapes for torch.export.export.

If input_specs (list of _InputCutInfo from the 'input' parameter) is provided
and contains shapes, dimensions marked as -1 (fully dynamic) get Dim.AUTO,
dimensions with min/max constraints (e.g. Dimension(1, 10)) get
Dim("dI_D", min=..., max=...), and fixed dimensions stay static.
When no specs are given returns None so that torch.export.export produces
a fully static graph.

The input_specs list is flat (one spec per leaf tensor), while inputs may
contain nested tuples/lists (e.g. past_key_values). pytree is used to
flatten inputs, pair each leaf with its spec, and then unflatten the
result back into the original structure that torch.export expects.

"""
def _export_torch_model(model, inputs, input_specs = None):
"""
Export a torch.nn.Module using torch.export.export with Dim.AUTO dynamic shapes.
"""
def extract_input_info_from_example(args, inputs):
...
def extract_module_extensions(args):
Expand Down
Loading