Skip to content

Commit 85614ed

Browse files
Update Python API stub files
1 parent 37156f2 commit 85614ed

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

src/bindings/python/src/openvino/tools/ovc/convert.pyi

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ from openvino.tools.ovc.logger import restore_logger_state
88
import openvino._ov_api
99
import pathlib as pathlib
1010
__all__: list[str] = ['Model', 'convert_model', 'get_all_cli_parser', 'get_logger_state', 'pathlib', 'restore_logger_state']
11-
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:
11+
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:
1212
"""
1313
1414
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
8383
then mmap is used to allocate weights directly from file. If input model is
8484
runtime object, then original memory regions allocated in the original model
8585
are reused for weights in the converted model.
86+
:param dynamo:
87+
Export a PyTorch torch.nn.Module using torch.export instead of
88+
torch.jit.trace. Requires example_input and PyTorch >= 2.6.
89+
Default is False.
90+
The resulting model uses static shapes derived from example_input by default.
91+
To enable dynamic dimensions, combine with the input parameter:
92+
dimensions set to -1 or Dimension(-1) become fully dynamic
93+
(torch.export.Dim.AUTO), and bounded dimensions such as Dimension(1, 10)
94+
are exported with explicit min/max constraints.
8695
8796
Returns:
8897
openvino.Model

src/bindings/python/src/openvino/tools/ovc/moc_frontend/pytorch_frontend_utils.pyi

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,35 @@ from __future__ import annotations
33
from openvino._pyopenvino import PartialShape
44
from openvino._pyopenvino import Tensor
55
from openvino.tools.ovc.cli_parser import InputCutInfo as _InputCutInfo
6+
from openvino.tools.ovc.cli_parser import input_to_input_cut_info
67
from openvino.tools.ovc.cli_parser import single_input_to_input_cut_info
78
from openvino.tools.ovc.error import Error
89
import logging as log
910
import numpy as np
1011
import pathlib as pathlib
1112
import sys as sys
12-
__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']
13+
__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']
14+
def _build_dynamic_shapes(inputs, input_specs = None):
15+
"""
16+
Build dynamic_shapes for torch.export.export.
17+
18+
If input_specs (list of _InputCutInfo from the 'input' parameter) is provided
19+
and contains shapes, dimensions marked as -1 (fully dynamic) get Dim.AUTO,
20+
dimensions with min/max constraints (e.g. Dimension(1, 10)) get
21+
Dim("dI_D", min=..., max=...), and fixed dimensions stay static.
22+
When no specs are given returns None so that torch.export.export produces
23+
a fully static graph.
24+
25+
The input_specs list is flat (one spec per leaf tensor), while inputs may
26+
contain nested tuples/lists (e.g. past_key_values). pytree is used to
27+
flatten inputs, pair each leaf with its spec, and then unflatten the
28+
result back into the original structure that torch.export expects.
29+
30+
"""
31+
def _export_torch_model(model, inputs, input_specs = None):
32+
"""
33+
Export a torch.nn.Module using torch.export.export with Dim.AUTO dynamic shapes.
34+
"""
1335
def extract_input_info_from_example(args, inputs):
1436
...
1537
def extract_module_extensions(args):

0 commit comments

Comments
 (0)