bigdl-core-npu 2.5.0__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-2.5.0.dist-info/METADATA +35 -0
- bigdl_core_npu-2.5.0.dist-info/RECORD +223 -0
- bigdl_core_npu-2.5.0.dist-info/WHEEL +5 -0
- bigdl_core_npu-2.5.0.dist-info/top_level.txt +1 -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 +215 -0
- intel_npu_acceleration_library/backend/bindings.py +279 -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 +944 -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 +141 -0
- intel_npu_acceleration_library/backend/qlinear.py +71 -0
- intel_npu_acceleration_library/backend/qmatmul.py +66 -0
- intel_npu_acceleration_library/backend/runtime.py +210 -0
- intel_npu_acceleration_library/backend/sdpa.py +107 -0
- intel_npu_acceleration_library/backend/tensor.py +1050 -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 +122 -0
- intel_npu_acceleration_library/external/openvino/__init__.py +71 -0
- intel_npu_acceleration_library/external/openvino/_offline_transformations/__init__.py +20 -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/frontend/__init__.py +34 -0
- intel_npu_acceleration_library/external/openvino/frontend/frontend.py +44 -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 +352 -0
- intel_npu_acceleration_library/external/openvino/frontend/pytorch/gptq.py +139 -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 +98 -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 +119 -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 +289 -0
- intel_npu_acceleration_library/external/openvino/frontend/pytorch/torchdynamo/partition.py +118 -0
- intel_npu_acceleration_library/external/openvino/frontend/pytorch/ts_decoder.py +536 -0
- intel_npu_acceleration_library/external/openvino/frontend/pytorch/utils.py +256 -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 +460 -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 +26 -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 +4 -0
- intel_npu_acceleration_library/external/openvino/preprocess/torchvision/torchvision_preprocessing.py +347 -0
- intel_npu_acceleration_library/external/openvino/properties/__init__.py +21 -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 +18 -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 +3067 -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 +399 -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 +10 -0
- intel_npu_acceleration_library/external/openvino/runtime/opset15/ops.py +85 -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 +189 -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 +783 -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 +38 -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 +429 -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 +70 -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 +536 -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 +35 -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/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 +246 -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 +205 -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 +109 -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 +98 -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,70 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# Copyright (C) 2018-2024 Intel Corporation
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
4
|
+
|
5
|
+
from functools import wraps
|
6
|
+
from inspect import getfullargspec
|
7
|
+
from typing import Any, Callable, List, Optional
|
8
|
+
|
9
|
+
from openvino.runtime import Node, Output
|
10
|
+
from openvino.runtime.utils.types import NodeInput, as_node, as_nodes
|
11
|
+
|
12
|
+
|
13
|
+
def _get_name(**kwargs: Any) -> Node:
|
14
|
+
if "name" in kwargs:
|
15
|
+
return kwargs["name"]
|
16
|
+
return None
|
17
|
+
|
18
|
+
|
19
|
+
def _set_node_friendly_name(node: Node, *, name: Optional[str] = None) -> Node:
|
20
|
+
if name is not None:
|
21
|
+
node.friendly_name = name
|
22
|
+
return node
|
23
|
+
|
24
|
+
|
25
|
+
def nameable_op(node_factory_function: Callable) -> Callable:
|
26
|
+
"""Set the name to the openvino operator returned by the wrapped function."""
|
27
|
+
|
28
|
+
@wraps(node_factory_function)
|
29
|
+
def wrapper(*args: Any, **kwargs: Any) -> Node:
|
30
|
+
node = node_factory_function(*args, **kwargs)
|
31
|
+
node = _set_node_friendly_name(node, name=_get_name(**kwargs))
|
32
|
+
return node
|
33
|
+
|
34
|
+
return wrapper
|
35
|
+
|
36
|
+
|
37
|
+
def unary_op(node_factory_function: Callable) -> Callable:
|
38
|
+
"""Convert the first input value to a Constant Node if a numeric value is detected."""
|
39
|
+
|
40
|
+
@wraps(node_factory_function)
|
41
|
+
def wrapper(input_value: NodeInput, *args: Any, **kwargs: Any) -> Node:
|
42
|
+
input_node = as_node(input_value, name=_get_name(**kwargs))
|
43
|
+
node = node_factory_function(input_node, *args, **kwargs)
|
44
|
+
node = _set_node_friendly_name(node, name=_get_name(**kwargs))
|
45
|
+
return node
|
46
|
+
|
47
|
+
return wrapper
|
48
|
+
|
49
|
+
|
50
|
+
def binary_op(node_factory_function: Callable) -> Callable:
|
51
|
+
"""Convert the first two input values to Constant Nodes if numeric values are detected."""
|
52
|
+
|
53
|
+
@wraps(node_factory_function)
|
54
|
+
def wrapper(left: NodeInput, right: NodeInput, *args: Any, **kwargs: Any) -> Node:
|
55
|
+
left, right = as_nodes(left, right, name=_get_name(**kwargs))
|
56
|
+
node = node_factory_function(left, right, *args, **kwargs)
|
57
|
+
node = _set_node_friendly_name(node, name=_get_name(**kwargs))
|
58
|
+
return node
|
59
|
+
|
60
|
+
return wrapper
|
61
|
+
|
62
|
+
|
63
|
+
def custom_preprocess_function(custom_function: Callable) -> Callable:
|
64
|
+
"""Convert Node returned from custom_function to Output."""
|
65
|
+
|
66
|
+
@wraps(custom_function)
|
67
|
+
def wrapper(node: Node) -> Output:
|
68
|
+
return Output._from_node(custom_function(node))
|
69
|
+
|
70
|
+
return wrapper
|
@@ -0,0 +1,133 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# Copyright (C) 2018-2024 Intel Corporation
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
4
|
+
|
5
|
+
"""Helper functions for validating user input."""
|
6
|
+
|
7
|
+
import logging
|
8
|
+
from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Type
|
9
|
+
|
10
|
+
import numpy as np
|
11
|
+
|
12
|
+
from openvino.runtime.exceptions import UserInputError
|
13
|
+
|
14
|
+
log = logging.getLogger(__name__)
|
15
|
+
|
16
|
+
|
17
|
+
def assert_list_of_ints(value_list: Iterable[int], message: str) -> None:
|
18
|
+
"""Verify that the provided value is an iterable of integers."""
|
19
|
+
try:
|
20
|
+
for value in value_list:
|
21
|
+
if not isinstance(value, int):
|
22
|
+
raise TypeError
|
23
|
+
except TypeError:
|
24
|
+
log.warning(message)
|
25
|
+
raise UserInputError(message, value_list)
|
26
|
+
|
27
|
+
|
28
|
+
def _check_value(op_name, attr_key, value, val_type, cond=None):
|
29
|
+
# type: (str, str, Any, Type, Optional[Callable[[Any], bool]]) -> bool
|
30
|
+
"""Check whether provided value satisfies specified criteria.
|
31
|
+
|
32
|
+
:param op_name: The operator name which attributes are checked.
|
33
|
+
:param attr_key: The attribute name.
|
34
|
+
:param value: The value to check.
|
35
|
+
:param val_type: Required value type.
|
36
|
+
:param cond: The optional function running additional checks.
|
37
|
+
|
38
|
+
:raises UserInputError:
|
39
|
+
|
40
|
+
returns: True if attribute satisfies all criterias. Otherwise False.
|
41
|
+
"""
|
42
|
+
if not np.issubdtype(type(value), val_type):
|
43
|
+
raise UserInputError(
|
44
|
+
f'{op_name} operator attribute "{attr_key}" value must by of type {val_type}.',
|
45
|
+
)
|
46
|
+
if cond is not None and not cond(value):
|
47
|
+
raise UserInputError(
|
48
|
+
f'{op_name} operator attribute "{attr_key}" value does not satisfy provided condition.',
|
49
|
+
)
|
50
|
+
return True
|
51
|
+
|
52
|
+
|
53
|
+
def check_valid_attribute(op_name, attr_dict, attr_key, val_type, cond=None, required=False):
|
54
|
+
# type: (str, dict, str, Type, Optional[Callable[[Any], bool]], Optional[bool]) -> bool
|
55
|
+
"""Check whether specified attribute satisfies given criteria.
|
56
|
+
|
57
|
+
:param op_name: The operator name which attributes are checked.
|
58
|
+
:param attr_dict: Dictionary containing key-value attributes to check.
|
59
|
+
:param attr_key: Key value for validated attribute.
|
60
|
+
:param val_type: Value type for validated attribute.
|
61
|
+
:param cond: Any callable wich accept attribute value and returns True or False.
|
62
|
+
:param required: Whether provided attribute key is not required. This mean it may be missing
|
63
|
+
from provided dictionary.
|
64
|
+
|
65
|
+
:raises UserInputError:
|
66
|
+
|
67
|
+
returns True if attribute satisfies all criterias. Otherwise False.
|
68
|
+
"""
|
69
|
+
result = True
|
70
|
+
|
71
|
+
if required and attr_key not in attr_dict:
|
72
|
+
raise UserInputError(
|
73
|
+
f'Provided dictionary is missing {op_name} operator required attribute "{attr_key}"',
|
74
|
+
)
|
75
|
+
|
76
|
+
if attr_key not in attr_dict:
|
77
|
+
return result
|
78
|
+
|
79
|
+
attr_value = attr_dict[attr_key]
|
80
|
+
|
81
|
+
if np.isscalar(attr_value):
|
82
|
+
result = result and _check_value(op_name, attr_key, attr_value, val_type, cond)
|
83
|
+
else:
|
84
|
+
for value in attr_value:
|
85
|
+
result = result and _check_value(op_name, attr_key, value, val_type, cond)
|
86
|
+
|
87
|
+
return result
|
88
|
+
|
89
|
+
|
90
|
+
def check_valid_attributes(
|
91
|
+
op_name, # type: str
|
92
|
+
attributes, # type: Dict[str, Any]
|
93
|
+
requirements, # type: List[Tuple[str, bool, Type, Optional[Callable]]]
|
94
|
+
):
|
95
|
+
# type: (...) -> bool
|
96
|
+
"""Perform attributes validation according to specified type, value criteria.
|
97
|
+
|
98
|
+
:param op_name: The operator name which attributes are checked.
|
99
|
+
:param attributes: The dictionary with user provided attributes to check.
|
100
|
+
:param requirements: The list of tuples describing attributes' requirements. The tuple should
|
101
|
+
contain following values:
|
102
|
+
(attr_name: str,
|
103
|
+
is_required: bool,
|
104
|
+
value_type: Type,
|
105
|
+
value_condition: Callable)
|
106
|
+
|
107
|
+
:raises UserInputError:
|
108
|
+
|
109
|
+
:returns True if all attributes satisfies criterias. Otherwise False.
|
110
|
+
"""
|
111
|
+
for attr, required, val_type, cond in requirements:
|
112
|
+
check_valid_attribute(op_name, attributes, attr, val_type, cond, required)
|
113
|
+
return True
|
114
|
+
|
115
|
+
|
116
|
+
def is_positive_value(value): # type: (Any) -> bool
|
117
|
+
"""Determine whether the specified x is positive value.
|
118
|
+
|
119
|
+
:param value: The value to check.
|
120
|
+
|
121
|
+
returns True if the specified x is positive value, False otherwise.
|
122
|
+
"""
|
123
|
+
return value > 0
|
124
|
+
|
125
|
+
|
126
|
+
def is_non_negative_value(value): # type: (Any) -> bool
|
127
|
+
"""Determine whether the specified x is non-negative value.
|
128
|
+
|
129
|
+
:param value: The value to check.
|
130
|
+
|
131
|
+
returns True if the specified x is non-negative value, False otherwise.
|
132
|
+
"""
|
133
|
+
return value >= 0
|
@@ -0,0 +1,127 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# Copyright (C) 2018-2024 Intel Corporation
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
4
|
+
|
5
|
+
import logging as log
|
6
|
+
|
7
|
+
from functools import partial, singledispatchmethod
|
8
|
+
from typing import Any, Dict, List, Optional, Union
|
9
|
+
from pathlib import Path
|
10
|
+
|
11
|
+
from openvino._pyopenvino import NodeFactory as _NodeFactory
|
12
|
+
|
13
|
+
from openvino.runtime import Node, Output, Extension
|
14
|
+
|
15
|
+
from openvino.runtime.exceptions import UserInputError
|
16
|
+
|
17
|
+
DEFAULT_OPSET = "opset13"
|
18
|
+
|
19
|
+
|
20
|
+
class NodeFactory(object):
|
21
|
+
"""Factory front-end to create node objects."""
|
22
|
+
|
23
|
+
def __init__(self, opset_version: str = DEFAULT_OPSET) -> None:
|
24
|
+
"""Create the NodeFactory object.
|
25
|
+
|
26
|
+
:param opset_version: The opset version the factory will use to produce ops from.
|
27
|
+
"""
|
28
|
+
self.factory = _NodeFactory(opset_version)
|
29
|
+
|
30
|
+
def create(
|
31
|
+
self,
|
32
|
+
op_type_name: str,
|
33
|
+
arguments: Optional[List[Union[Node, Output]]] = None,
|
34
|
+
attributes: Optional[Dict[str, Any]] = None,
|
35
|
+
) -> Node:
|
36
|
+
"""Create node object from provided description.
|
37
|
+
|
38
|
+
The user does not have to provide all node's attributes, but only required ones.
|
39
|
+
|
40
|
+
:param op_type_name: The operator type name.
|
41
|
+
:param arguments: The operator arguments.
|
42
|
+
:param attributes: The operator attributes.
|
43
|
+
|
44
|
+
:return: Node object representing requested operator with attributes set.
|
45
|
+
"""
|
46
|
+
if arguments is None and attributes is None:
|
47
|
+
node = self.factory.create(op_type_name)
|
48
|
+
return node
|
49
|
+
|
50
|
+
if arguments is None and attributes is not None:
|
51
|
+
raise UserInputError(f'Error: cannot create "{op_type_name}" op without arguments.')
|
52
|
+
|
53
|
+
if attributes is None:
|
54
|
+
attributes = {}
|
55
|
+
|
56
|
+
assert arguments is not None
|
57
|
+
|
58
|
+
arguments = self._arguments_as_outputs(arguments)
|
59
|
+
node = self.factory.create(op_type_name, arguments, attributes)
|
60
|
+
|
61
|
+
return node
|
62
|
+
|
63
|
+
@singledispatchmethod
|
64
|
+
def add_extension(self, extension: Union[Path, str, Extension, List[Extension]]) -> None:
|
65
|
+
raise TypeError(f"Unknown argument type: {type(extension)}")
|
66
|
+
|
67
|
+
@add_extension.register(Path)
|
68
|
+
@add_extension.register(str)
|
69
|
+
def _(self, lib_path: Union[Path, str]) -> None:
|
70
|
+
"""Add custom operations from an extension.
|
71
|
+
|
72
|
+
Extends operation types available for creation by operations
|
73
|
+
loaded from prebuilt C++ library. Enables instantiation of custom
|
74
|
+
operations exposed in that library without direct use of
|
75
|
+
operation classes. Other types of extensions, e.g. conversion
|
76
|
+
extensions, if they are exposed in the library, are ignored.
|
77
|
+
|
78
|
+
In case if an extension operation type from the extension match
|
79
|
+
one of existing operations registered before (from the standard
|
80
|
+
OpenVINO opset or from another extension loaded earlier), a new
|
81
|
+
operation overrides an old operation.
|
82
|
+
|
83
|
+
Version of an operation is ignored: an operation with a given type and
|
84
|
+
a given version/opset will override operation with the same type but
|
85
|
+
different version/opset in the same NodeFactory instance.
|
86
|
+
Use separate libraries and NodeFactory instances to differentiate
|
87
|
+
versions/opsets.
|
88
|
+
|
89
|
+
:param lib_path: A path to the library with extension.
|
90
|
+
"""
|
91
|
+
self.factory.add_extension(lib_path)
|
92
|
+
|
93
|
+
@add_extension.register(Extension)
|
94
|
+
@add_extension.register(list)
|
95
|
+
def _(self, extension: Union[Extension, List[Extension]]) -> None:
|
96
|
+
"""Add custom operations from extension library.
|
97
|
+
|
98
|
+
Extends operation types available for creation by operations
|
99
|
+
loaded from prebuilt C++ library. Enables instantiation of custom
|
100
|
+
operations exposed in that library without direct use of
|
101
|
+
operation classes. Other types of extensions, e.g. conversion
|
102
|
+
extensions, if they are exposed in the library, are ignored.
|
103
|
+
|
104
|
+
In case if an extension operation type from a library match
|
105
|
+
one of existing operations registered before (from the standard
|
106
|
+
OpenVINO opset or from another extension loaded earlier), a new
|
107
|
+
operation overrides an old operation.
|
108
|
+
|
109
|
+
Version of an operation is ignored: an operation with a given type and
|
110
|
+
a given version/opset will override operation with the same type but
|
111
|
+
different version/opset in the same NodeFactory instance.
|
112
|
+
Use separate libraries and NodeFactory instances to differentiate
|
113
|
+
versions/opsets.
|
114
|
+
|
115
|
+
:param extension: A single Extension or list of Extensions.
|
116
|
+
"""
|
117
|
+
self.factory.add_extension(extension)
|
118
|
+
|
119
|
+
@staticmethod
|
120
|
+
def _arguments_as_outputs(arguments: List[Union[Node, Output]]) -> List[Output]:
|
121
|
+
outputs = []
|
122
|
+
for argument in arguments:
|
123
|
+
if issubclass(type(argument), Output):
|
124
|
+
outputs.append(argument)
|
125
|
+
else:
|
126
|
+
outputs.extend(argument.outputs())
|
127
|
+
return outputs
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# Copyright (C) 2018-2024 Intel Corporation
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
4
|
+
|
5
|
+
from typing import Iterable, Optional
|
6
|
+
|
7
|
+
from openvino.runtime import Node
|
8
|
+
|
9
|
+
|
10
|
+
def get_reduction_axes(node: Node, reduction_axes: Optional[Iterable[int]]) -> Iterable[int]:
|
11
|
+
"""Get reduction axes if it is None and convert it to set if its type is different.
|
12
|
+
|
13
|
+
If reduction_axes is None we default to reduce all axes.
|
14
|
+
|
15
|
+
:param node: The node we fill reduction axes for.
|
16
|
+
:param reduction_axes: The collection of indices of axes to reduce. May be None.
|
17
|
+
|
18
|
+
returns: Set filled with indices of axes we want to reduce.
|
19
|
+
"""
|
20
|
+
if reduction_axes is None:
|
21
|
+
reduction_axes = set(range(len(node.shape)))
|
22
|
+
|
23
|
+
if type(reduction_axes) is not set:
|
24
|
+
reduction_axes = set(reduction_axes)
|
25
|
+
return reduction_axes
|
@@ -0,0 +1,175 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# Copyright (C) 2018-2024 Intel Corporation
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
4
|
+
|
5
|
+
"""Functions related to converting between Python and numpy types and openvino types."""
|
6
|
+
|
7
|
+
import logging
|
8
|
+
from typing import List, Union, Optional
|
9
|
+
|
10
|
+
import numpy as np
|
11
|
+
|
12
|
+
from openvino.runtime.exceptions import OVTypeError
|
13
|
+
from openvino.runtime import Node, Shape, Output, Type
|
14
|
+
from openvino.runtime.op import Constant
|
15
|
+
|
16
|
+
log = logging.getLogger(__name__)
|
17
|
+
|
18
|
+
TensorShape = List[int]
|
19
|
+
NumericData = Union[int, float, np.ndarray]
|
20
|
+
NumericType = Union[type, np.dtype]
|
21
|
+
ScalarData = Union[int, float]
|
22
|
+
NodeInput = Union[Node, NumericData]
|
23
|
+
|
24
|
+
openvino_to_numpy_types_map = [
|
25
|
+
(Type.boolean, bool),
|
26
|
+
(Type.boolean, np.bool_),
|
27
|
+
(Type.f16, np.float16),
|
28
|
+
(Type.f32, np.float32),
|
29
|
+
(Type.f64, np.float64),
|
30
|
+
(Type.i8, np.int8),
|
31
|
+
(Type.i16, np.int16),
|
32
|
+
(Type.i32, np.int32),
|
33
|
+
(Type.i64, np.int64),
|
34
|
+
(Type.u8, np.uint8),
|
35
|
+
(Type.u16, np.uint16),
|
36
|
+
(Type.u32, np.uint32),
|
37
|
+
(Type.u64, np.uint64),
|
38
|
+
(Type.bf16, np.uint16),
|
39
|
+
(Type.string, str),
|
40
|
+
(Type.string, np.str_),
|
41
|
+
(Type.string, bytes),
|
42
|
+
(Type.string, np.bytes_),
|
43
|
+
]
|
44
|
+
|
45
|
+
openvino_to_numpy_types_str_map = [
|
46
|
+
("boolean", bool),
|
47
|
+
("boolean", np.bool_),
|
48
|
+
("f16", np.float16),
|
49
|
+
("f32", np.float32),
|
50
|
+
("f64", np.float64),
|
51
|
+
("i8", np.int8),
|
52
|
+
("i16", np.int16),
|
53
|
+
("i32", np.int32),
|
54
|
+
("i64", np.int64),
|
55
|
+
("u8", np.uint8),
|
56
|
+
("u16", np.uint16),
|
57
|
+
("u32", np.uint32),
|
58
|
+
("u64", np.uint64),
|
59
|
+
("string", str),
|
60
|
+
("string", np.str_),
|
61
|
+
("string", bytes),
|
62
|
+
("string", np.bytes_),
|
63
|
+
]
|
64
|
+
|
65
|
+
|
66
|
+
def get_element_type(data_type: NumericType) -> Type:
|
67
|
+
"""Return an ngraph element type for a Python type or numpy.dtype."""
|
68
|
+
if data_type is int:
|
69
|
+
log.warning("Converting int type of undefined bitwidth to 32-bit ngraph integer.")
|
70
|
+
return Type.i32
|
71
|
+
|
72
|
+
if data_type is float:
|
73
|
+
log.warning("Converting float type of undefined bitwidth to 32-bit ngraph float.")
|
74
|
+
return Type.f32
|
75
|
+
|
76
|
+
ov_type = next(
|
77
|
+
(ov_type for (ov_type, np_type) in openvino_to_numpy_types_map if np_type == data_type),
|
78
|
+
None,
|
79
|
+
)
|
80
|
+
if ov_type:
|
81
|
+
return ov_type
|
82
|
+
|
83
|
+
raise OVTypeError("Unidentified data type %s", data_type)
|
84
|
+
|
85
|
+
|
86
|
+
def get_element_type_str(data_type: NumericType) -> str:
|
87
|
+
"""Return an ngraph element type string representation for a Python type or numpy dtype."""
|
88
|
+
if data_type is int:
|
89
|
+
log.warning("Converting int type of undefined bitwidth to 32-bit ngraph integer.")
|
90
|
+
return "i32"
|
91
|
+
|
92
|
+
if data_type is float:
|
93
|
+
log.warning("Converting float type of undefined bitwidth to 32-bit ngraph float.")
|
94
|
+
return "f32"
|
95
|
+
|
96
|
+
ov_type = next(
|
97
|
+
(ov_type for (ov_type, np_type) in openvino_to_numpy_types_str_map if np_type == data_type),
|
98
|
+
None,
|
99
|
+
)
|
100
|
+
if ov_type:
|
101
|
+
return ov_type
|
102
|
+
|
103
|
+
raise OVTypeError("Unidentified data type %s", data_type)
|
104
|
+
|
105
|
+
|
106
|
+
def get_dtype(openvino_type: Type) -> np.dtype:
|
107
|
+
"""Return a numpy.dtype for an openvino element type."""
|
108
|
+
np_type = next(
|
109
|
+
(np_type for (ov_type, np_type) in openvino_to_numpy_types_map if ov_type == openvino_type),
|
110
|
+
None,
|
111
|
+
)
|
112
|
+
|
113
|
+
if np_type:
|
114
|
+
return np.dtype(np_type)
|
115
|
+
|
116
|
+
raise OVTypeError("Unidentified data type %s", openvino_type)
|
117
|
+
|
118
|
+
|
119
|
+
def get_numpy_ctype(openvino_type: Type) -> type:
|
120
|
+
"""Return numpy ctype for an openvino element type."""
|
121
|
+
np_type = next(
|
122
|
+
(np_type for (ov_type, np_type) in openvino_to_numpy_types_map if ov_type == openvino_type),
|
123
|
+
None,
|
124
|
+
)
|
125
|
+
|
126
|
+
if np_type:
|
127
|
+
return np_type
|
128
|
+
|
129
|
+
raise OVTypeError("Unidentified data type %s", openvino_type)
|
130
|
+
|
131
|
+
|
132
|
+
def get_ndarray(data: NumericData) -> np.ndarray:
|
133
|
+
"""Wrap data into a numpy ndarray."""
|
134
|
+
if isinstance(data, np.ndarray):
|
135
|
+
return data # type: ignore
|
136
|
+
return np.array(data)
|
137
|
+
|
138
|
+
|
139
|
+
def get_shape(data: NumericData) -> TensorShape:
|
140
|
+
"""Return a shape of NumericData."""
|
141
|
+
if isinstance(data, np.ndarray):
|
142
|
+
return data.shape # type: ignore
|
143
|
+
if isinstance(data, list):
|
144
|
+
return [len(data)] # type: ignore
|
145
|
+
return []
|
146
|
+
|
147
|
+
|
148
|
+
def make_constant_node(value: NumericData, dtype: Union[NumericType, Type] = None, *, name: Optional[str] = None) -> Constant:
|
149
|
+
"""Return an openvino Constant node with the specified value."""
|
150
|
+
ndarray = get_ndarray(value)
|
151
|
+
if dtype is not None:
|
152
|
+
element_type = get_element_type(dtype) if isinstance(dtype, (type, np.dtype)) else dtype
|
153
|
+
else:
|
154
|
+
element_type = get_element_type(ndarray.dtype)
|
155
|
+
|
156
|
+
const = Constant(element_type, Shape(ndarray.shape), ndarray.flatten().tolist())
|
157
|
+
|
158
|
+
if name:
|
159
|
+
const.friendly_name = name + "/" + const.friendly_name
|
160
|
+
|
161
|
+
return const
|
162
|
+
|
163
|
+
|
164
|
+
def as_node(input_value: NodeInput, name: Optional[str] = None) -> Node:
|
165
|
+
"""Return input values as nodes. Scalars will be converted to Constant nodes."""
|
166
|
+
if issubclass(type(input_value), Node):
|
167
|
+
return input_value
|
168
|
+
if issubclass(type(input_value), Output):
|
169
|
+
return input_value
|
170
|
+
return make_constant_node(input_value, name=name)
|
171
|
+
|
172
|
+
|
173
|
+
def as_nodes(*input_values: NodeInput, name: Optional[str] = None) -> List[Node]:
|
174
|
+
"""Return input values as nodes. Scalars will be converted to Constant nodes."""
|
175
|
+
return [as_node(input_value, name=name) for input_value in input_values]
|