uni-tensorflow 1.10.0__py3-none-any.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.
- uni/common/__init__.py +23 -0
- uni/common/core/__init__.py +23 -0
- uni/common/core/common.py +41 -0
- uni/common/core/connectivity_map.py +107 -0
- uni/common/core/error/__init__.py +25 -0
- uni/common/core/error/defs.py +132 -0
- uni/common/core/error/util.py +70 -0
- uni/common/core/multigraph/__init__.py +23 -0
- uni/common/core/multigraph/edge.py +53 -0
- uni/common/core/multigraph/graph.py +440 -0
- uni/common/core/multigraph/node_graph_api.py +127 -0
- uni/common/core/multigraph/typing.py +59 -0
- uni/common/core/nnir_graph/__init__.py +24 -0
- uni/common/core/nnir_graph/nnir_edge.py +31 -0
- uni/common/core/nnir_graph/nnir_graph.py +85 -0
- uni/common/core/nnir_graph/nnir_nodes/__init__.py +76 -0
- uni/common/core/nnir_graph/nnir_nodes/abs.py +28 -0
- uni/common/core/nnir_graph/nnir_nodes/add.py +34 -0
- uni/common/core/nnir_graph/nnir_nodes/argmax.py +53 -0
- uni/common/core/nnir_graph/nnir_nodes/average_pool2d.py +85 -0
- uni/common/core/nnir_graph/nnir_nodes/batch_norm.py +60 -0
- uni/common/core/nnir_graph/nnir_nodes/binary_op.py +38 -0
- uni/common/core/nnir_graph/nnir_nodes/box_decode.py +77 -0
- uni/common/core/nnir_graph/nnir_nodes/broadcast.py +48 -0
- uni/common/core/nnir_graph/nnir_nodes/common.py +46 -0
- uni/common/core/nnir_graph/nnir_nodes/concat.py +50 -0
- uni/common/core/nnir_graph/nnir_nodes/conv2d.py +125 -0
- uni/common/core/nnir_graph/nnir_nodes/conv2dtranspose.py +95 -0
- uni/common/core/nnir_graph/nnir_nodes/div.py +27 -0
- uni/common/core/nnir_graph/nnir_nodes/dummy_node.py +44 -0
- uni/common/core/nnir_graph/nnir_nodes/equal.py +27 -0
- uni/common/core/nnir_graph/nnir_nodes/expand_dims.py +37 -0
- uni/common/core/nnir_graph/nnir_nodes/fully_connected.py +73 -0
- uni/common/core/nnir_graph/nnir_nodes/hard_sigmoid.py +57 -0
- uni/common/core/nnir_graph/nnir_nodes/hard_swish.py +33 -0
- uni/common/core/nnir_graph/nnir_nodes/identity.py +36 -0
- uni/common/core/nnir_graph/nnir_nodes/layer_norm.py +73 -0
- uni/common/core/nnir_graph/nnir_nodes/matmul.py +70 -0
- uni/common/core/nnir_graph/nnir_nodes/max.py +32 -0
- uni/common/core/nnir_graph/nnir_nodes/max_pool2d.py +82 -0
- uni/common/core/nnir_graph/nnir_nodes/min.py +32 -0
- uni/common/core/nnir_graph/nnir_nodes/mul.py +30 -0
- uni/common/core/nnir_graph/nnir_nodes/negative.py +28 -0
- uni/common/core/nnir_graph/nnir_nodes/nms.py +112 -0
- uni/common/core/nnir_graph/nnir_nodes/nnir_node.py +323 -0
- uni/common/core/nnir_graph/nnir_nodes/output.py +40 -0
- uni/common/core/nnir_graph/nnir_nodes/pad.py +71 -0
- uni/common/core/nnir_graph/nnir_nodes/placeholder.py +55 -0
- uni/common/core/nnir_graph/nnir_nodes/prelu.py +38 -0
- uni/common/core/nnir_graph/nnir_nodes/quant.py +35 -0
- uni/common/core/nnir_graph/nnir_nodes/reduce_ops.py +74 -0
- uni/common/core/nnir_graph/nnir_nodes/relu_x.py +42 -0
- uni/common/core/nnir_graph/nnir_nodes/reshape.py +76 -0
- uni/common/core/nnir_graph/nnir_nodes/resize.py +87 -0
- uni/common/core/nnir_graph/nnir_nodes/rsqrt.py +28 -0
- uni/common/core/nnir_graph/nnir_nodes/sigmoid.py +28 -0
- uni/common/core/nnir_graph/nnir_nodes/slice.py +52 -0
- uni/common/core/nnir_graph/nnir_nodes/softmax.py +51 -0
- uni/common/core/nnir_graph/nnir_nodes/split.py +62 -0
- uni/common/core/nnir_graph/nnir_nodes/sqrt.py +28 -0
- uni/common/core/nnir_graph/nnir_nodes/squeeze.py +36 -0
- uni/common/core/nnir_graph/nnir_nodes/ssd_post_process.py +188 -0
- uni/common/core/nnir_graph/nnir_nodes/stack.py +54 -0
- uni/common/core/nnir_graph/nnir_nodes/strided_slice.py +77 -0
- uni/common/core/nnir_graph/nnir_nodes/sub.py +27 -0
- uni/common/core/nnir_graph/nnir_nodes/swish.py +33 -0
- uni/common/core/nnir_graph/nnir_nodes/tanh.py +28 -0
- uni/common/core/nnir_graph/nnir_nodes/topk.py +41 -0
- uni/common/core/nnir_graph/nnir_nodes/topk_gather.py +67 -0
- uni/common/core/nnir_graph/nnir_nodes/transpose.py +58 -0
- uni/common/core/nnir_graph/nnir_nodes/unstack.py +41 -0
- uni/common/core/nnir_graph/nnir_nodes/variable.py +57 -0
- uni/common/core/nnir_graph/nnir_nodes/weights_bias_node_base.py +110 -0
- uni/common/core/nnir_graph/nnir_substitution/__init__.py +28 -0
- uni/common/core/nnir_graph/nnir_substitution/absorb_quant_substitution.py +77 -0
- uni/common/core/nnir_graph/nnir_substitution/merge_fully_connected_add_substitution.py +84 -0
- uni/common/core/nnir_graph/nnir_substitution/nnir_substitute_base.py +87 -0
- uni/common/core/nnir_graph/nnir_substitution/remove_dummy_nodes_substitution.py +52 -0
- uni/common/core/nnir_graph/nnir_substitution/remove_identity_like_substitution.py +72 -0
- uni/common/core/nnir_graph/nnir_substitution/rsqrt_substitution.py +77 -0
- uni/common/core/nnir_graph/nnir_substitution/single_nodes_substitution.py +71 -0
- uni/common/core/nnir_graph/nnir_substitution/substitution_manager.py +63 -0
- uni/common/core/nnir_graph/quant_info/__init__.py +25 -0
- uni/common/core/nnir_graph/quant_info/lut_per_channel_quant_info.py +55 -0
- uni/common/core/nnir_graph/quant_info/lut_quant_info.py +52 -0
- uni/common/core/nnir_graph/quant_info/quant_info_base.py +29 -0
- uni/common/core/nnir_graph/quant_info/quant_per_channel_base.py +27 -0
- uni/common/core/nnir_graph/quant_info/symmetric_per_channel_quant_info.py +48 -0
- uni/common/core/nnir_graph/quant_info/symmetric_quant_info.py +45 -0
- uni/common/core/nnir_graph/quant_info/uniform_quant_info.py +47 -0
- uni/common/core/nnir_graph/semantics.py +227 -0
- uni/common/core/node_history.py +31 -0
- uni/common/core/uid_generator.py +43 -0
- uni/common/exit_code.py +31 -0
- uni/common/exporters/__init__.py +23 -0
- uni/common/exporters/uni_model/__init__.py +18 -0
- uni/common/exporters/uni_model/uni_model_exporter.py +87 -0
- uni/common/exporters/uni_model/util.py +26 -0
- uni/common/logger.py +254 -0
- uni/common/main.py +175 -0
- uni/common/parsers/__init__.py +23 -0
- uni/common/parsers/_pad_util.py +68 -0
- uni/common/parsers/base_parser.py +188 -0
- uni/common/parsers/base_reader.py +128 -0
- uni/common/util/__init__.py +23 -0
- uni/common/util/dev.py +44 -0
- uni/common/util/vis.py +143 -0
- uni/tensorflow/__init__.py +23 -0
- uni/tensorflow/keras_import_util.py +33 -0
- uni/tensorflow/main.py +42 -0
- uni/tensorflow/tf_parser/__init__.py +23 -0
- uni/tensorflow/tf_parser/nnir_node_factory/__init__.py +52 -0
- uni/tensorflow/tf_parser/nnir_node_factory/_conv2d_base.py +134 -0
- uni/tensorflow/tf_parser/nnir_node_factory/_op2d_mixin.py +63 -0
- uni/tensorflow/tf_parser/nnir_node_factory/_op_activation_mixin.py +70 -0
- uni/tensorflow/tf_parser/nnir_node_factory/_op_weights_bias_mixin.py +114 -0
- uni/tensorflow/tf_parser/nnir_node_factory/activation_factory.py +72 -0
- uni/tensorflow/tf_parser/nnir_node_factory/batch_norm_factory.py +68 -0
- uni/tensorflow/tf_parser/nnir_node_factory/binary_op_factory.py +93 -0
- uni/tensorflow/tf_parser/nnir_node_factory/concat_factory.py +33 -0
- uni/tensorflow/tf_parser/nnir_node_factory/conv2d_factory.py +41 -0
- uni/tensorflow/tf_parser/nnir_node_factory/conv2dtranspose_factory.py +81 -0
- uni/tensorflow/tf_parser/nnir_node_factory/custom/__init__.py +25 -0
- uni/tensorflow/tf_parser/nnir_node_factory/custom/box_decode_factory.py +47 -0
- uni/tensorflow/tf_parser/nnir_node_factory/custom/ssd_post_process_factory.py +63 -0
- uni/tensorflow/tf_parser/nnir_node_factory/dense_factory.py +58 -0
- uni/tensorflow/tf_parser/nnir_node_factory/depthwise_conv2d_factory.py +78 -0
- uni/tensorflow/tf_parser/nnir_node_factory/dropout_factory.py +42 -0
- uni/tensorflow/tf_parser/nnir_node_factory/dummy_output_factory.py +34 -0
- uni/tensorflow/tf_parser/nnir_node_factory/flatten_factory.py +35 -0
- uni/tensorflow/tf_parser/nnir_node_factory/global_pool_factories.py +69 -0
- uni/tensorflow/tf_parser/nnir_node_factory/identity_factory.py +39 -0
- uni/tensorflow/tf_parser/nnir_node_factory/layer_norm_factory.py +66 -0
- uni/tensorflow/tf_parser/nnir_node_factory/leaky_relu_factory.py +38 -0
- uni/tensorflow/tf_parser/nnir_node_factory/mct_quantizers_nodes/__init__.py +23 -0
- uni/tensorflow/tf_parser/nnir_node_factory/mct_quantizers_nodes/keras_activation_quantization_holder_factory.py +52 -0
- uni/tensorflow/tf_parser/nnir_node_factory/mct_quantizers_nodes/keras_quantization_wrapper_factory.py +164 -0
- uni/tensorflow/tf_parser/nnir_node_factory/mct_quantizers_nodes/tf_mct_factory_base.py +36 -0
- uni/tensorflow/tf_parser/nnir_node_factory/native_slice_factory.py +99 -0
- uni/tensorflow/tf_parser/nnir_node_factory/output_factory.py +35 -0
- uni/tensorflow/tf_parser/nnir_node_factory/permute_factory.py +38 -0
- uni/tensorflow/tf_parser/nnir_node_factory/placeholder_factory.py +41 -0
- uni/tensorflow/tf_parser/nnir_node_factory/pool_factories.py +69 -0
- uni/tensorflow/tf_parser/nnir_node_factory/relu_factory.py +70 -0
- uni/tensorflow/tf_parser/nnir_node_factory/reshape_factory.py +37 -0
- uni/tensorflow/tf_parser/nnir_node_factory/resize_factory_base.py +61 -0
- uni/tensorflow/tf_parser/nnir_node_factory/resizing_factory.py +48 -0
- uni/tensorflow/tf_parser/nnir_node_factory/softmax_factory.py +44 -0
- uni/tensorflow/tf_parser/nnir_node_factory/tf_node_factory.py +118 -0
- uni/tensorflow/tf_parser/nnir_node_factory/tf_op_lambda_factory/__init__.py +24 -0
- uni/tensorflow/tf_parser/nnir_node_factory/tf_op_lambda_factory/abs_factory.py +32 -0
- uni/tensorflow/tf_parser/nnir_node_factory/tf_op_lambda_factory/argmax_factory.py +35 -0
- uni/tensorflow/tf_parser/nnir_node_factory/tf_op_lambda_factory/binary_op_factory.py +132 -0
- uni/tensorflow/tf_parser/nnir_node_factory/tf_op_lambda_factory/broadcast_to_factory.py +35 -0
- uni/tensorflow/tf_parser/nnir_node_factory/tf_op_lambda_factory/cast_factory.py +55 -0
- uni/tensorflow/tf_parser/nnir_node_factory/tf_op_lambda_factory/combined_nms_factory.py +62 -0
- uni/tensorflow/tf_parser/nnir_node_factory/tf_op_lambda_factory/concat_factory.py +34 -0
- uni/tensorflow/tf_parser/nnir_node_factory/tf_op_lambda_factory/expand_dims_factory.py +32 -0
- uni/tensorflow/tf_parser/nnir_node_factory/tf_op_lambda_factory/gather_factory.py +60 -0
- uni/tensorflow/tf_parser/nnir_node_factory/tf_op_lambda_factory/identity_factory.py +35 -0
- uni/tensorflow/tf_parser/nnir_node_factory/tf_op_lambda_factory/matmul_factory.py +54 -0
- uni/tensorflow/tf_parser/nnir_node_factory/tf_op_lambda_factory/negative_factory.py +32 -0
- uni/tensorflow/tf_parser/nnir_node_factory/tf_op_lambda_factory/pad_factory.py +53 -0
- uni/tensorflow/tf_parser/nnir_node_factory/tf_op_lambda_factory/reduce_factories.py +59 -0
- uni/tensorflow/tf_parser/nnir_node_factory/tf_op_lambda_factory/relu.py +36 -0
- uni/tensorflow/tf_parser/nnir_node_factory/tf_op_lambda_factory/relu6.py +36 -0
- uni/tensorflow/tf_parser/nnir_node_factory/tf_op_lambda_factory/reshape_factory.py +35 -0
- uni/tensorflow/tf_parser/nnir_node_factory/tf_op_lambda_factory/resize_factory.py +51 -0
- uni/tensorflow/tf_parser/nnir_node_factory/tf_op_lambda_factory/rsqrt_factory.py +32 -0
- uni/tensorflow/tf_parser/nnir_node_factory/tf_op_lambda_factory/sigmoid_factory.py +38 -0
- uni/tensorflow/tf_parser/nnir_node_factory/tf_op_lambda_factory/silu_factory.py +43 -0
- uni/tensorflow/tf_parser/nnir_node_factory/tf_op_lambda_factory/slice_factory.py +38 -0
- uni/tensorflow/tf_parser/nnir_node_factory/tf_op_lambda_factory/softmax_factory.py +41 -0
- uni/tensorflow/tf_parser/nnir_node_factory/tf_op_lambda_factory/split_factory.py +42 -0
- uni/tensorflow/tf_parser/nnir_node_factory/tf_op_lambda_factory/sqrt_factory.py +32 -0
- uni/tensorflow/tf_parser/nnir_node_factory/tf_op_lambda_factory/squeeze_factory.py +37 -0
- uni/tensorflow/tf_parser/nnir_node_factory/tf_op_lambda_factory/stack_factory.py +36 -0
- uni/tensorflow/tf_parser/nnir_node_factory/tf_op_lambda_factory/strided_slice_factory.py +57 -0
- uni/tensorflow/tf_parser/nnir_node_factory/tf_op_lambda_factory/tanh_factory.py +38 -0
- uni/tensorflow/tf_parser/nnir_node_factory/tf_op_lambda_factory/tf_op_lambda_dispatcher.py +147 -0
- uni/tensorflow/tf_parser/nnir_node_factory/tf_op_lambda_factory/tf_op_lambda_factory_base.py +123 -0
- uni/tensorflow/tf_parser/nnir_node_factory/tf_op_lambda_factory/top_k_factory.py +43 -0
- uni/tensorflow/tf_parser/nnir_node_factory/tf_op_lambda_factory/transpose_factory.py +43 -0
- uni/tensorflow/tf_parser/nnir_node_factory/tf_op_lambda_factory/unstack_factory.py +36 -0
- uni/tensorflow/tf_parser/nnir_node_factory/upsample2d_factory.py +47 -0
- uni/tensorflow/tf_parser/nnir_node_factory/zero_padding2d_factory.py +49 -0
- uni/tensorflow/tf_parser/tf_mct_reader_helper.py +80 -0
- uni/tensorflow/tf_parser/tf_meta_node.py +78 -0
- uni/tensorflow/tf_parser/tf_op_to_factory.py +87 -0
- uni/tensorflow/tf_parser/tf_parser.py +94 -0
- uni/tensorflow/tf_parser/tf_reader.py +294 -0
- uni/tensorflow/tf_parser/tf_reader_helper.py +155 -0
- uni/tensorflow/version.py +1 -0
- uni_tensorflow-1.10.0.dist-info/METADATA +14 -0
- uni_tensorflow-1.10.0.dist-info/RECORD +198 -0
- uni_tensorflow-1.10.0.dist-info/WHEEL +5 -0
- uni_tensorflow-1.10.0.dist-info/entry_points.txt +2 -0
- uni_tensorflow-1.10.0.dist-info/top_level.txt +1 -0
uni/common/__init__.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# -------------------------------------------------------------------------------
|
|
2
|
+
# (c) Copyright 2022 Sony Semiconductor Israel, Ltd. All rights reserved.
|
|
3
|
+
#
|
|
4
|
+
# This software, in source or object form (the "Software"), is the
|
|
5
|
+
# property of Sony Semiconductor Israel Ltd. (the "Company") and/or its
|
|
6
|
+
# licensors, which have all right, title and interest therein, You
|
|
7
|
+
# may use the Software only in accordance with the terms of written
|
|
8
|
+
# license agreement between you and the Company (the "License").
|
|
9
|
+
# Except as expressly stated in the License, the Company grants no
|
|
10
|
+
# licenses by implication, estoppel, or otherwise. If you are not
|
|
11
|
+
# aware of or do not agree to the License terms, you may not use,
|
|
12
|
+
# copy or modify the Software. You may use the source code of the
|
|
13
|
+
# Software only for your internal purposes and may not distribute the
|
|
14
|
+
# source code of the Software, any part thereof, or any derivative work
|
|
15
|
+
# thereof, to any third party, except pursuant to the Company's prior
|
|
16
|
+
# written consent.
|
|
17
|
+
# The Software is the confidential information of the Company.
|
|
18
|
+
# -------------------------------------------------------------------------------
|
|
19
|
+
"""
|
|
20
|
+
Created on 8/4/22
|
|
21
|
+
|
|
22
|
+
@author: irenab
|
|
23
|
+
"""
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# -------------------------------------------------------------------------------
|
|
2
|
+
# (c) Copyright 2022 Sony Semiconductor Israel, Ltd. All rights reserved.
|
|
3
|
+
#
|
|
4
|
+
# This software, in source or object form (the "Software"), is the
|
|
5
|
+
# property of Sony Semiconductor Israel Ltd. (the "Company") and/or its
|
|
6
|
+
# licensors, which have all right, title and interest therein, You
|
|
7
|
+
# may use the Software only in accordance with the terms of written
|
|
8
|
+
# license agreement between you and the Company (the "License").
|
|
9
|
+
# Except as expressly stated in the License, the Company grants no
|
|
10
|
+
# licenses by implication, estoppel, or otherwise. If you are not
|
|
11
|
+
# aware of or do not agree to the License terms, you may not use,
|
|
12
|
+
# copy or modify the Software. You may use the source code of the
|
|
13
|
+
# Software only for your internal purposes and may not distribute the
|
|
14
|
+
# source code of the Software, any part thereof, or any derivative work
|
|
15
|
+
# thereof, to any third party, except pursuant to the Company's prior
|
|
16
|
+
# written consent.
|
|
17
|
+
# The Software is the confidential information of the Company.
|
|
18
|
+
# -------------------------------------------------------------------------------
|
|
19
|
+
"""
|
|
20
|
+
Created on 8/4/22
|
|
21
|
+
|
|
22
|
+
@author: irenab
|
|
23
|
+
"""
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# -------------------------------------------------------------------------------
|
|
2
|
+
# (c) Copyright 2022 Sony Semiconductor Israel, Ltd. All rights reserved.
|
|
3
|
+
#
|
|
4
|
+
# This software, in source or object form (the "Software"), is the
|
|
5
|
+
# property of Sony Semiconductor Israel Ltd. (the "Company") and/or its
|
|
6
|
+
# licensors, which have all right, title and interest therein, You
|
|
7
|
+
# may use the Software only in accordance with the terms of written
|
|
8
|
+
# license agreement between you and the Company (the "License").
|
|
9
|
+
# Except as expressly stated in the License, the Company grants no
|
|
10
|
+
# licenses by implication, estoppel, or otherwise. If you are not
|
|
11
|
+
# aware of or do not agree to the License terms, you may not use,
|
|
12
|
+
# copy or modify the Software. You may use the source code of the
|
|
13
|
+
# Software only for your internal purposes and may not distribute the
|
|
14
|
+
# source code of the Software, any part thereof, or any derivative work
|
|
15
|
+
# thereof, to any third party, except pursuant to the Company's prior
|
|
16
|
+
# written consent.
|
|
17
|
+
# The Software is the confidential information of the Company.
|
|
18
|
+
# -------------------------------------------------------------------------------
|
|
19
|
+
"""
|
|
20
|
+
Created on 12/5/22
|
|
21
|
+
|
|
22
|
+
@author: irenab
|
|
23
|
+
"""
|
|
24
|
+
from enum import Enum
|
|
25
|
+
import dataclasses
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class Framework(str, Enum):
|
|
29
|
+
nnir = 'Internal' # internal nodes
|
|
30
|
+
onnx = 'ONNX'
|
|
31
|
+
tensorflow = 'TensorFlow'
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@dataclasses.dataclass
|
|
35
|
+
class OpInfo:
|
|
36
|
+
node_id: str
|
|
37
|
+
op: str
|
|
38
|
+
framework: str
|
|
39
|
+
|
|
40
|
+
def clone(self, **kwargs):
|
|
41
|
+
return dataclasses.replace(self, **kwargs)
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# -------------------------------------------------------------------------------
|
|
2
|
+
# (c) Copyright 2022 Sony Semiconductor Israel, Ltd. All rights reserved.
|
|
3
|
+
#
|
|
4
|
+
# This software, in source or object form (the "Software"), is the
|
|
5
|
+
# property of Sony Semiconductor Israel Ltd. (the "Company") and/or its
|
|
6
|
+
# licensors, which have all right, title and interest therein, You
|
|
7
|
+
# may use the Software only in accordance with the terms of written
|
|
8
|
+
# license agreement between you and the Company (the "License").
|
|
9
|
+
# Except as expressly stated in the License, the Company grants no
|
|
10
|
+
# licenses by implication, estoppel, or otherwise. If you are not
|
|
11
|
+
# aware of or do not agree to the License terms, you may not use,
|
|
12
|
+
# copy or modify the Software. You may use the source code of the
|
|
13
|
+
# Software only for your internal purposes and may not distribute the
|
|
14
|
+
# source code of the Software, any part thereof, or any derivative work
|
|
15
|
+
# thereof, to any third party, except pursuant to the Company's prior
|
|
16
|
+
# written consent.
|
|
17
|
+
# The Software is the confidential information of the Company.
|
|
18
|
+
# -------------------------------------------------------------------------------
|
|
19
|
+
"""
|
|
20
|
+
Created on 6/29/22
|
|
21
|
+
|
|
22
|
+
@author: irenab
|
|
23
|
+
"""
|
|
24
|
+
from collections import defaultdict
|
|
25
|
+
from dataclasses import dataclass, field, replace
|
|
26
|
+
from typing import List, NamedTuple, Optional, Tuple
|
|
27
|
+
|
|
28
|
+
from uni.common.logger import trace_method
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class ConnectivityMap:
|
|
32
|
+
|
|
33
|
+
def __init__(self):
|
|
34
|
+
""" build a map containing source and target nodes and ordinals of each tensor
|
|
35
|
+
"""
|
|
36
|
+
self.tensors = defaultdict(Tensor) # type: defaultdict
|
|
37
|
+
|
|
38
|
+
def __getitem__(self, key):
|
|
39
|
+
return self.tensors[key]
|
|
40
|
+
|
|
41
|
+
def items(self):
|
|
42
|
+
return self.tensors.items()
|
|
43
|
+
|
|
44
|
+
def values(self):
|
|
45
|
+
return self.tensors.values()
|
|
46
|
+
|
|
47
|
+
@trace_method
|
|
48
|
+
def add_source(self, tensor_id, node_name, index, shape=None):
|
|
49
|
+
assert tensor_id and node_name
|
|
50
|
+
t = self.tensors[tensor_id]
|
|
51
|
+
if t.src:
|
|
52
|
+
raise RuntimeError(f't.src for {tensor_id} already exists')
|
|
53
|
+
t.src = Connection(node_name, index)
|
|
54
|
+
self.add_shape(tensor_id, shape)
|
|
55
|
+
|
|
56
|
+
@trace_method
|
|
57
|
+
def add_dest(self, tensor_id, node_name, index, shape: Optional[Tuple] = None):
|
|
58
|
+
assert tensor_id and node_name
|
|
59
|
+
t = self.tensors[tensor_id]
|
|
60
|
+
if t.dest and [d for d in t.dest if d.name == node_name and d.index == index]:
|
|
61
|
+
raise RuntimeError(f't.dest for {tensor_id} already exists')
|
|
62
|
+
t.dest.append(Connection(node_name, index))
|
|
63
|
+
self.add_shape(tensor_id, shape)
|
|
64
|
+
|
|
65
|
+
def add_shape(self, tensor_id, shape: Optional[Tuple]):
|
|
66
|
+
assert tensor_id
|
|
67
|
+
if shape is None:
|
|
68
|
+
return
|
|
69
|
+
t = self.tensors[tensor_id]
|
|
70
|
+
if t.shape not in [None, shape]:
|
|
71
|
+
raise RuntimeError(f'Conflicting t.shape for {tensor_id}. Previously set {t.shape}, new {shape}.')
|
|
72
|
+
t.shape = shape
|
|
73
|
+
|
|
74
|
+
def update(self, other):
|
|
75
|
+
# Assert that no keys in other.tensors are in self.tensors
|
|
76
|
+
assert all(key not in self.tensors for key in other.tensors), "Some tensors are already present in self.tensors"
|
|
77
|
+
self.tensors.update(other.tensors)
|
|
78
|
+
|
|
79
|
+
def clone_with_new_names(self, new_tensor_names, suffix):
|
|
80
|
+
new_map = ConnectivityMap()
|
|
81
|
+
for tensor_id, tensor in self.tensors.items():
|
|
82
|
+
kwargs = {}
|
|
83
|
+
if tensor.src:
|
|
84
|
+
kwargs['src'] = Connection(new_tensor_names[tensor.src.name], tensor.src.index)
|
|
85
|
+
kwargs['dest'] = [Connection(new_tensor_names[d.name], d.index) for d in tensor.dest] # type: ignore
|
|
86
|
+
new_tensor = tensor.clone(**kwargs)
|
|
87
|
+
new_map.tensors[tensor_id + suffix] = new_tensor
|
|
88
|
+
return new_map
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
class Connection(NamedTuple):
|
|
92
|
+
""" Represents edge connection to node, either outgoing or incoming
|
|
93
|
+
for src -> (edge1, edge2) -> dest there are 4 connections: (src, 0), (src, 1), (dest, 0), (dest, 1) """
|
|
94
|
+
name: str
|
|
95
|
+
index: int # type: ignore # Incompatible types in assignment
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
@dataclass
|
|
99
|
+
class Tensor:
|
|
100
|
+
""" Tensor's connectivity info
|
|
101
|
+
Can have a single source, but can be shared among several outputs """
|
|
102
|
+
src: Optional[Connection] = None
|
|
103
|
+
dest: List[Connection] = field(default_factory=list)
|
|
104
|
+
shape: Optional[Tuple] = None
|
|
105
|
+
|
|
106
|
+
def clone(self, **kwargs):
|
|
107
|
+
return replace(self, **kwargs)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# -------------------------------------------------------------------------------
|
|
2
|
+
# (c) Copyright 2022 Sony Semiconductor Israel, Ltd. All rights reserved.
|
|
3
|
+
#
|
|
4
|
+
# This software, in source or object form (the "Software"), is the
|
|
5
|
+
# property of Sony Semiconductor Israel Ltd. (the "Company") and/or its
|
|
6
|
+
# licensors, which have all right, title and interest therein, You
|
|
7
|
+
# may use the Software only in accordance with the terms of written
|
|
8
|
+
# license agreement between you and the Company (the "License").
|
|
9
|
+
# Except as expressly stated in the License, the Company grants no
|
|
10
|
+
# licenses by implication, estoppel, or otherwise. If you are not
|
|
11
|
+
# aware of or do not agree to the License terms, you may not use,
|
|
12
|
+
# copy or modify the Software. You may use the source code of the
|
|
13
|
+
# Software only for your internal purposes and may not distribute the
|
|
14
|
+
# source code of the Software, any part thereof, or any derivative work
|
|
15
|
+
# thereof, to any third party, except pursuant to the Company's prior
|
|
16
|
+
# written consent.
|
|
17
|
+
# The Software is the confidential information of the Company.
|
|
18
|
+
# -------------------------------------------------------------------------------
|
|
19
|
+
"""
|
|
20
|
+
Created on 10/13/22
|
|
21
|
+
|
|
22
|
+
@author: irenab
|
|
23
|
+
"""
|
|
24
|
+
from .defs import * # noqa: F403
|
|
25
|
+
from .util import * # noqa: F403
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# -------------------------------------------------------------------------------
|
|
2
|
+
# (c) Copyright 2022 Sony Semiconductor Israel, Ltd. All rights reserved.
|
|
3
|
+
#
|
|
4
|
+
# This software, in source or object form (the "Software"), is the
|
|
5
|
+
# property of Sony Semiconductor Israel Ltd. (the "Company") and/or its
|
|
6
|
+
# licensors, which have all right, title and interest therein, You
|
|
7
|
+
# may use the Software only in accordance with the terms of written
|
|
8
|
+
# license agreement between you and the Company (the "License").
|
|
9
|
+
# Except as expressly stated in the License, the Company grants no
|
|
10
|
+
# licenses by implication, estoppel, or otherwise. If you are not
|
|
11
|
+
# aware of or do not agree to the License terms, you may not use,
|
|
12
|
+
# copy or modify the Software. You may use the source code of the
|
|
13
|
+
# Software only for your internal purposes and may not distribute the
|
|
14
|
+
# source code of the Software, any part thereof, or any derivative work
|
|
15
|
+
# thereof, to any third party, except pursuant to the Company's prior
|
|
16
|
+
# written consent.
|
|
17
|
+
# The Software is the confidential information of the Company.
|
|
18
|
+
# -------------------------------------------------------------------------------
|
|
19
|
+
"""
|
|
20
|
+
Created on 8/8/22
|
|
21
|
+
|
|
22
|
+
@author: irenab
|
|
23
|
+
"""
|
|
24
|
+
from dataclasses import dataclass
|
|
25
|
+
from typing import Any, Sequence, Iterable, NamedTuple, Optional, List
|
|
26
|
+
|
|
27
|
+
from uni.common.core.common import OpInfo
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class UnsupportedError(Exception):
|
|
31
|
+
""" Base class for Unsupported exceptions """
|
|
32
|
+
pass
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class ErrorInfo:
|
|
36
|
+
reason: str
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@dataclass
|
|
40
|
+
class ParamErrorInfo(ErrorInfo):
|
|
41
|
+
""" Info about an error for a single param of an op """
|
|
42
|
+
name: str
|
|
43
|
+
value: Any
|
|
44
|
+
reason: str
|
|
45
|
+
|
|
46
|
+
def __str__(self):
|
|
47
|
+
return f'Param error - param: {self.name}, value: {self.value}, reason: {self.reason}'
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
@dataclass
|
|
51
|
+
class OpInputErrorInfo(ErrorInfo):
|
|
52
|
+
""" Invalid input for op """
|
|
53
|
+
input_index: int
|
|
54
|
+
input_name: str
|
|
55
|
+
reason: str
|
|
56
|
+
|
|
57
|
+
def __str__(self):
|
|
58
|
+
return f'Input error - input index: {self.input_index}, input node: {self.input_name}, reason: {self.reason}'
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
@dataclass
|
|
62
|
+
class OpOutputErrorInfo(ErrorInfo):
|
|
63
|
+
""" Invalid output for op. Can refer to output tensor or to output op """
|
|
64
|
+
output_index: int
|
|
65
|
+
output_name: str
|
|
66
|
+
reason: str
|
|
67
|
+
|
|
68
|
+
def __str__(self):
|
|
69
|
+
return f'Output error - output index: {self.output_index}, ' \
|
|
70
|
+
f'output tensor/node: {self.output_name}, reason: {self.reason}'
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
@dataclass
|
|
74
|
+
class OpIncorrectNumberOfInputsErrorInfo(ErrorInfo):
|
|
75
|
+
""" Missing inputs for op (in case onnx allow less o more inputs) """
|
|
76
|
+
expected_num_inputs: List[int]
|
|
77
|
+
actual_num_inputs: int
|
|
78
|
+
reason: str
|
|
79
|
+
|
|
80
|
+
def __str__(self):
|
|
81
|
+
return f'Incorrect number of inputs error - expected: {self.expected_num_inputs},' \
|
|
82
|
+
f' actual: {self.actual_num_inputs}, reason: {self.reason}'
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
class OpErrorsInfo(NamedTuple):
|
|
86
|
+
""" Info about all error for a single op """
|
|
87
|
+
op_info: OpInfo
|
|
88
|
+
errors: Sequence[ErrorInfo]
|
|
89
|
+
orig_op_info: Optional[OpInfo] = None
|
|
90
|
+
|
|
91
|
+
@staticmethod
|
|
92
|
+
def _format_op_info(op_info):
|
|
93
|
+
s = ''
|
|
94
|
+
if op_info.framework:
|
|
95
|
+
s = f'[{op_info.framework}] '
|
|
96
|
+
s += f'op: {op_info.op}, id: {op_info.node_id}'
|
|
97
|
+
return s
|
|
98
|
+
|
|
99
|
+
def __str__(self):
|
|
100
|
+
msg = 'Node ' + self._format_op_info(self.op_info)
|
|
101
|
+
if self.orig_op_info:
|
|
102
|
+
orig_op = self.orig_op_info
|
|
103
|
+
assert orig_op.node_id and orig_op.op and orig_op.framework
|
|
104
|
+
if orig_op.node_id != self.op_info.node_id or orig_op.op != self.op_info.op:
|
|
105
|
+
msg += ', ' + self._format_op_info(self.orig_op_info)
|
|
106
|
+
msg += ', errors:\n\t'
|
|
107
|
+
msg += '\n\t'.join(str(e) for e in self.errors)
|
|
108
|
+
return msg
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
class InvalidOpError(UnsupportedError):
|
|
112
|
+
""" Exception: errors for a single Op """
|
|
113
|
+
|
|
114
|
+
def __init__(self, op_errors: OpErrorsInfo):
|
|
115
|
+
self.op_errors = op_errors
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
class InvalidOpsError(UnsupportedError):
|
|
119
|
+
""" Exception: All Ops with invalid params """
|
|
120
|
+
|
|
121
|
+
def __init__(self, ops: Sequence[OpErrorsInfo]):
|
|
122
|
+
self.ops = ops
|
|
123
|
+
|
|
124
|
+
def __str__(self):
|
|
125
|
+
return '\n'.join(str(op) for op in self.ops)
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
class UnsupportedOpsError(UnsupportedError):
|
|
129
|
+
""" Exception: Unsupported ops """
|
|
130
|
+
|
|
131
|
+
def __init__(self, ops: Iterable[str]):
|
|
132
|
+
self.ops = sorted(ops)
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# -------------------------------------------------------------------------------
|
|
2
|
+
# (c) Copyright 2022 Sony Semiconductor Israel, Ltd. All rights reserved.
|
|
3
|
+
#
|
|
4
|
+
# This software, in source or object form (the "Software"), is the
|
|
5
|
+
# property of Sony Semiconductor Israel Ltd. (the "Company") and/or its
|
|
6
|
+
# licensors, which have all right, title and interest therein, You
|
|
7
|
+
# may use the Software only in accordance with the terms of written
|
|
8
|
+
# license agreement between you and the Company (the "License").
|
|
9
|
+
# Except as expressly stated in the License, the Company grants no
|
|
10
|
+
# licenses by implication, estoppel, or otherwise. If you are not
|
|
11
|
+
# aware of or do not agree to the License terms, you may not use,
|
|
12
|
+
# copy or modify the Software. You may use the source code of the
|
|
13
|
+
# Software only for your internal purposes and may not distribute the
|
|
14
|
+
# source code of the Software, any part thereof, or any derivative work
|
|
15
|
+
# thereof, to any third party, except pursuant to the Company's prior
|
|
16
|
+
# written consent.
|
|
17
|
+
# The Software is the confidential information of the Company.
|
|
18
|
+
# -------------------------------------------------------------------------------
|
|
19
|
+
"""
|
|
20
|
+
Created on 10/13/22
|
|
21
|
+
|
|
22
|
+
@author: irenab
|
|
23
|
+
"""
|
|
24
|
+
from typing import Sequence, Optional, List
|
|
25
|
+
|
|
26
|
+
from .defs import OpInfo, OpInputErrorInfo, ParamErrorInfo, OpErrorsInfo, InvalidOpError, ErrorInfo, \
|
|
27
|
+
OpOutputErrorInfo, OpIncorrectNumberOfInputsErrorInfo
|
|
28
|
+
from uni.common.core.node_history import NodeHistory
|
|
29
|
+
|
|
30
|
+
training_mode_error = 'Received op in training mode'
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def supported_vals_msg(vals: Sequence):
|
|
34
|
+
return f'Supported values: {list(vals)}'
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def exceeds_limit_msg(desc, limit):
|
|
38
|
+
return f'{desc} exceeds the supported limit of {limit}'
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def raise_op_param_error(op_info: OpInfo, param_name, param_value, reason, history: Optional[NodeHistory]):
|
|
42
|
+
""" Utility wrapper to raise InvalidOpError with a single param error """
|
|
43
|
+
err = ParamErrorInfo(name=param_name, value=param_value, reason=reason)
|
|
44
|
+
raise_op_error(op_info, [err], history)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def raise_op_input_error(op_info: OpInfo, input_index, input_name, reason, history: Optional[NodeHistory]):
|
|
48
|
+
""" Utility wrapper to raise InvalidOpError with a single input error """
|
|
49
|
+
err = OpInputErrorInfo(input_index=input_index, input_name=input_name, reason=reason)
|
|
50
|
+
raise_op_error(op_info, [err], history)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def raise_op_output_error(op_info: OpInfo, output_index, output_name, reason, history: Optional[NodeHistory]):
|
|
54
|
+
""" Utility wrapper to raise InvalidOpError with a single output error """
|
|
55
|
+
err = OpOutputErrorInfo(output_index=output_index, output_name=output_name, reason=reason)
|
|
56
|
+
raise_op_error(op_info, [err], history)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def raise_op_error(op_info: OpInfo, errors: Sequence[ErrorInfo], history: Optional[NodeHistory]):
|
|
60
|
+
""" Utility wrapper to raise InvalidOpError from a list of op errors """
|
|
61
|
+
assert len(errors)
|
|
62
|
+
orig_op = history.op_info if history else None
|
|
63
|
+
op_err = OpErrorsInfo(op_info, errors=errors, orig_op_info=orig_op)
|
|
64
|
+
raise InvalidOpError(op_errors=op_err)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def raise_incorrect_number_of_inputs(op_info: OpInfo, expected_num_inputs: List[int], actual_num_inputs: int, reason,
|
|
68
|
+
history: Optional[NodeHistory]):
|
|
69
|
+
err = OpIncorrectNumberOfInputsErrorInfo(expected_num_inputs, actual_num_inputs, reason=reason)
|
|
70
|
+
raise_op_error(op_info, [err], history)
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# -------------------------------------------------------------------------------
|
|
2
|
+
# (c) Copyright 2022 Sony Semiconductor Israel, Ltd. All rights reserved.
|
|
3
|
+
#
|
|
4
|
+
# This software, in source or object form (the "Software"), is the
|
|
5
|
+
# property of Sony Semiconductor Israel Ltd. (the "Company") and/or its
|
|
6
|
+
# licensors, which have all right, title and interest therein, You
|
|
7
|
+
# may use the Software only in accordance with the terms of written
|
|
8
|
+
# license agreement between you and the Company (the "License").
|
|
9
|
+
# Except as expressly stated in the License, the Company grants no
|
|
10
|
+
# licenses by implication, estoppel, or otherwise. If you are not
|
|
11
|
+
# aware of or do not agree to the License terms, you may not use,
|
|
12
|
+
# copy or modify the Software. You may use the source code of the
|
|
13
|
+
# Software only for your internal purposes and may not distribute the
|
|
14
|
+
# source code of the Software, any part thereof, or any derivative work
|
|
15
|
+
# thereof, to any third party, except pursuant to the Company's prior
|
|
16
|
+
# written consent.
|
|
17
|
+
# The Software is the confidential information of the Company.
|
|
18
|
+
# -------------------------------------------------------------------------------
|
|
19
|
+
"""
|
|
20
|
+
Created on 8/4/22
|
|
21
|
+
|
|
22
|
+
@author: irenab
|
|
23
|
+
"""
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# -------------------------------------------------------------------------------
|
|
2
|
+
# (c) Copyright 2022 Sony Semiconductor Israel, Ltd. All rights reserved.
|
|
3
|
+
#
|
|
4
|
+
# This software, in source or object form (the "Software"), is the
|
|
5
|
+
# property of Sony Semiconductor Israel Ltd. (the "Company") and/or its
|
|
6
|
+
# licensors, which have all right, title and interest therein, You
|
|
7
|
+
# may use the Software only in accordance with the terms of written
|
|
8
|
+
# license agreement between you and the Company (the "License").
|
|
9
|
+
# Except as expressly stated in the License, the Company grants no
|
|
10
|
+
# licenses by implication, estoppel, or otherwise. If you are not
|
|
11
|
+
# aware of or do not agree to the License terms, you may not use,
|
|
12
|
+
# copy or modify the Software. You may use the source code of the
|
|
13
|
+
# Software only for your internal purposes and may not distribute the
|
|
14
|
+
# source code of the Software, any part thereof, or any derivative work
|
|
15
|
+
# thereof, to any third party, except pursuant to the Company's prior
|
|
16
|
+
# written consent.
|
|
17
|
+
# The Software is the confidential information of the Company.
|
|
18
|
+
# -------------------------------------------------------------------------------
|
|
19
|
+
"""
|
|
20
|
+
Created on 8/4/22
|
|
21
|
+
|
|
22
|
+
@author: irenab
|
|
23
|
+
"""
|
|
24
|
+
from typing import Optional, TYPE_CHECKING
|
|
25
|
+
from dataclasses import dataclass, replace
|
|
26
|
+
if TYPE_CHECKING:
|
|
27
|
+
from .typing import NodeKey
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
# eq + frozen make the class hashable
|
|
31
|
+
@dataclass(eq=True, frozen=True)
|
|
32
|
+
class Edge:
|
|
33
|
+
"""
|
|
34
|
+
Base class for Edge object supported by MultiDiGraph
|
|
35
|
+
Shape is optional - it's not strictly required by MultiDiGraph,
|
|
36
|
+
but it can provide convenience services if it exists
|
|
37
|
+
"""
|
|
38
|
+
src: 'NodeKey' # source node key
|
|
39
|
+
dest: 'NodeKey' # dest node key
|
|
40
|
+
src_index: int # index of corresponding output of the source node
|
|
41
|
+
dest_index: int # index of corresponding input of the target node
|
|
42
|
+
shape: Optional[tuple] = None # tensor shape
|
|
43
|
+
|
|
44
|
+
def clone(self, **kwargs):
|
|
45
|
+
return replace(self, **kwargs)
|
|
46
|
+
|
|
47
|
+
def __str__(self):
|
|
48
|
+
return f'({self.src}:{self.src_index} -> {self.dest}:{self.dest_index})'
|
|
49
|
+
|
|
50
|
+
def equal_by_connectivity(self, other):
|
|
51
|
+
""" Equality between src, src_index, dest, dest_index """
|
|
52
|
+
return self.src == other.src and self.dest == other.dest and \
|
|
53
|
+
self.src_index == other.src_index and self.dest_index == other.dest_index
|