Skip to content

Commit b00660a

Browse files
committed
NXP backend: Remove ONNX related and unused code.
1 parent 6a238e3 commit b00660a

File tree

8 files changed

+20
-785
lines changed

8 files changed

+20
-785
lines changed

backends/nxp/backend/ir/conversion_config.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 NXP
1+
# Copyright 2024-2025 NXP
22
#
33
# This source code is licensed under the BSD-style license found in the
44
# LICENSE file in the root directory of this source tree.
@@ -14,7 +14,6 @@ def __init__(self, args: dict | None = None):
1414
:param args: Optional dictionary with conversion arguments. Unknown arguments are ignored.
1515
"""
1616
self.keep_io_format: bool = False
17-
self.skip_shape_inference: bool = False
1817
self.allow_inputs_stripping: bool = True
1918
self.qdq_aware_conversion: bool = True
2019
self.symbolic_dimensions_mapping: dict[str, int] | None = None
@@ -46,15 +45,6 @@ def __repr__(self):
4645
return "ConversionConfig[" + ", ".join(attrs) + "]"
4746

4847

49-
class SkipShapeInferenceConfig(ConversionConfig):
50-
51-
def __init__(self):
52-
"""
53-
Conversion config shortcut with disabled shape inference.
54-
"""
55-
super().__init__({"skip_shape_inference": True})
56-
57-
5848
class QDQAwareConfig(ConversionConfig):
5949

6050
def __init__(self):

backends/nxp/backend/ir/converter/builder/model_builder.py

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#
22
# Copyright 2023 Martin Pavella
3-
# Copyright 2023-2024 NXP
3+
# Copyright 2023-2025 NXP
44
#
55
# License: MIT
66
# See the LICENSE_MIT for more details.
@@ -795,29 +795,8 @@ def _remove_tensor_with_name(self, name):
795795

796796
def append_new_tensor(self, t_tensor: tflite_model.Tensor, overwrite: bool = False):
797797
"""Append the TFLite tensor 't_tensor' to the 'SubGraph.tensors' and register it."""
798-
799-
if t_tensor.name in self._tensor_name_map.keys():
800-
"""Tensor has already been added. Sometimes however, ONNX models
801-
will have tensors in their 'inputs' or 'outputs', which don't
802-
belong there and are in fact static. I this case we need to
803-
overwrite the existing tensors."""
804-
805-
if overwrite:
806-
self._remove_tensor_with_name(t_tensor.name)
807-
808-
# If the tenor previously appeared in ONNX 'inputs' or 'outputs',
809-
# the old version MUST be removed from there.
810-
self._remove_input_with_name(t_tensor.name)
811-
self._remove_output_with_name(t_tensor.name)
812-
813-
self.get_tensors().append(t_tensor)
814-
self._tensor_name_map[t_tensor.name] = t_tensor
815-
else:
816-
logger.w(f"Tensor '{t_tensor.name}' is already in the tensors!")
817-
818-
else:
819-
self._tensor_name_map[t_tensor.name] = t_tensor
820-
self.get_tensors().append(t_tensor)
798+
self._tensor_name_map[t_tensor.name] = t_tensor
799+
self.get_tensors().append(t_tensor)
821800

822801
def append_new_buffer(self, buffer: tflite_model.Buffer):
823802
"""Append the 'buffer' to the 'model.buffers'."""

backends/nxp/backend/ir/converter/conversion/common.py

Lines changed: 3 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#
22
# Copyright 2023 Martin Pavella
3-
# Copyright 2023-2024 NXP
3+
# Copyright 2023-2025 NXP
44
#
55
# License: MIT
66
# See the LICENSE_MIT for more details.
@@ -12,7 +12,7 @@
1212
'conversion/builtin/' directory.
1313
"""
1414

15-
from typing import Any, List, MutableSequence, Optional
15+
from typing import List, MutableSequence, Optional
1616

1717
import executorch.backends.nxp.backend.ir.logger as logger
1818
from executorch.backends.nxp.backend.ir.tflite_generator import tflite_model
@@ -22,28 +22,8 @@
2222
max_pool_2d_options,
2323
transpose_conv_options,
2424
)
25-
from torch.fx import Node
26-
27-
28-
def exactly_one_is_none(obj1: Optional, obj2: Optional) -> bool:
29-
"""Determine if exactly 1 of the arguments is None, or not."""
30-
return (obj1 is None and obj2 is not None) or (obj1 is not None and obj2 is None)
31-
32-
33-
def contains_duplicates(list_to_check: List[Any]) -> bool:
34-
"""Determine if given list has duplicate elements or not."""
35-
return len(list_to_check) != len(set(list_to_check))
36-
37-
38-
def clamp(val: int, start: int, end: int) -> int:
39-
"""Clamp an int value between start and end (inclusive) and return it."""
40-
if val < start:
41-
return start
42-
43-
elif val > end:
44-
return end
4525

46-
return val
26+
from torch.fx import Node
4727

4828

4929
def try_get_input(t_op: tflite_model.Operator, idx: int) -> tflite_model.Tensor | None:
@@ -62,11 +42,6 @@ def try_get_input(t_op: tflite_model.Operator, idx: int) -> tflite_model.Tensor
6242

6343
tensor = t_op.tmp_inputs[idx]
6444

65-
if tensor.name == "":
66-
# ONNX allows the name "" for optional tensors. It indicates that the tensor should be ignored, and a default
67-
# value should be used. Just like if the tensor was omitted altogether.
68-
return None
69-
7045
return tensor
7146

7247

@@ -188,32 +163,6 @@ def node_uses_shape_broadcasting(node: Node) -> bool:
188163
)
189164

190165

191-
def uses_multiple_input_types(t_op: tflite_model.Operator) -> bool:
192-
"""Determine if the input tensors of given TFLite operator use different data types or not.
193-
194-
:param t_op: TFLite operator with 'tmp_inputs' initialized.
195-
:return: True, if any two input tensors have a different data type.
196-
False, if all input tensors use the same data type.
197-
"""
198-
199-
if t_op.tmp_inputs is None:
200-
logger.e(
201-
logger.Code.INTERNAL_ERROR,
202-
"common.uses_multiple_input_types(): 'tmp_inputs' are None!",
203-
)
204-
205-
if len(t_op.tmp_inputs) == 0:
206-
logger.e(
207-
logger.Code.INTERNAL_ERROR,
208-
"common.uses_multiple_input_types(): Operator has no inputs!",
209-
)
210-
211-
first_input_type = t_op.tmp_inputs[0].type
212-
return any(
213-
input_tensor.type != first_input_type for input_tensor in t_op.tmp_inputs[1:]
214-
)
215-
216-
217166
class OpsList:
218167
"""
219168
Holder of TFLite operator (middle_op) that can be prefixed (pre_ops) of suffixed (post_ops)

0 commit comments

Comments
 (0)