Skip to content

Commit a8256b7

Browse files
Arm backend: Remove output_order_workaround (pytorch#21730)
output_order_workaround was deprecated in 1.2 and to be removed ahead of 1.4. cc @digantdesai @freddan80 @per @zingo @mansnils @Sebastian-Larsson @robell @rascani --------- Signed-off-by: Oscar Andersson <oscar.andersson@arm.com>
1 parent d189b45 commit a8256b7

6 files changed

Lines changed: 5 additions & 207 deletions

File tree

‎backends/arm/common/arm_compile_spec.py‎

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
SoftmaxDecompositionConfig,
2222
)
2323
from executorch.backends.arm.tosa import TosaSpecification
24-
from executorch.exir._warnings import deprecated
25-
2624
from executorch.exir.backend.compile_spec_schema import CompileSpec
2725

2826

@@ -48,7 +46,6 @@ class DebugMode(Enum):
4846
_OUTPUT_FORMAT_KEY = "output_format"
4947
_DEBUG_ARTIFACT_KEY = "debug_artifact_path"
5048
_DEBUG_MODE_KEY = "dump_debug_info"
51-
_OUTPUT_REORDER_KEY = "ouput_reorder_workaround"
5249
_TRANSFORM_PIPELINE_CONFIG_KEY = "transform_pipeline_config"
5350
_PRESERVE_IO_QUANT_KEY = "preserve_io_quantization"
5451
_TOSA_DEV_MODE = "tosa_sw_dev_mode"
@@ -59,7 +56,6 @@ def _set_compile_specs(
5956
compiler_flags: list[str],
6057
path_for_intermediates: str | None = None,
6158
tosa_debug_mode: DebugMode | None = None,
62-
output_order_workaround: bool = False,
6359
pipeline_config: ArmPassPipelineConfig | None = None,
6460
preserve_io_quantization: bool = False,
6561
tosa_dev_mode: bool | None = None,
@@ -70,17 +66,9 @@ def _set_compile_specs(
7066
self.path_for_intermediates = path_for_intermediates
7167
self.tosa_debug_mode = tosa_debug_mode
7268
self._pipeline_config = pipeline_config
73-
self.output_order_workaround = output_order_workaround
7469
self.preserve_io_quantization = preserve_io_quantization
7570
self._warn_if_redundant_preserve_io_quantization()
7671
self.tosa_dev_mode = tosa_dev_mode
77-
if output_order_workaround:
78-
warnings.warn(
79-
"ArmCompileSpec(output_order_workaround=True) is deprecated and will be "
80-
"removed in v1.5; please remove this flag.",
81-
DeprecationWarning,
82-
stacklevel=2,
83-
)
8472

8573
@classmethod
8674
def _from_list(cls, compile_specs: list[CompileSpec]): # noqa: C901
@@ -89,7 +77,6 @@ def _from_list(cls, compile_specs: list[CompileSpec]): # noqa: C901
8977
compiler_flags: list[str] | None = None
9078
path_for_intermediates: str | None = None
9179
tosa_debug_mode: ArmCompileSpec.DebugMode | None = None
92-
output_order_workaround: bool = False
9380
pipeline_config: ArmPassPipelineConfig | None = None
9481
preserve_io_quantization: bool = False
9582
tosa_dev_mode: bool | None = None
@@ -129,14 +116,6 @@ def _from_list(cls, compile_specs: list[CompileSpec]): # noqa: C901
129116
"More than one tosa_debug_mode entry in compile spec."
130117
)
131118
tosa_debug_mode = ArmCompileSpec.DebugMode[val]
132-
elif key == ArmCompileSpec._OUTPUT_REORDER_KEY:
133-
output_order_workaround = val # type: ignore[assignment]
134-
if output_order_workaround:
135-
warnings.warn(
136-
"The 'output_order_workaround' compile spec entry is deprecated and will be removed in v1.5; please remove this entry.",
137-
DeprecationWarning,
138-
stacklevel=2,
139-
)
140119
elif key == ArmCompileSpec._TRANSFORM_PIPELINE_CONFIG_KEY:
141120
if pipeline_config is not None:
142121
raise ValueError(
@@ -172,7 +151,6 @@ def _from_list(cls, compile_specs: list[CompileSpec]): # noqa: C901
172151
compiler_flags=compiler_flags,
173152
path_for_intermediates=path_for_intermediates,
174153
tosa_debug_mode=tosa_debug_mode,
175-
output_order_workaround=output_order_workaround,
176154
pipeline_config=pipeline_config,
177155
preserve_io_quantization=preserve_io_quantization,
178156
tosa_dev_mode=tosa_dev_mode,
@@ -237,14 +215,6 @@ def _to_list(self):
237215
)
238216
)
239217

240-
if not self.output_order_workaround:
241-
compile_spec.append(
242-
CompileSpec(
243-
ArmCompileSpec._OUTPUT_REORDER_KEY,
244-
bytes(self.output_order_workaround),
245-
)
246-
)
247-
248218
if self._pipeline_config is not None and not self._pipeline_config.is_default():
249219
compile_spec.append(
250220
CompileSpec(
@@ -359,26 +329,6 @@ def _set_tosa_dev_mode(self, tosa_dev_mode: bool):
359329
self.tosa_dev_mode = tosa_dev_mode
360330
return self
361331

362-
@deprecated(
363-
"set_output_order_workaround() is deprecated and will be removed in v1.5; please remove this call."
364-
)
365-
def set_output_order_workaround(self, output_order_workaround: bool):
366-
"""Sets whether to apply the output order workaround.
367-
368-
Args:
369-
output_order_workaround: Boolean indicating whether to apply the workaround.
370-
371-
"""
372-
self.output_order_workaround = output_order_workaround
373-
return self
374-
375-
@deprecated(
376-
"get_output_order_workaround() is deprecated and will be removed in v1.5; please remove this call."
377-
)
378-
def get_output_order_workaround(self) -> bool:
379-
"""Gets whether the output order workaround is being applied."""
380-
return self.output_order_workaround
381-
382332
@classmethod
383333
@abstractmethod
384334
def _get_output_format(cls) -> str:

‎backends/arm/test/deprecation/test_arm_compile_spec_deprecation.py‎

Lines changed: 0 additions & 46 deletions
This file was deleted.

‎backends/arm/test/test_arm_backend.sh‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,11 +474,13 @@ test_memory_allocation() {
474474
# Ethos-U85
475475
echo "${TEST_SUITE_NAME}: Test target Ethos-U85"
476476
examples/arm/run.sh --et_build_root=arm_test/test_run --target=ethos-u85-128 --model_name=examples/arm/example_modules/add.py &> arm_test/test_run/full.log
477+
# method_allocator_input includes one 16-byte EValue input plus possible
478+
# alignment padding before that allocation.
477479
python3 backends/arm/test/test_memory_allocator_log.py --log arm_test/test_run/full.log \
478480
--require "model_pte_program_size" "<= 3200 B" \
479481
--require "method_allocator_planned" "<= 64 B" \
480482
--require "method_allocator_loaded" "<= 1024 B" \
481-
--require "method_allocator_input" "<= 16 B" \
483+
--require "method_allocator_input" "<= 24 B" \
482484
--require "Total DRAM used" "<= 0.06 KiB"
483485

484486
_test_runner_size_optimization

‎backends/arm/tosa/backend.py‎

Lines changed: 2 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
"""
1717

1818
import logging
19-
from itertools import count
20-
from typing import cast, Dict, final, List
19+
from typing import cast, final, List
2120

2221
import torch
2322

@@ -40,7 +39,7 @@
4039
from executorch.exir.backend.compile_spec_schema import CompileSpec
4140
from executorch.exir.graph_module import get_cond_while_submodules
4241
from torch.export.exported_program import ExportedProgram
43-
from torch.fx import Graph, GraphModule, Node
42+
from torch.fx import GraphModule, Node
4443

4544
# TOSA backend debug functionality
4645
logger = logging.getLogger(__name__)
@@ -55,78 +54,6 @@ def _qualify_control_flow_region_name(
5554
return f"{parent_region_name}__{child_region_name}"
5655

5756

58-
def _annotate_external_ids(ep_graph: Graph) -> Dict[str, int]:
59-
"""Assign deterministic output IDs to leaf outputs.
60-
61-
Flattens the output structure and assigns the external ID
62-
based on the leaf position in the exported output tuple/list.
63-
64-
Args:
65-
ep_graph (Graph): FX graph produced by export preprocessing.
66-
67-
Returns:
68-
dict[str, int]: Mapping from *leaf output node name* to external output index.
69-
70-
"""
71-
node2external_id = {}
72-
73-
def _collect_leaves(arg, nodes):
74-
# Collect only FX Nodes that are actual outputs
75-
# (ignore ints/None/etc inside structured outputs).
76-
if isinstance(arg, Node):
77-
nodes.append(arg)
78-
elif isinstance(arg, (list, tuple)):
79-
for a in arg:
80-
_collect_leaves(a, nodes)
81-
82-
out = ep_graph.output_node()
83-
out_leaves: list[Node] = []
84-
# First argument of output is the structured container (tuple/list) of outputs
85-
_collect_leaves(out.args[0], out_leaves)
86-
87-
# Map each output leaf's name to its position
88-
node2external_id = {leaf.name: idx for idx, leaf in enumerate(out_leaves)}
89-
90-
return node2external_id
91-
92-
93-
def _sort_outputs(graph_module: GraphModule, node_to_id_map: dict[str, int]):
94-
"""Reorder graph outputs to match ascending external IDs.
95-
96-
Args:
97-
graph_module (GraphModule): Graph to reorder in place.
98-
node_to_id_map (dict[str, int]): Mapping from node name to output index.
99-
100-
Returns:
101-
GraphModule: Updated graph module with deterministic output ordering.
102-
103-
"""
104-
105-
def _external_id(n: Node, node_2_id, fallback: int) -> int:
106-
"""Return the external ID for ``n`` or ``fallback`` when absent."""
107-
return node_2_id.get(n.name, fallback)
108-
109-
out_node = graph_module.graph.output_node()
110-
out_list = cast(tuple, out_node.args[0])
111-
_counter = count()
112-
113-
# sort nodes by the key that is id
114-
def _sort_key(t: Node) -> int:
115-
"""Key function that orders outputs by external ID or position."""
116-
return _external_id(t, node_to_id_map, next(_counter))
117-
118-
orig_ord = tuple(sorted(out_list, key=_sort_key))
119-
120-
current_order = tuple(out_list)
121-
if orig_ord != current_order:
122-
replacement = list(orig_ord) if isinstance(out_node.args[0], list) else orig_ord
123-
out_node.args = (replacement,)
124-
graph_module.graph.lint()
125-
graph_module.recompile()
126-
127-
return graph_module
128-
129-
13057
def _get_matching_fake_tensor(node: Node):
13158
"""Return the fake tensor of node."""
13259
return node.meta["val"]
@@ -376,9 +303,7 @@ def _annotate_control_flow_region_names(
376303
)
377304

378305
tosa_spec = compile_spec.tosa_spec
379-
node_to_id_map = _annotate_external_ids(graph_module.graph)
380306
artifact_path = compile_spec._get_intermediate_path()
381-
output_order_workaround = compile_spec.get_output_order_workaround()
382307

383308
# TODO: Fix the need to lazily import this.
384309
from executorch.backends.arm._passes import ArmPassManager
@@ -392,12 +317,6 @@ def _annotate_control_flow_region_names(
392317

393318
node_visitors = get_node_visitors(tosa_spec, debug_hook)
394319

395-
if output_order_workaround:
396-
logger.debug("Re-sorting outputs during TOSA lowering.")
397-
graph_module = _sort_outputs(graph_module, node_to_id_map)
398-
else:
399-
logger.debug("No re-sorting outputs (workaround) during TOSA lowering.")
400-
401320
_annotate_control_flow_region_names(graph_module, submodule_name)
402321

403322
if submodule_name is not None:
@@ -486,6 +405,5 @@ def filter_tosa_compile_specs(
486405
compile_spec._get_intermediate_path()
487406
)
488407
.dump_debug_info(compile_spec.tosa_debug_mode)
489-
.set_output_order_workaround(compile_spec.output_order_workaround)
490408
._set_tosa_dev_mode(compile_spec.tosa_dev_mode)
491409
)

‎docs/source/backends/arm-ethos-u/arm-ethos-u-overview.md‎

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,6 @@ Set a path for dumping TOSA and PTE intermediate results.
7272
Args:
7373
- **output_path**: Path to dump intermediate results to.
7474

75-
```python
76-
def EthosUCompileSpec.get_output_order_workaround(self) -> bool:
77-
```
78-
Gets whether the output order workaround is being applied.
79-
80-
```python
81-
def EthosUCompileSpec.set_output_order_workaround(self, output_order_workaround: bool):
82-
```
83-
Sets whether to apply the output order workaround.
84-
85-
Args:
86-
- **output_order_workaround**: Boolean indicating whether to apply the workaround.
87-
8875
```python
8976
def EthosUCompileSpec.set_pass_pipeline_config(self, config: executorch.backends.arm.common.pipeline_config.ArmPassPipelineConfig) -> None:
9077
```

‎docs/source/backends/arm-vgf/arm-vgf-overview.md‎

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,6 @@ Set a path for dumping TOSA and PTE intermediate results.
6363
Args:
6464
- **output_path**: Path to dump intermediate results to.
6565

66-
```python
67-
def VgfCompileSpec.get_output_order_workaround(self) -> bool:
68-
```
69-
Gets whether the output order workaround is being applied.
70-
71-
```python
72-
def VgfCompileSpec.set_output_order_workaround(self, output_order_workaround: bool):
73-
```
74-
Sets whether to apply the output order workaround.
75-
76-
Args:
77-
- **output_order_workaround**: Boolean indicating whether to apply the workaround.
78-
7966
```python
8067
def VgfCompileSpec.set_pass_pipeline_config(self, config: executorch.backends.arm.common.pipeline_config.ArmPassPipelineConfig) -> None:
8168
```

0 commit comments

Comments
 (0)