bigdl-core-npu 2.6.0b20250114__cp310-cp310-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- bigdl-core-npu/__init__.py +0 -0
- bigdl-core-npu/include/common.h +96 -0
- bigdl-core-npu/include/npu_llm.h +74 -0
- bigdl-core-npu/npu_llm.dll +0 -0
- bigdl-core-npu/npu_llm.lib +0 -0
- bigdl_core_npu-2.6.0b20250114.dist-info/METADATA +44 -0
- bigdl_core_npu-2.6.0b20250114.dist-info/RECORD +234 -0
- bigdl_core_npu-2.6.0b20250114.dist-info/WHEEL +5 -0
- bigdl_core_npu-2.6.0b20250114.dist-info/top_level.txt +2 -0
- intel_npu_acceleration_library/__init__.py +24 -0
- intel_npu_acceleration_library/_version.py +6 -0
- intel_npu_acceleration_library/backend/__init__.py +37 -0
- intel_npu_acceleration_library/backend/base.py +250 -0
- intel_npu_acceleration_library/backend/bindings.py +383 -0
- intel_npu_acceleration_library/backend/compression.py +24 -0
- intel_npu_acceleration_library/backend/convolution.py +58 -0
- intel_npu_acceleration_library/backend/factory.py +1161 -0
- intel_npu_acceleration_library/backend/linear.py +60 -0
- intel_npu_acceleration_library/backend/matmul.py +59 -0
- intel_npu_acceleration_library/backend/mlp.py +58 -0
- intel_npu_acceleration_library/backend/ops.py +142 -0
- intel_npu_acceleration_library/backend/qlinear.py +75 -0
- intel_npu_acceleration_library/backend/qmatmul.py +66 -0
- intel_npu_acceleration_library/backend/runtime.py +215 -0
- intel_npu_acceleration_library/backend/sdpa.py +107 -0
- intel_npu_acceleration_library/backend/tensor.py +1120 -0
- intel_npu_acceleration_library/backend/utils.py +70 -0
- intel_npu_acceleration_library/compiler.py +194 -0
- intel_npu_acceleration_library/device.py +230 -0
- intel_npu_acceleration_library/dtypes.py +155 -0
- intel_npu_acceleration_library/external/openvino/__init__.py +72 -0
- intel_npu_acceleration_library/external/openvino/_offline_transformations/__init__.py +21 -0
- intel_npu_acceleration_library/external/openvino/_pyopenvino.cp310-win_amd64.pyd +0 -0
- intel_npu_acceleration_library/external/openvino/_pyopenvino.cp311-win_amd64.pyd +0 -0
- intel_npu_acceleration_library/external/openvino/_pyopenvino.cp312-win_amd64.pyd +0 -0
- intel_npu_acceleration_library/external/openvino/_pyopenvino.cp38-win_amd64.pyd +0 -0
- intel_npu_acceleration_library/external/openvino/_pyopenvino.cp39-win_amd64.pyd +0 -0
- intel_npu_acceleration_library/external/openvino/experimental/__init__.py +14 -0
- intel_npu_acceleration_library/external/openvino/frontend/__init__.py +34 -0
- intel_npu_acceleration_library/external/openvino/frontend/frontend.py +44 -0
- intel_npu_acceleration_library/external/openvino/frontend/jax/__init__.py +15 -0
- intel_npu_acceleration_library/external/openvino/frontend/jax/jaxpr_decoder.py +293 -0
- intel_npu_acceleration_library/external/openvino/frontend/jax/passes.py +65 -0
- intel_npu_acceleration_library/external/openvino/frontend/jax/utils.py +182 -0
- intel_npu_acceleration_library/external/openvino/frontend/onnx/__init__.py +15 -0
- intel_npu_acceleration_library/external/openvino/frontend/onnx/py_onnx_frontend.cp310-win_amd64.pyd +0 -0
- intel_npu_acceleration_library/external/openvino/frontend/onnx/py_onnx_frontend.cp311-win_amd64.pyd +0 -0
- intel_npu_acceleration_library/external/openvino/frontend/onnx/py_onnx_frontend.cp312-win_amd64.pyd +0 -0
- intel_npu_acceleration_library/external/openvino/frontend/onnx/py_onnx_frontend.cp38-win_amd64.pyd +0 -0
- intel_npu_acceleration_library/external/openvino/frontend/onnx/py_onnx_frontend.cp39-win_amd64.pyd +0 -0
- intel_npu_acceleration_library/external/openvino/frontend/paddle/__init__.py +15 -0
- intel_npu_acceleration_library/external/openvino/frontend/paddle/py_paddle_frontend.cp310-win_amd64.pyd +0 -0
- intel_npu_acceleration_library/external/openvino/frontend/paddle/py_paddle_frontend.cp311-win_amd64.pyd +0 -0
- intel_npu_acceleration_library/external/openvino/frontend/paddle/py_paddle_frontend.cp312-win_amd64.pyd +0 -0
- intel_npu_acceleration_library/external/openvino/frontend/paddle/py_paddle_frontend.cp38-win_amd64.pyd +0 -0
- intel_npu_acceleration_library/external/openvino/frontend/paddle/py_paddle_frontend.cp39-win_amd64.pyd +0 -0
- intel_npu_acceleration_library/external/openvino/frontend/pytorch/__init__.py +19 -0
- intel_npu_acceleration_library/external/openvino/frontend/pytorch/fx_decoder.py +370 -0
- intel_npu_acceleration_library/external/openvino/frontend/pytorch/gptq.py +180 -0
- intel_npu_acceleration_library/external/openvino/frontend/pytorch/module_extension.py +39 -0
- intel_npu_acceleration_library/external/openvino/frontend/pytorch/patch_model.py +118 -0
- intel_npu_acceleration_library/external/openvino/frontend/pytorch/py_pytorch_frontend.cp310-win_amd64.pyd +0 -0
- intel_npu_acceleration_library/external/openvino/frontend/pytorch/py_pytorch_frontend.cp311-win_amd64.pyd +0 -0
- intel_npu_acceleration_library/external/openvino/frontend/pytorch/py_pytorch_frontend.cp312-win_amd64.pyd +0 -0
- intel_npu_acceleration_library/external/openvino/frontend/pytorch/py_pytorch_frontend.cp38-win_amd64.pyd +0 -0
- intel_npu_acceleration_library/external/openvino/frontend/pytorch/py_pytorch_frontend.cp39-win_amd64.pyd +0 -0
- intel_npu_acceleration_library/external/openvino/frontend/pytorch/torchdynamo/backend.py +131 -0
- intel_npu_acceleration_library/external/openvino/frontend/pytorch/torchdynamo/backend_utils.py +85 -0
- intel_npu_acceleration_library/external/openvino/frontend/pytorch/torchdynamo/compile.py +141 -0
- intel_npu_acceleration_library/external/openvino/frontend/pytorch/torchdynamo/decompositions.py +116 -0
- intel_npu_acceleration_library/external/openvino/frontend/pytorch/torchdynamo/execute.py +189 -0
- intel_npu_acceleration_library/external/openvino/frontend/pytorch/torchdynamo/op_support.py +290 -0
- intel_npu_acceleration_library/external/openvino/frontend/pytorch/torchdynamo/partition.py +126 -0
- intel_npu_acceleration_library/external/openvino/frontend/pytorch/ts_decoder.py +568 -0
- intel_npu_acceleration_library/external/openvino/frontend/pytorch/utils.py +258 -0
- intel_npu_acceleration_library/external/openvino/frontend/tensorflow/__init__.py +16 -0
- intel_npu_acceleration_library/external/openvino/frontend/tensorflow/graph_iterator.py +116 -0
- intel_npu_acceleration_library/external/openvino/frontend/tensorflow/node_decoder.py +219 -0
- intel_npu_acceleration_library/external/openvino/frontend/tensorflow/py_tensorflow_frontend.cp310-win_amd64.pyd +0 -0
- intel_npu_acceleration_library/external/openvino/frontend/tensorflow/py_tensorflow_frontend.cp311-win_amd64.pyd +0 -0
- intel_npu_acceleration_library/external/openvino/frontend/tensorflow/py_tensorflow_frontend.cp312-win_amd64.pyd +0 -0
- intel_npu_acceleration_library/external/openvino/frontend/tensorflow/py_tensorflow_frontend.cp38-win_amd64.pyd +0 -0
- intel_npu_acceleration_library/external/openvino/frontend/tensorflow/py_tensorflow_frontend.cp39-win_amd64.pyd +0 -0
- intel_npu_acceleration_library/external/openvino/frontend/tensorflow/utils.py +481 -0
- intel_npu_acceleration_library/external/openvino/helpers/__init__.py +6 -0
- intel_npu_acceleration_library/external/openvino/helpers/packing.py +87 -0
- intel_npu_acceleration_library/external/openvino/preprocess/README.md +60 -0
- intel_npu_acceleration_library/external/openvino/preprocess/__init__.py +28 -0
- intel_npu_acceleration_library/external/openvino/preprocess/torchvision/__init__.py +15 -0
- intel_npu_acceleration_library/external/openvino/preprocess/torchvision/preprocess_converter.py +47 -0
- intel_npu_acceleration_library/external/openvino/preprocess/torchvision/requirements.txt +5 -0
- intel_npu_acceleration_library/external/openvino/preprocess/torchvision/torchvision_preprocessing.py +347 -0
- intel_npu_acceleration_library/external/openvino/properties/__init__.py +22 -0
- intel_npu_acceleration_library/external/openvino/properties/_properties.py +55 -0
- intel_npu_acceleration_library/external/openvino/properties/device/__init__.py +14 -0
- intel_npu_acceleration_library/external/openvino/properties/hint/__init__.py +15 -0
- intel_npu_acceleration_library/external/openvino/properties/intel_auto/__init__.py +12 -0
- intel_npu_acceleration_library/external/openvino/properties/intel_cpu/__init__.py +8 -0
- intel_npu_acceleration_library/external/openvino/properties/intel_gpu/__init__.py +12 -0
- intel_npu_acceleration_library/external/openvino/properties/intel_gpu/hint/__init__.py +11 -0
- intel_npu_acceleration_library/external/openvino/properties/log/__init__.py +11 -0
- intel_npu_acceleration_library/external/openvino/properties/streams/__init__.py +11 -0
- intel_npu_acceleration_library/external/openvino/runtime/__init__.py +85 -0
- intel_npu_acceleration_library/external/openvino/runtime/exceptions.py +17 -0
- intel_npu_acceleration_library/external/openvino/runtime/ie_api.py +631 -0
- intel_npu_acceleration_library/external/openvino/runtime/op/__init__.py +19 -0
- intel_npu_acceleration_library/external/openvino/runtime/op/util/__init__.py +22 -0
- intel_npu_acceleration_library/external/openvino/runtime/opset1/__init__.py +112 -0
- intel_npu_acceleration_library/external/openvino/runtime/opset1/ops.py +3068 -0
- intel_npu_acceleration_library/external/openvino/runtime/opset10/__init__.py +179 -0
- intel_npu_acceleration_library/external/openvino/runtime/opset10/ops.py +173 -0
- intel_npu_acceleration_library/external/openvino/runtime/opset11/__init__.py +179 -0
- intel_npu_acceleration_library/external/openvino/runtime/opset11/ops.py +107 -0
- intel_npu_acceleration_library/external/openvino/runtime/opset12/__init__.py +180 -0
- intel_npu_acceleration_library/external/openvino/runtime/opset12/ops.py +120 -0
- intel_npu_acceleration_library/external/openvino/runtime/opset13/__init__.py +188 -0
- intel_npu_acceleration_library/external/openvino/runtime/opset13/ops.py +398 -0
- intel_npu_acceleration_library/external/openvino/runtime/opset14/__init__.py +190 -0
- intel_npu_acceleration_library/external/openvino/runtime/opset14/ops.py +171 -0
- intel_npu_acceleration_library/external/openvino/runtime/opset15/__init__.py +17 -0
- intel_npu_acceleration_library/external/openvino/runtime/opset15/ops.py +276 -0
- intel_npu_acceleration_library/external/openvino/runtime/opset2/__init__.py +118 -0
- intel_npu_acceleration_library/external/openvino/runtime/opset2/ops.py +216 -0
- intel_npu_acceleration_library/external/openvino/runtime/opset3/__init__.py +134 -0
- intel_npu_acceleration_library/external/openvino/runtime/opset3/ops.py +638 -0
- intel_npu_acceleration_library/external/openvino/runtime/opset4/__init__.py +145 -0
- intel_npu_acceleration_library/external/openvino/runtime/opset4/ops.py +464 -0
- intel_npu_acceleration_library/external/openvino/runtime/opset5/__init__.py +152 -0
- intel_npu_acceleration_library/external/openvino/runtime/opset5/ops.py +372 -0
- intel_npu_acceleration_library/external/openvino/runtime/opset6/__init__.py +154 -0
- intel_npu_acceleration_library/external/openvino/runtime/opset6/ops.py +215 -0
- intel_npu_acceleration_library/external/openvino/runtime/opset7/__init__.py +158 -0
- intel_npu_acceleration_library/external/openvino/runtime/opset7/ops.py +169 -0
- intel_npu_acceleration_library/external/openvino/runtime/opset8/__init__.py +169 -0
- intel_npu_acceleration_library/external/openvino/runtime/opset8/ops.py +787 -0
- intel_npu_acceleration_library/external/openvino/runtime/opset9/__init__.py +175 -0
- intel_npu_acceleration_library/external/openvino/runtime/opset9/ops.py +341 -0
- intel_npu_acceleration_library/external/openvino/runtime/opset_utils.py +22 -0
- intel_npu_acceleration_library/external/openvino/runtime/passes/__init__.py +19 -0
- intel_npu_acceleration_library/external/openvino/runtime/passes/graph_rewrite.py +33 -0
- intel_npu_acceleration_library/external/openvino/runtime/passes/manager.py +26 -0
- intel_npu_acceleration_library/external/openvino/runtime/properties/__init__.py +40 -0
- intel_npu_acceleration_library/external/openvino/runtime/properties/hint/__init__.py +25 -0
- intel_npu_acceleration_library/external/openvino/runtime/utils/__init__.py +7 -0
- intel_npu_acceleration_library/external/openvino/runtime/utils/broadcasting.py +44 -0
- intel_npu_acceleration_library/external/openvino/runtime/utils/data_helpers/__init__.py +8 -0
- intel_npu_acceleration_library/external/openvino/runtime/utils/data_helpers/data_dispatcher.py +447 -0
- intel_npu_acceleration_library/external/openvino/runtime/utils/data_helpers/wrappers.py +148 -0
- intel_npu_acceleration_library/external/openvino/runtime/utils/decorators.py +156 -0
- intel_npu_acceleration_library/external/openvino/runtime/utils/input_validation.py +133 -0
- intel_npu_acceleration_library/external/openvino/runtime/utils/node_factory.py +127 -0
- intel_npu_acceleration_library/external/openvino/runtime/utils/reduction.py +25 -0
- intel_npu_acceleration_library/external/openvino/runtime/utils/types.py +175 -0
- intel_npu_acceleration_library/external/openvino/tools/__init__.py +4 -0
- intel_npu_acceleration_library/external/openvino/tools/benchmark/__init__.py +3 -0
- intel_npu_acceleration_library/external/openvino/tools/benchmark/benchmark.py +186 -0
- intel_npu_acceleration_library/external/openvino/tools/benchmark/main.py +695 -0
- intel_npu_acceleration_library/external/openvino/tools/benchmark/parameters.py +199 -0
- intel_npu_acceleration_library/external/openvino/tools/benchmark/utils/__init__.py +3 -0
- intel_npu_acceleration_library/external/openvino/tools/benchmark/utils/constants.py +26 -0
- intel_npu_acceleration_library/external/openvino/tools/benchmark/utils/inputs_filling.py +482 -0
- intel_npu_acceleration_library/external/openvino/tools/benchmark/utils/logging.py +8 -0
- intel_npu_acceleration_library/external/openvino/tools/benchmark/utils/statistics_report.py +296 -0
- intel_npu_acceleration_library/external/openvino/tools/benchmark/utils/utils.py +836 -0
- intel_npu_acceleration_library/external/openvino/tools/ovc/__init__.py +20 -0
- intel_npu_acceleration_library/external/openvino/tools/ovc/__main__.py +10 -0
- intel_npu_acceleration_library/external/openvino/tools/ovc/cli_parser.py +633 -0
- intel_npu_acceleration_library/external/openvino/tools/ovc/convert.py +102 -0
- intel_npu_acceleration_library/external/openvino/tools/ovc/convert_data_type.py +82 -0
- intel_npu_acceleration_library/external/openvino/tools/ovc/convert_impl.py +550 -0
- intel_npu_acceleration_library/external/openvino/tools/ovc/environment_setup_utils.py +50 -0
- intel_npu_acceleration_library/external/openvino/tools/ovc/error.py +49 -0
- intel_npu_acceleration_library/external/openvino/tools/ovc/get_ov_update_message.py +16 -0
- intel_npu_acceleration_library/external/openvino/tools/ovc/help.py +45 -0
- intel_npu_acceleration_library/external/openvino/tools/ovc/logger.py +91 -0
- intel_npu_acceleration_library/external/openvino/tools/ovc/main.py +40 -0
- intel_npu_acceleration_library/external/openvino/tools/ovc/moc_frontend/__init__.py +2 -0
- intel_npu_acceleration_library/external/openvino/tools/ovc/moc_frontend/analysis.py +46 -0
- intel_npu_acceleration_library/external/openvino/tools/ovc/moc_frontend/check_config.py +57 -0
- intel_npu_acceleration_library/external/openvino/tools/ovc/moc_frontend/extractor.py +447 -0
- intel_npu_acceleration_library/external/openvino/tools/ovc/moc_frontend/jax_frontend_utils.py +19 -0
- intel_npu_acceleration_library/external/openvino/tools/ovc/moc_frontend/layout_utils.py +73 -0
- intel_npu_acceleration_library/external/openvino/tools/ovc/moc_frontend/moc_emit_ir.py +32 -0
- intel_npu_acceleration_library/external/openvino/tools/ovc/moc_frontend/offline_transformations.py +107 -0
- intel_npu_acceleration_library/external/openvino/tools/ovc/moc_frontend/paddle_frontend_utils.py +83 -0
- intel_npu_acceleration_library/external/openvino/tools/ovc/moc_frontend/pipeline.py +298 -0
- intel_npu_acceleration_library/external/openvino/tools/ovc/moc_frontend/preprocessing.py +220 -0
- intel_npu_acceleration_library/external/openvino/tools/ovc/moc_frontend/pytorch_frontend_utils.py +214 -0
- intel_npu_acceleration_library/external/openvino/tools/ovc/moc_frontend/shape_utils.py +109 -0
- intel_npu_acceleration_library/external/openvino/tools/ovc/moc_frontend/type_utils.py +82 -0
- intel_npu_acceleration_library/external/openvino/tools/ovc/ovc.py +13 -0
- intel_npu_acceleration_library/external/openvino/tools/ovc/telemetry_params.py +6 -0
- intel_npu_acceleration_library/external/openvino/tools/ovc/telemetry_stub.py +28 -0
- intel_npu_acceleration_library/external/openvino/tools/ovc/telemetry_utils.py +118 -0
- intel_npu_acceleration_library/external/openvino/tools/ovc/utils.py +196 -0
- intel_npu_acceleration_library/external/openvino/tools/ovc/version.py +80 -0
- intel_npu_acceleration_library/external/openvino/torch/__init__.py +5 -0
- intel_npu_acceleration_library/external/openvino/utils.py +115 -0
- intel_npu_acceleration_library/functional/__init__.py +8 -0
- intel_npu_acceleration_library/functional/scaled_dot_product_attention.py +47 -0
- intel_npu_acceleration_library/lib/Release/cache.json +113732 -0
- intel_npu_acceleration_library/lib/Release/intel_npu_acceleration_library.dll +0 -0
- intel_npu_acceleration_library/lib/Release/openvino.dll +0 -0
- intel_npu_acceleration_library/lib/Release/openvino_auto_batch_plugin.dll +0 -0
- intel_npu_acceleration_library/lib/Release/openvino_auto_plugin.dll +0 -0
- intel_npu_acceleration_library/lib/Release/openvino_c.dll +0 -0
- intel_npu_acceleration_library/lib/Release/openvino_hetero_plugin.dll +0 -0
- intel_npu_acceleration_library/lib/Release/openvino_intel_cpu_plugin.dll +0 -0
- intel_npu_acceleration_library/lib/Release/openvino_intel_gpu_plugin.dll +0 -0
- intel_npu_acceleration_library/lib/Release/openvino_intel_npu_plugin.dll +0 -0
- intel_npu_acceleration_library/lib/Release/openvino_ir_frontend.dll +0 -0
- intel_npu_acceleration_library/lib/Release/openvino_onnx_frontend.dll +0 -0
- intel_npu_acceleration_library/lib/Release/openvino_paddle_frontend.dll +0 -0
- intel_npu_acceleration_library/lib/Release/openvino_pytorch_frontend.dll +0 -0
- intel_npu_acceleration_library/lib/Release/openvino_tensorflow_frontend.dll +0 -0
- intel_npu_acceleration_library/lib/Release/openvino_tensorflow_lite_frontend.dll +0 -0
- intel_npu_acceleration_library/lib/Release/tbb12.dll +0 -0
- intel_npu_acceleration_library/lib/Release/tbb12_debug.dll +0 -0
- intel_npu_acceleration_library/lib/Release/tbbbind_2_5.dll +0 -0
- intel_npu_acceleration_library/lib/Release/tbbbind_2_5_debug.dll +0 -0
- intel_npu_acceleration_library/lib/Release/tbbmalloc.dll +0 -0
- intel_npu_acceleration_library/lib/Release/tbbmalloc_debug.dll +0 -0
- intel_npu_acceleration_library/lib/Release/tbbmalloc_proxy.dll +0 -0
- intel_npu_acceleration_library/lib/Release/tbbmalloc_proxy_debug.dll +0 -0
- intel_npu_acceleration_library/modelling.py +150 -0
- intel_npu_acceleration_library/nn/__init__.py +20 -0
- intel_npu_acceleration_library/nn/autograd.py +68 -0
- intel_npu_acceleration_library/nn/conv.py +257 -0
- intel_npu_acceleration_library/nn/functional.py +1207 -0
- intel_npu_acceleration_library/nn/linear.py +162 -0
- intel_npu_acceleration_library/nn/llm.py +417 -0
- intel_npu_acceleration_library/nn/module.py +393 -0
- intel_npu_acceleration_library/optimizations.py +157 -0
- intel_npu_acceleration_library/quantization.py +174 -0
@@ -0,0 +1,447 @@
|
|
1
|
+
# Copyright (C) 2018-2024 Intel Corporation
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
3
|
+
|
4
|
+
import re
|
5
|
+
from enum import Enum
|
6
|
+
|
7
|
+
import numpy as np
|
8
|
+
from openvino._pyopenvino import Place, PartialShape # pylint: disable=no-name-in-module,import-error
|
9
|
+
from openvino.frontend import InputModel # pylint: disable=no-name-in-module,import-error
|
10
|
+
from openvino.tools.ovc.error import Error
|
11
|
+
|
12
|
+
|
13
|
+
def raise_no_node(node_name: str):
|
14
|
+
raise Error('No node with name {}'.format(node_name))
|
15
|
+
|
16
|
+
|
17
|
+
def raise_node_name_collision(node_name: str, found_nodes: list):
|
18
|
+
raise Error('Name collision was found, there are several nodes for mask "{}": {}. '
|
19
|
+
'If your intention was to specify port for node, please instead specify node names connected to '
|
20
|
+
'this port. If your intention was to specify the node name, please add port to the node '
|
21
|
+
'name'.format(node_name, found_nodes))
|
22
|
+
|
23
|
+
|
24
|
+
class IOType(Enum):
|
25
|
+
Input = 1
|
26
|
+
Output = 2
|
27
|
+
|
28
|
+
|
29
|
+
def decode_name_with_port(
|
30
|
+
input_model: InputModel, node_name: str, framework="", io_type=IOType.Input
|
31
|
+
) -> Place or None:
|
32
|
+
"""
|
33
|
+
Decode name with optional port specification w/o traversing all the nodes in the graph
|
34
|
+
TODO: in future node_name can specify input/output port groups as well as indices (58562)
|
35
|
+
:param input_model: Input Model
|
36
|
+
:param node_name: user provided node name
|
37
|
+
:return: decoded place in the graph
|
38
|
+
"""
|
39
|
+
found_places = []
|
40
|
+
found_place_names = []
|
41
|
+
|
42
|
+
def get_place_by_operation_name(input_model, name, framework, io_type):
|
43
|
+
node = input_model.get_place_by_operation_name(name)
|
44
|
+
if node and framework == "onnx":
|
45
|
+
if io_type == IOType.Input:
|
46
|
+
return (
|
47
|
+
node.get_input_port(input_port_index=0)
|
48
|
+
.get_producing_port()
|
49
|
+
.get_target_tensor()
|
50
|
+
)
|
51
|
+
else:
|
52
|
+
return node.get_output_port(output_port_index=0).get_target_tensor()
|
53
|
+
return node
|
54
|
+
|
55
|
+
# find by tensor name
|
56
|
+
place = input_model.get_place_by_tensor_name(node_name)
|
57
|
+
if place:
|
58
|
+
found_place_names.append("Tensor:" + node_name)
|
59
|
+
found_places.append(place)
|
60
|
+
else:
|
61
|
+
# find by operation name
|
62
|
+
place = get_place_by_operation_name(input_model, node_name, framework, io_type)
|
63
|
+
name = node_name
|
64
|
+
if framework == "onnx" and io_type == IOType.Output:
|
65
|
+
name = "Tensor:" + name
|
66
|
+
|
67
|
+
if place:
|
68
|
+
found_place_names.append(name)
|
69
|
+
found_places.append(place)
|
70
|
+
|
71
|
+
def try_get_node(model, name, framework):
|
72
|
+
node = model.get_place_by_operation_name(name)
|
73
|
+
if node:
|
74
|
+
return node
|
75
|
+
if framework == "onnx":
|
76
|
+
tensor = model.get_place_by_tensor_name(name)
|
77
|
+
if tensor:
|
78
|
+
if tensor.is_input() or tensor.is_output():
|
79
|
+
return tensor
|
80
|
+
return tensor.get_producing_operation()
|
81
|
+
return None
|
82
|
+
|
83
|
+
def get_port(match, match_starts_with_name, input_model, framework):
|
84
|
+
if not match:
|
85
|
+
return None
|
86
|
+
|
87
|
+
if match_starts_with_name:
|
88
|
+
name = match.group(1)
|
89
|
+
port_index = match.group(2)
|
90
|
+
else:
|
91
|
+
name = match.group(2)
|
92
|
+
port_index = match.group(1)
|
93
|
+
|
94
|
+
node = try_get_node(input_model, name, framework)
|
95
|
+
if node:
|
96
|
+
# if regular expression has structure <name>:<port>, get node output port.
|
97
|
+
# Otherwise get node input port
|
98
|
+
if match_starts_with_name:
|
99
|
+
return node.get_output_port(output_port_index=int(port_index))
|
100
|
+
else:
|
101
|
+
return node.get_input_port(input_port_index=int(port_index))
|
102
|
+
else:
|
103
|
+
return None
|
104
|
+
|
105
|
+
regexp_post = r"(.+):(\d+)"
|
106
|
+
match = re.search(regexp_post, node_name)
|
107
|
+
match_port = get_port(
|
108
|
+
match=match,
|
109
|
+
match_starts_with_name=True,
|
110
|
+
input_model=input_model,
|
111
|
+
framework=framework,
|
112
|
+
)
|
113
|
+
|
114
|
+
if match_port:
|
115
|
+
name = match.group(1)
|
116
|
+
if framework == "onnx":
|
117
|
+
found_place_names.append("Tensor:" + name)
|
118
|
+
found_places.append(match_port.get_target_tensor())
|
119
|
+
else:
|
120
|
+
found_place_names.append(name)
|
121
|
+
found_places.append(match_port)
|
122
|
+
|
123
|
+
regexp_pre = r"(\d+):(.+)"
|
124
|
+
match = re.search(regexp_pre, node_name)
|
125
|
+
match_port = get_port(
|
126
|
+
match=match,
|
127
|
+
match_starts_with_name=False,
|
128
|
+
input_model=input_model,
|
129
|
+
framework=framework,
|
130
|
+
)
|
131
|
+
|
132
|
+
if match_port:
|
133
|
+
name = match.group(2)
|
134
|
+
if framework == "onnx":
|
135
|
+
found_place_names.append("Tensor:" + name)
|
136
|
+
found_places.append(match_port.get_producing_port().get_target_tensor())
|
137
|
+
else:
|
138
|
+
found_places.append(match_port)
|
139
|
+
found_place_names.append(name)
|
140
|
+
|
141
|
+
if len(found_places) == 0:
|
142
|
+
raise_no_node(node_name)
|
143
|
+
|
144
|
+
# Check that there is no collision, all found places shall point to same data
|
145
|
+
if not all([n.is_equal_data(found_places[0]) for n in found_places]):
|
146
|
+
raise_node_name_collision(node_name, found_place_names)
|
147
|
+
|
148
|
+
# TODO: Add support for input/output group name and port index here (58562)
|
149
|
+
# For new frontends logic shall be extended to additionally support input and output group names
|
150
|
+
return found_places[0]
|
151
|
+
|
152
|
+
|
153
|
+
def fe_input_user_data_repack(
|
154
|
+
input_model: InputModel,
|
155
|
+
input_user_shapes: [None, list, dict, np.ndarray],
|
156
|
+
freeze_placeholder: dict,
|
157
|
+
framework: str,
|
158
|
+
input_user_data_types=None,
|
159
|
+
):
|
160
|
+
"""
|
161
|
+
Restructures user input cutting request. Splits ports out of node names.
|
162
|
+
Transforms node names to node ids.
|
163
|
+
:param input_model: current input model
|
164
|
+
:param input_user_shapes: data structure representing user input cutting request. It may be:
|
165
|
+
# None value if user did not provide neither "input" nor "input_shape" keys
|
166
|
+
# list instance which contains input layer names with or without ports if user provided
|
167
|
+
only "input" key
|
168
|
+
# dict instance which contains input layer names with or without ports as keys and shapes as
|
169
|
+
values if user provided both "input" and "input_shape"
|
170
|
+
# np.ndarray if user provided only "input_shape" key
|
171
|
+
:param freeze_placeholder: dictionary with placeholder names as keys and freezing value as values
|
172
|
+
:param input_user_data_types: dictionary with input nodes and its data types
|
173
|
+
:return: restructured input shapes and freeze placeholder shapes information
|
174
|
+
Example of input dictionary:
|
175
|
+
_input_shapes =
|
176
|
+
{
|
177
|
+
'node_ID':
|
178
|
+
[
|
179
|
+
{'shape': None, 'in': 0},
|
180
|
+
{'shape': None, 'in': 1},
|
181
|
+
],
|
182
|
+
'node_1_ID':
|
183
|
+
[
|
184
|
+
{'shape': [1, 227, 227, 3], 'port': None, 'data_type': np.int32}
|
185
|
+
],
|
186
|
+
'node_2_ID':
|
187
|
+
[
|
188
|
+
{'shape': None, 'out': 3}
|
189
|
+
]
|
190
|
+
}
|
191
|
+
Example of freeze placeholder dictionary:
|
192
|
+
_freeze_placeholder =
|
193
|
+
{
|
194
|
+
'phase_train' : False
|
195
|
+
}
|
196
|
+
"""
|
197
|
+
_input_shapes = []
|
198
|
+
_input_names = []
|
199
|
+
model_inputs = input_model.get_inputs()
|
200
|
+
|
201
|
+
if isinstance(input_user_shapes, list) and len(input_user_shapes) > 1 and isinstance(input_user_shapes[0],
|
202
|
+
PartialShape):
|
203
|
+
for shape in input_user_shapes:
|
204
|
+
assert isinstance(shape, PartialShape), "Got incorrect format of input shapes."
|
205
|
+
assert len(model_inputs) == len(input_user_shapes)
|
206
|
+
for idx, model_input in enumerate(model_inputs):
|
207
|
+
_input_shapes.append({"node": model_input, "shape": input_user_shapes[idx]})
|
208
|
+
elif isinstance(input_user_shapes, list) or isinstance(input_user_shapes, dict):
|
209
|
+
for input_name in input_user_shapes:
|
210
|
+
node = decode_name_with_port(
|
211
|
+
input_model, input_name, framework, IOType.Input
|
212
|
+
)
|
213
|
+
if node is None:
|
214
|
+
raise Error(
|
215
|
+
"Cannot find location {} in the input model".format(input_name)
|
216
|
+
)
|
217
|
+
shape = (
|
218
|
+
None
|
219
|
+
if isinstance(input_user_shapes, list)
|
220
|
+
else input_user_shapes[input_name]
|
221
|
+
)
|
222
|
+
if isinstance(input_user_data_types, dict) and input_user_data_types.get(input_name) is not None:
|
223
|
+
data_type = input_user_data_types[input_name]
|
224
|
+
_input_shapes.append(
|
225
|
+
{
|
226
|
+
"node": node,
|
227
|
+
"shape": shape,
|
228
|
+
"data_type": data_type,
|
229
|
+
"input_name": input_name,
|
230
|
+
}
|
231
|
+
)
|
232
|
+
else:
|
233
|
+
_input_shapes.append(
|
234
|
+
{
|
235
|
+
"node": node,
|
236
|
+
"shape": shape,
|
237
|
+
"input_name": input_name
|
238
|
+
}
|
239
|
+
)
|
240
|
+
_input_names.append(input_name)
|
241
|
+
elif isinstance(input_user_shapes, PartialShape):
|
242
|
+
# this branch covers the single use of `input_shape` without `input` option
|
243
|
+
# but it can be used along with `freeze_placeholder_with_value` option
|
244
|
+
# for example, input_shape [3] freeze_placeholder_with_value "is_training->False"
|
245
|
+
# means the model has two inputs: one is is_training to be frozen, the other to re-write the shape
|
246
|
+
# NOTE: the logic relies on parameters with the single name
|
247
|
+
frozen_names = freeze_placeholder.keys()
|
248
|
+
assert len(model_inputs) == len(frozen_names) + 1, \
|
249
|
+
"Please check the conversion command-line. Total number of model inputs ({} detected) " \
|
250
|
+
"must match to a number of input shapes along with frozen inputs ({} in total).".format(
|
251
|
+
len(model_inputs),
|
252
|
+
len(frozen_names) + 1)
|
253
|
+
for node in model_inputs:
|
254
|
+
assert len(node.get_names()) > 0, "Original model inputs must have tensor names."
|
255
|
+
input_name = node.get_names()[0]
|
256
|
+
if input_name not in frozen_names:
|
257
|
+
_input_shapes.append(
|
258
|
+
{
|
259
|
+
"node": node,
|
260
|
+
"shape": input_user_shapes,
|
261
|
+
"input_name": input_name
|
262
|
+
}
|
263
|
+
)
|
264
|
+
# case when single unnamed input shape and type was specified
|
265
|
+
if input_name in input_user_data_types:
|
266
|
+
_input_shapes[-1]['data_type'] = input_user_data_types[input_name]
|
267
|
+
_input_names.append(input_name)
|
268
|
+
break
|
269
|
+
else:
|
270
|
+
# this case means that we use original inputs of the model
|
271
|
+
# and they should not be changed and their properties (shape and type) should not be over-written
|
272
|
+
# NOTE: the logic relies on parameters with the single name
|
273
|
+
assert input_user_shapes is None
|
274
|
+
for node in model_inputs:
|
275
|
+
assert len(node.get_names()) > 0, "Original model inputs must have tensor names."
|
276
|
+
input_name = node.get_names()[0]
|
277
|
+
_input_shapes.append(
|
278
|
+
{
|
279
|
+
"node": node,
|
280
|
+
"input_name": input_name
|
281
|
+
}
|
282
|
+
)
|
283
|
+
# case when types were specified for unnamed inputs
|
284
|
+
if input_name in input_user_data_types:
|
285
|
+
_input_shapes[-1]['data_type'] = input_user_data_types[input_name]
|
286
|
+
# mark-up Place names we already put into the _input_names
|
287
|
+
# to avoid duplicates in updates by freeze_placeholder below
|
288
|
+
_input_names.append(input_name)
|
289
|
+
|
290
|
+
if freeze_placeholder:
|
291
|
+
# in case freezing via freeze_placeholder_with_value option, _input_shapes can miss some frozen places
|
292
|
+
for input_name in freeze_placeholder:
|
293
|
+
if input_name in _input_names:
|
294
|
+
continue
|
295
|
+
node = decode_name_with_port(
|
296
|
+
input_model, input_name, framework, IOType.Input
|
297
|
+
)
|
298
|
+
_input_shapes.append(
|
299
|
+
{
|
300
|
+
"node": node,
|
301
|
+
"input_name": input_name
|
302
|
+
}
|
303
|
+
)
|
304
|
+
return _input_shapes, freeze_placeholder
|
305
|
+
return _input_shapes, dict()
|
306
|
+
|
307
|
+
|
308
|
+
def fe_output_user_data_repack(input_model: InputModel, outputs: list, framework: str):
|
309
|
+
"""
|
310
|
+
|
311
|
+
:param input_model: Input Model to operate on
|
312
|
+
:param outputs: list of node names provided by user
|
313
|
+
:return: dictionary with node IDs as keys and list of port dictionaries as values
|
314
|
+
Example of outputs dictionary:
|
315
|
+
_outputs =
|
316
|
+
{
|
317
|
+
'node_ID':
|
318
|
+
[
|
319
|
+
{'out': 0},
|
320
|
+
{'out': 1},
|
321
|
+
],
|
322
|
+
'node_1_ID':
|
323
|
+
[
|
324
|
+
{'port': None}
|
325
|
+
],
|
326
|
+
'node_2_ID':
|
327
|
+
[
|
328
|
+
{'in': 3}
|
329
|
+
]
|
330
|
+
}
|
331
|
+
"""
|
332
|
+
_outputs = []
|
333
|
+
if outputs is not None:
|
334
|
+
for output in outputs:
|
335
|
+
node = decode_name_with_port(input_model, output, framework, IOType.Output)
|
336
|
+
if node is None:
|
337
|
+
raise Error("Cannot find location {} in the graph".format(output))
|
338
|
+
_outputs.append({"node": node, "output_name": output})
|
339
|
+
return _outputs
|
340
|
+
|
341
|
+
|
342
|
+
def find_first_unused_input(model_inputs: list, param_dict: dict, param_name: str):
|
343
|
+
"""
|
344
|
+
Finds first input in model_inputs, which is not present in freeze_placeholder dictionary or param_dict.
|
345
|
+
|
346
|
+
:param model_inputs: list of model inputs
|
347
|
+
:param param_dict: dictionary where key is input name, value is parameter value (shape or type).
|
348
|
+
:param param_name: name of parameter used in exception message.
|
349
|
+
|
350
|
+
:return: first input name, which is not present in freeze_placeholder dictionary or param_dict.
|
351
|
+
"""
|
352
|
+
for inp in model_inputs:
|
353
|
+
input_names = inp.get_names()
|
354
|
+
name_found = False
|
355
|
+
for input_name in input_names:
|
356
|
+
if input_name in param_dict:
|
357
|
+
name_found = True
|
358
|
+
break
|
359
|
+
if name_found:
|
360
|
+
continue
|
361
|
+
return input_names[0]
|
362
|
+
raise Error("Could not set {}, as model does not have enough inputs.".format(param_name))
|
363
|
+
|
364
|
+
|
365
|
+
def convert_params_lists_to_dicts(input_model,
|
366
|
+
input_user_shapes: [list, dict],
|
367
|
+
input_user_data_types: [list, dict]):
|
368
|
+
"""
|
369
|
+
Convert lists of unnamed params to dicts using input names from input_model.
|
370
|
+
|
371
|
+
:param input_model: openvino.runtime.InputModel
|
372
|
+
:param input_user_shapes: list of input shapes or dictionary where key is input name, value is input shape from user.
|
373
|
+
:param input_user_data_types: list of input types or dictionary where key is input name, value is input type from user.
|
374
|
+
|
375
|
+
:return: (input_user_shapes_dict, input_user_data_types_dict, freeze_placeholder), where
|
376
|
+
input_user_shapes_dict - dictionary where key is input name, value is shape from user;
|
377
|
+
input_user_data_types_dict - dictionary where key is input name, value is type from user;
|
378
|
+
freeze_placeholder - dictionary where key is input name, value is input value from user;
|
379
|
+
"""
|
380
|
+
from openvino.runtime import PartialShape # pylint: disable=no-name-in-module,import-error
|
381
|
+
model_inputs = input_model.get_inputs()
|
382
|
+
input_user_data_types_dict = {}
|
383
|
+
input_user_shapes_dict = {}
|
384
|
+
|
385
|
+
# input_user_shapes is list only if unnamed inputs were used
|
386
|
+
if isinstance(input_user_shapes, list):
|
387
|
+
|
388
|
+
# this cycle adds each unnamed shape to dictionary using name from model_inputs
|
389
|
+
for idx, shape in enumerate(input_user_shapes):
|
390
|
+
assert isinstance(shape, PartialShape), "Got incorrect format of input shapes {}.".format(type(shape))
|
391
|
+
|
392
|
+
inp_name = find_first_unused_input(model_inputs, input_user_shapes_dict, "shape")
|
393
|
+
input_user_shapes_dict[inp_name] = shape
|
394
|
+
else:
|
395
|
+
input_user_shapes_dict = input_user_shapes
|
396
|
+
|
397
|
+
# input_user_data_types is list only if unnamed inputs were used
|
398
|
+
if isinstance(input_user_data_types, list):
|
399
|
+
from openvino.runtime import Type # pylint: disable=no-name-in-module,import-error
|
400
|
+
|
401
|
+
if input_user_shapes_dict is None:
|
402
|
+
input_user_shapes_dict = {}
|
403
|
+
|
404
|
+
# this cycle adds each unnamed type to dictionary using name from model_inputs
|
405
|
+
for idx, node_type in enumerate(input_user_data_types):
|
406
|
+
assert isinstance(node_type, (type, np.dtype, Type)), "Got incorrect format of input types. " \
|
407
|
+
"Expected numpy type or openvino.runtime.Type, " \
|
408
|
+
"got {}.".format(type(node_type))
|
409
|
+
|
410
|
+
inp_name = find_first_unused_input(model_inputs, input_user_data_types_dict, "type")
|
411
|
+
input_user_data_types_dict[inp_name] = node_type
|
412
|
+
# FE postprocessing expects input_user_shapes_dict to always have shapes for corresponding types.
|
413
|
+
# If shape is not set it is expected to have None shape in input_user_shapes_dict dictionary.
|
414
|
+
if inp_name not in input_user_shapes_dict:
|
415
|
+
input_user_shapes_dict[inp_name] = None
|
416
|
+
else:
|
417
|
+
input_user_data_types_dict = input_user_data_types
|
418
|
+
|
419
|
+
return input_user_shapes_dict, input_user_data_types_dict
|
420
|
+
|
421
|
+
|
422
|
+
def fe_user_data_repack(
|
423
|
+
input_model: InputModel,
|
424
|
+
input_user_shapes: [None, list, dict, np.array],
|
425
|
+
input_user_data_types: dict,
|
426
|
+
outputs: list,
|
427
|
+
freeze_placeholder: dict,
|
428
|
+
framework: str,
|
429
|
+
):
|
430
|
+
"""
|
431
|
+
:param input_model: Input Model to operate on
|
432
|
+
:param input_user_shapes: data structure representing user input cutting request
|
433
|
+
:param input_user_data_types: dictionary with input nodes and its data types
|
434
|
+
:param outputs: list of node names to treat as outputs
|
435
|
+
:param freeze_placeholder: dictionary with placeholder names as keys and freezing value as values
|
436
|
+
:return: restructured input, output and freeze placeholder dictionaries or None values
|
437
|
+
"""
|
438
|
+
_input_shapes, _freeze_placeholder = fe_input_user_data_repack(
|
439
|
+
input_model,
|
440
|
+
input_user_shapes,
|
441
|
+
freeze_placeholder,
|
442
|
+
framework,
|
443
|
+
input_user_data_types=input_user_data_types,
|
444
|
+
)
|
445
|
+
_outputs = fe_output_user_data_repack(input_model, outputs, framework)
|
446
|
+
|
447
|
+
return _input_shapes, _outputs, _freeze_placeholder
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# Copyright (C) 2018-2024 Intel Corporation
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
3
|
+
|
4
|
+
import logging as log
|
5
|
+
|
6
|
+
|
7
|
+
def get_jax_decoder(model, args):
|
8
|
+
try:
|
9
|
+
from openvino.frontend.jax.jaxpr_decoder import JaxprPythonDecoder
|
10
|
+
except Exception as e:
|
11
|
+
log.error("JAX frontend loading failed")
|
12
|
+
raise e
|
13
|
+
|
14
|
+
if not isinstance(model, JaxprPythonDecoder):
|
15
|
+
decoder = JaxprPythonDecoder(model)
|
16
|
+
else:
|
17
|
+
decoder = model
|
18
|
+
|
19
|
+
args['input_model'] = decoder
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# Copyright (C) 2018-2024 Intel Corporation
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
3
|
+
|
4
|
+
from typing import Callable
|
5
|
+
|
6
|
+
from openvino.runtime import PartialShape # pylint: disable=no-name-in-module,import-error
|
7
|
+
from openvino.tools.ovc.error import Error
|
8
|
+
from openvino.tools.ovc.utils import refer_to_faq_msg
|
9
|
+
|
10
|
+
|
11
|
+
def update_layout_to_dict(inputs: list, layout: [list, dict], get_names_func: Callable):
|
12
|
+
"""
|
13
|
+
The function prepares layout values in the dictionary with items of the format:
|
14
|
+
{ node_name : {'source_layout': 'NHWC', 'target_layout': 'NCHW'} }
|
15
|
+
"""
|
16
|
+
if isinstance(layout, dict):
|
17
|
+
if '' in layout:
|
18
|
+
input_names = [list(get_names_func(cur_input))[0] for cur_input in inputs]
|
19
|
+
if len(input_names) > 1:
|
20
|
+
raise Error('Layout without name can be specified for models with only one input, '
|
21
|
+
'but provided model has {} inputs: \'{}\'. '
|
22
|
+
'Please specify explicitly input/output name for "layout" option'
|
23
|
+
.format(len(input_names), input_names))
|
24
|
+
layout = {
|
25
|
+
input_names[0]: {
|
26
|
+
'source_layout': layout[''].get('source_layout'),
|
27
|
+
'target_layout': layout[''].get('target_layout')
|
28
|
+
}
|
29
|
+
}
|
30
|
+
return layout
|
31
|
+
if isinstance(layout, list):
|
32
|
+
if len(layout) != len(inputs):
|
33
|
+
raise Error('Numbers of inputs and layout values do not match. ' + refer_to_faq_msg(61))
|
34
|
+
layout_dict = {}
|
35
|
+
for idx, cur_input in enumerate(inputs):
|
36
|
+
names_list = list(get_names_func(cur_input))
|
37
|
+
assert len(names_list) > 0, "No names for input"
|
38
|
+
node_name = names_list[0]
|
39
|
+
layout_dict.update(
|
40
|
+
{
|
41
|
+
node_name: layout[idx]
|
42
|
+
}
|
43
|
+
)
|
44
|
+
return layout_dict
|
45
|
+
raise Error("Unknown layout type. Expected dict, list. Got {}".format(type(layout)))
|
46
|
+
|
47
|
+
|
48
|
+
def get_dimension_index_by_label(input_shape: PartialShape, input_names: list, layout_dict: [dict],
|
49
|
+
dimension_label: str, default_dim: int):
|
50
|
+
"""
|
51
|
+
The function returns index of the dimension pointed in the layout
|
52
|
+
and a flag indicating if the index is chosen by default.
|
53
|
+
For example, the index for 'D' dimension in "NHWDC" layout is 3.
|
54
|
+
"""
|
55
|
+
if input_shape.rank.is_static and input_shape.rank.get_length() == 0:
|
56
|
+
# in case a scalar, batch dimension is not defined
|
57
|
+
return None, False
|
58
|
+
|
59
|
+
# search for the corresponding layout
|
60
|
+
for name, layout_value in layout_dict.items():
|
61
|
+
if name in input_names:
|
62
|
+
layout = layout_value.get('source_layout', None)
|
63
|
+
if layout is None:
|
64
|
+
return default_dim, True
|
65
|
+
from openvino.runtime import Layout # pylint: disable=no-name-in-module,import-error
|
66
|
+
layout_parsed = Layout(layout)
|
67
|
+
if layout_parsed.has_name(dimension_label):
|
68
|
+
return layout_parsed.get_index_by_name(dimension_label), False
|
69
|
+
else:
|
70
|
+
# if the layout is specified and the required dimension label is not found, the batch is unknown
|
71
|
+
return None, False
|
72
|
+
|
73
|
+
return default_dim, True
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# Copyright (C) 2018-2024 Intel Corporation
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
3
|
+
|
4
|
+
import argparse
|
5
|
+
|
6
|
+
from openvino.runtime import Model # pylint: disable=no-name-in-module,import-error
|
7
|
+
from openvino.tools.ovc.moc_frontend.preprocessing import apply_preprocessing
|
8
|
+
|
9
|
+
|
10
|
+
def moc_emit_ir(ngraph_function: Model, argv: argparse.Namespace):
|
11
|
+
from openvino._offline_transformations import compress_quantize_weights_transformation, \
|
12
|
+
apply_moc_transformations # pylint: disable=no-name-in-module,import-error
|
13
|
+
from openvino.tools.ovc.moc_frontend.offline_transformations import apply_moc_legacy_transformations, \
|
14
|
+
apply_fused_names_cleanup
|
15
|
+
|
16
|
+
# Apply preprocessing (mean/scale/reverse_channels/convert_layout/etc)
|
17
|
+
apply_preprocessing(ov_function=ngraph_function, argv=argv)
|
18
|
+
|
19
|
+
# Apply transformations
|
20
|
+
apply_moc_transformations(ngraph_function, cf=False, smart_reshape=True)
|
21
|
+
compress_quantize_weights_transformation(ngraph_function)
|
22
|
+
|
23
|
+
if argv.framework == "onnx": # TODO: Consider removing
|
24
|
+
# set OldApi map in IR to be executed via OV API 1.x and for parity with legacy MO
|
25
|
+
params_with_custom_types = [] if argv.placeholder_data_types is None \
|
26
|
+
else list(argv.placeholder_data_types.keys())
|
27
|
+
apply_moc_legacy_transformations(ngraph_function, params_with_custom_types)
|
28
|
+
|
29
|
+
apply_fused_names_cleanup(ngraph_function)
|
30
|
+
|
31
|
+
del argv.feManager
|
32
|
+
return ngraph_function
|
intel_npu_acceleration_library/external/openvino/tools/ovc/moc_frontend/offline_transformations.py
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
# Copyright (C) 2018-2024 Intel Corporation
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
3
|
+
|
4
|
+
from typing import List
|
5
|
+
|
6
|
+
from openvino.tools.ovc.error import Error
|
7
|
+
|
8
|
+
|
9
|
+
def get_new_placeholder_name(node_id: str, is_out_port: bool = False, port: int = 0):
|
10
|
+
"""
|
11
|
+
Forms a name of new placeholder created by cutting a graph
|
12
|
+
:param node_id: a node name that is cut
|
13
|
+
:param is_out_port: it is True iff output port is cut
|
14
|
+
:param port: a port number
|
15
|
+
:return: a name of new placeholder created by cutting a graph
|
16
|
+
"""
|
17
|
+
port_type = '_out' if is_out_port else ''
|
18
|
+
return '{}/placeholder{}_port_{}'.format(node_id, port_type, port)
|
19
|
+
|
20
|
+
|
21
|
+
def create_params_with_custom_types(packed_user_shapes: [None, dict]):
|
22
|
+
"""
|
23
|
+
Compute a list of placeholder names for which an user specifies custom type
|
24
|
+
:param packed_user_shapes: packed data that contains input node names,
|
25
|
+
their port numbers, shapes and data types
|
26
|
+
:return: a list of placeholder names for which an user specifies custom type
|
27
|
+
Example of packed_user_shapes dictionary:
|
28
|
+
packed_user_shapes =
|
29
|
+
{
|
30
|
+
'node_ID':
|
31
|
+
[
|
32
|
+
{'shape': None, 'in': 0},
|
33
|
+
{'shape': None, 'in': 1},
|
34
|
+
],
|
35
|
+
'node_1_ID':
|
36
|
+
[
|
37
|
+
{'shape': [1, 227, 227, 3], 'port': None, 'data_type': np.int32}
|
38
|
+
],
|
39
|
+
'node_2_ID':
|
40
|
+
[
|
41
|
+
{'shape': None, 'out': 3}
|
42
|
+
]
|
43
|
+
}
|
44
|
+
For which the function returns a list ['node_1_ID'] because this node only has custom data type
|
45
|
+
"""
|
46
|
+
if packed_user_shapes is None:
|
47
|
+
return []
|
48
|
+
|
49
|
+
params_with_custom_types = []
|
50
|
+
for input_name in packed_user_shapes:
|
51
|
+
for desc in packed_user_shapes[input_name]:
|
52
|
+
p_name = input_name
|
53
|
+
if 'port' in desc and desc['port'] is None: # neither input nor output port specified
|
54
|
+
user_defined_type = desc.get('data_type', None)
|
55
|
+
else: # need to check the particular port the Parameter was created for
|
56
|
+
p_name = get_new_placeholder_name(input_name, 'out' in desc,
|
57
|
+
desc['out'] if 'out' in desc else desc['in'])
|
58
|
+
user_defined_type = desc.get('data_type', None)
|
59
|
+
if user_defined_type is not None:
|
60
|
+
params_with_custom_types.append(p_name)
|
61
|
+
return params_with_custom_types
|
62
|
+
|
63
|
+
|
64
|
+
def get_available_transformations():
|
65
|
+
try:
|
66
|
+
from openvino._offline_transformations import \
|
67
|
+
apply_low_latency_transformation # pylint: disable=import-error,no-name-in-module
|
68
|
+
from openvino._offline_transformations import \
|
69
|
+
apply_make_stateful_transformation # pylint: disable=import-error,no-name-in-module
|
70
|
+
from openvino._offline_transformations import \
|
71
|
+
apply_pruning_transformation # pylint: disable=import-error,no-name-in-module
|
72
|
+
return {
|
73
|
+
'MakeStateful': apply_make_stateful_transformation,
|
74
|
+
'LowLatency2': apply_low_latency_transformation,
|
75
|
+
'Pruning': apply_pruning_transformation,
|
76
|
+
}
|
77
|
+
except Exception as e:
|
78
|
+
return {}
|
79
|
+
|
80
|
+
|
81
|
+
# net should be openvino.runtime.Model type, but OV Engine is still optional dependency
|
82
|
+
def apply_user_transformations(func: object, transforms: list):
|
83
|
+
available_transformations = get_available_transformations()
|
84
|
+
|
85
|
+
for name, args in transforms:
|
86
|
+
if name not in available_transformations.keys():
|
87
|
+
raise Error("Transformation {} is not available.".format(name))
|
88
|
+
|
89
|
+
available_transformations[name](func, **args)
|
90
|
+
|
91
|
+
|
92
|
+
def apply_moc_legacy_transformations(func: object, params_with_custom_types: List[str]):
|
93
|
+
from openvino._offline_transformations import \
|
94
|
+
apply_moc_legacy_transformations # pylint: disable=import-error,no-name-in-module
|
95
|
+
apply_moc_legacy_transformations(func, params_with_custom_types)
|
96
|
+
|
97
|
+
|
98
|
+
def compress_model(func: object):
|
99
|
+
from openvino._offline_transformations import \
|
100
|
+
compress_model_transformation # pylint: disable=import-error,no-name-in-module
|
101
|
+
compress_model_transformation(func)
|
102
|
+
|
103
|
+
|
104
|
+
def apply_fused_names_cleanup(func: object):
|
105
|
+
from openvino._offline_transformations import \
|
106
|
+
apply_fused_names_cleanup # pylint: disable=import-error,no-name-in-module
|
107
|
+
apply_fused_names_cleanup(func)
|