From 85614ed13828a6a5093d77df1d4049d0285d429a Mon Sep 17 00:00:00 2001 From: sys-openvino-ci Date: Fri, 13 Mar 2026 04:02:39 +0100 Subject: [PATCH] Update Python API stub files --- .../python/src/openvino/tools/ovc/convert.pyi | 11 ++++++++- .../moc_frontend/pytorch_frontend_utils.pyi | 24 ++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/bindings/python/src/openvino/tools/ovc/convert.pyi b/src/bindings/python/src/openvino/tools/ovc/convert.pyi index 97d86f809d3459..8f394793729afe 100644 --- a/src/bindings/python/src/openvino/tools/ovc/convert.pyi +++ b/src/bindings/python/src/openvino/tools/ovc/convert.pyi @@ -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. @@ -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 diff --git a/src/bindings/python/src/openvino/tools/ovc/moc_frontend/pytorch_frontend_utils.pyi b/src/bindings/python/src/openvino/tools/ovc/moc_frontend/pytorch_frontend_utils.pyi index 1802dbcb64dc07..a379895076f3b2 100644 --- a/src/bindings/python/src/openvino/tools/ovc/moc_frontend/pytorch_frontend_utils.pyi +++ b/src/bindings/python/src/openvino/tools/ovc/moc_frontend/pytorch_frontend_utils.pyi @@ -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):