Skip to content

Commit f662ba6

Browse files
committed
NXP backend: Replace CustomDelegationOptions with NeutronTargetSpec in new Neutron C flow references
1 parent 83b2c9f commit f662ba6

8 files changed

Lines changed: 13 additions & 18 deletions

File tree

backends/nxp/backend/custom_delegation_options.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,3 @@ class CustomDelegationOptions:
2222
# not create any NeutronGraph that can be called. This is done by the partitioner itself, and is not handled by
2323
# the individual node converters.
2424
allow_no_op_partitions: bool = False
25-
26-
# The new neutron converter flow has different constraints for supported operators. These need to be addressed when
27-
# deciding is operator is delegated or not in _is_supported_on_target().
28-
use_new_flow_neutron_c: bool = False

backends/nxp/backend/ir/converter/node_converters/ops_converters/abs_converter.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66

77
import torch
8-
98
from executorch.backends.nxp.backend.ir.converter.node_converter import (
109
CustomDelegationOptions,
1110
NeutronTargetSpec,
@@ -36,7 +35,7 @@ def _is_supported_on_target(
3635
custom_delegation_options: CustomDelegationOptions,
3736
) -> bool:
3837

39-
if custom_delegation_options.use_new_flow_neutron_c:
38+
if neutron_target_spec.use_new_flow_neutron_c:
4039
# Requirements specified by the new Neutron flow documentation.
4140

4241
supported_types = [torch.int8, torch.uint8]

backends/nxp/backend/ir/converter/node_converters/ops_converters/avg_pool_2d_converter.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import numpy as np
77
import torch
8-
98
from executorch.backends.nxp.backend.ir.converter.conversion import (
109
aten_translator,
1110
common,
@@ -22,7 +21,6 @@
2221
from executorch.backends.nxp.backend.ir.tflite_generator.builtin_options import (
2322
average_pool_2d_options,
2423
)
25-
2624
from executorch.backends.nxp.backend.neutron_target_spec import NeutronTargetSpec
2725
from torch.fx import Node
2826
from torch.nn import Parameter
@@ -66,7 +64,7 @@ def _is_supported_on_target(
6664
kernel = node.args[1]
6765
stride = node.args[2]
6866

69-
if custom_delegation_options.use_new_flow_neutron_c:
67+
if neutron_target_spec.use_new_flow_neutron_c:
7068
# Requirements specified by the new Neutron flow documentation.
7169

7270
supported_types = [torch.int8, torch.uint8]

backends/nxp/backend/ir/converter/node_converters/ops_converters/max_pool2d_with_indices_converter.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import numpy as np
99
import torch
10-
1110
from executorch.backends.nxp.backend.edge_helper import try_get_arg
1211
from executorch.backends.nxp.backend.ir.converter.conversion import (
1312
aten_translator,
@@ -74,7 +73,7 @@ def _is_supported_on_target(
7473
MaxPool2DWithIndicesConverter._get_node_args(node)
7574
)
7675

77-
if custom_delegation_options.use_new_flow_neutron_c:
76+
if neutron_target_spec.use_new_flow_neutron_c:
7877
# Requirements specified by the new Neutron flow documentation.
7978

8079
supported_types = [torch.int8, torch.uint8]

backends/nxp/backend/neutron_target_spec.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ def __init__(self, target: str, use_new_flow_neutron_c: bool = False):
102102
converter_manager.verify_target(target)
103103
neutron_converter = converter_manager.get_converter()
104104
self.neutron_target = neutron_converter.getNeutronTarget(target)
105+
106+
# The new neutron converter flow has different constraints for supported operators. These need to be addressed when
107+
# deciding is operator is delegated or not in _is_supported_on_target().
105108
self.use_new_flow_neutron_c = use_new_flow_neutron_c
106109

107110
if self.is_subsystem():

backends/nxp/nxp_backend.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,11 @@ def preprocess( # noqa C901
231231
)
232232
tflite_model, io_formats = EdgeProgramToIRConverter().convert_program(
233233
edge_program,
234-
neutron_target_spec=NeutronTargetSpec(target),
235-
conversion_config=conversion_config,
236-
custom_delegation_options=CustomDelegationOptions(
237-
use_new_flow_neutron_c=use_new_flow_neutron_c
234+
neutron_target_spec=NeutronTargetSpec(
235+
target, use_new_flow_neutron_c=use_new_flow_neutron_c
238236
),
237+
conversion_config=conversion_config,
238+
custom_delegation_options=CustomDelegationOptions(),
239239
)
240240

241241
neutron_model = NeutronConverterManager(dump_kernel_selection_code).convert(

backends/nxp/tests/executorch_pipeline.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ def to_quantized_edge_program(
195195
_neutron_target_spec = NeutronTargetSpec(
196196
target, use_new_flow_neutron_c=use_new_flow_neutron_c
197197
)
198-
custom_delegation_options.use_new_flow_neutron_c = use_new_flow_neutron_c
199198
if get_quantizer_fn is None:
200199
get_quantizer_fn = partial(
201200
_get_default_quantizer, _neutron_target_spec, use_qat

examples/nxp/aot_neutron_compile.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
import executorch.extension.pybindings.portable_lib
1414
import executorch.kernels.quantized # noqa F401
15-
1615
import torch
1716
from executorch.backends.nxp.backend.neutron_target_spec import NeutronTargetSpec
1817
from executorch.backends.nxp.edge_passes.neutron_edge_pass_manager import (
@@ -253,7 +252,9 @@ def get_model_and_inputs_from_name(model_name: str, use_random_dataset: bool):
253252
if args.debug:
254253
logging.basicConfig(level=logging.DEBUG, format=FORMAT, force=True)
255254

256-
neutron_target_spec = NeutronTargetSpec(target=args.target)
255+
neutron_target_spec = NeutronTargetSpec(
256+
target=args.target, use_new_flow_neutron_c=args.use_new_flow_neutron_c
257+
)
257258

258259
# 1. pick model from one of the supported lists
259260
model, example_inputs, calibration_inputs = get_model_and_inputs_from_name(

0 commit comments

Comments
 (0)