Skip to content

Commit ec062cc

Browse files
committed
Fix after rebase
1 parent de53846 commit ec062cc

4 files changed

Lines changed: 32 additions & 3 deletions

File tree

backends/nxp/backend/neutron_map.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,20 @@ def get_name_matches(tf_names: list[str], neutron_names: list[str]) -> int:
294294
# (i.e., sharing a common prefix separated by "/").
295295
result = 0
296296
for tf_name in tf_names:
297+
# Determine if the tensor name corresponds to a special operation input
298+
# (e.g., permutation input for Transpose or padding input for Pad)
299+
special_op = (
300+
# Matches names like "perm0", "perm1", etc. → used by Transpose ops
301+
"permutation"
302+
if re.fullmatch(r"perm(\d+)?", tf_name)
303+
# Matches names like "padding0", "padding1", etc. → used by Pad ops
304+
else (
305+
"padding"
306+
if re.fullmatch(r"padding(s)?(\d+)?", tf_name)
307+
# Default: no special operation
308+
else None
309+
)
310+
)
297311
for neutron_name in neutron_names:
298312
if (
299313
neutron_name == tf_name
@@ -302,6 +316,11 @@ def get_name_matches(tf_names: list[str], neutron_names: list[str]) -> int:
302316
):
303317
result += 1
304318
break
319+
320+
# Check if the neutron input is also the special op (Pad or Transpose)
321+
if special_op and special_op in neutron_name:
322+
result += 1
323+
break
305324
return result
306325

307326
name_matches = get_name_matches(tf_node.inputs, neutron_node.inputs)

backends/nxp/runtime/NeutronBackend.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ namespace neutron {
2626
#define ALIGN_SIZE(size) \
2727
((size + BUFFER_ALIGNMENT - 1) & (~(BUFFER_ALIGNMENT - 1)))
2828

29-
#define KOPC_CALLARGS 6 // The operation for TileIR
30-
29+
#define KOPC_CALLARGS 6 // The operation for TileIR
30+
3131
// clang-format off
3232
/* Header schema:
3333
+----------------------------+-----------------------------+------------------------+

backends/nxp/tests/generic_tests/test_profiling.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def test__parallel_pool(self, caplog):
8686
input_shape,
8787
dlg_model_verifier=BaseGraphVerifier(1, []),
8888
output_comparator=NumericalStatsOutputComparator(),
89+
use_neutron_for_format_conversion=False,
8990
use_profiling=True,
9091
)
9192
neutron_map = extract_map_from_logs(caplog)
@@ -113,11 +114,12 @@ def test__cifar(self, caplog):
113114
input_shape,
114115
dlg_model_verifier=BaseGraphVerifier(1, []),
115116
output_comparator=NumericalStatsOutputComparator(),
117+
use_neutron_for_format_conversion=False,
116118
use_profiling=True,
117119
)
118120
neutron_map = extract_map_from_logs(caplog)
119121
assert neutron_map == {
120-
0: (), # Pad
122+
0: (10,), # Pad
121123
1: (10, 11), # Conv2DStandardV1 (Pad + Conv2d)
122124
2: (12,), # MaxPool
123125
3: (13, 14), # Conv2DStandardV1 (Pad + Conv2d)
@@ -140,6 +142,7 @@ def test__avg_pool(self, caplog):
140142
input_shape,
141143
dlg_model_verifier=BaseGraphVerifier(1, []),
142144
output_comparator=NumericalStatsOutputComparator(),
145+
use_neutron_for_format_conversion=False,
143146
use_profiling=True,
144147
)
145148
neutron_map = extract_map_from_logs(caplog)

backends/nxp/tests/nsys_testing.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ def _run_delegated_executorch_program(
9797
use_qat: bool = False,
9898
train_fn: Callable[[torch.fx.GraphModule], None] | None = None,
9999
use_profiling: bool = False,
100+
use_neutron_for_format_conversion=True,
100101
operators_not_to_delegate: list[str] = None,
101102
remove_quant_io_ops: bool = False,
102103
) -> tuple[ExportedProgram, str]:
@@ -125,6 +126,7 @@ def wrapper(*args, **kwargs):
125126
use_qat=use_qat,
126127
train_fn=train_fn,
127128
use_profiling=use_profiling,
129+
use_neutron_for_format_conversion=use_neutron_for_format_conversion,
128130
operators_not_to_delegate=operators_not_to_delegate,
129131
remove_quant_io_ops=remove_quant_io_ops,
130132
)
@@ -400,6 +402,7 @@ def lower_run_compare(
400402
use_qat: bool = False,
401403
train_fn: Callable[[torch.fx.GraphModule], None] | None = None,
402404
use_profiling: bool = False,
405+
use_neutron_for_format_conversion=True,
403406
operators_not_to_delegate: list[str] = None,
404407
remove_quant_io_ops: bool = False,
405408
):
@@ -419,6 +422,9 @@ def lower_run_compare(
419422
:param use_qat: If True, applies quantization-aware training before conversion (without the QAT training).
420423
:param train_fn: Train/finetune function for QAT training. Is used only when `use_qat=True`.
421424
:param use_profiling: Enable profiling for neutron delegated model.
425+
:param use_neutron_for_format_conversion: If True, the EdgeProgramToIRConverter will insert `Transpose` ops to
426+
ensure that the IO matches the executorch partition, which will be
427+
delegated to Neutron,
422428
:param operators_not_to_delegate: list of operators not to delegate.
423429
:param remove_quant_io_ops: If true, IO q-ops are removed and verification is done on quantized
424430
version of dataset (quantized INT8 input samples).
@@ -464,6 +470,7 @@ def lower_run_compare(
464470
use_qat=use_qat,
465471
train_fn=train_fn,
466472
use_profiling=use_profiling,
473+
use_neutron_for_format_conversion=use_neutron_for_format_conversion,
467474
operators_not_to_delegate=operators_not_to_delegate,
468475
remove_quant_io_ops=remove_quant_io_ops,
469476
)

0 commit comments

Comments
 (0)