Skip to content

Commit 0e9529a

Browse files
Andrew Pullinfacebook-github-bot
authored andcommitted
Disable _sort_outputs in TOSA backend (MLETORCH-1266) (#17138)
Summary: Disables the _sort_outputs call in the TOSA backend lowering. The _sort_outputs function reorders TOSA flatbuffer outputs, but the runner reads output shapes from original_module (a pre-preprocess copy), creating a mismatch between expected and actual output order. The TOSA reference model preserves flatbuffer order, so no sorting is actually needed. This change prevents the mismatch issue. When output_order_workaround is enabled, the code now logs a debug message indicating the option is set but _sort_outputs is disabled. --- > Generated by [Confucius Code Assist (CCA)](https://www.internalfb.com/wiki/Confucius/Analect/Shared_Analects/Confucius_Code_Assist_(CCA)/) [Confucius Session](https://www.internalfb.com/confucius?host=62602.od.fbinfra.net&port=8086&tab=Chat&session_id=e1d1ac52-0014-11f1-9d55-75b7d4e71d8a&entry_name=Code+Assist), [Trace](https://www.internalfb.com/confucius?session_id=e1d1ac52-0014-11f1-9d55-75b7d4e71d8a&tab=Trace) Differential Revision: D92059044
1 parent 9436714 commit 0e9529a

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

backends/arm/tosa/backend.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
from typing import cast, Dict, final, List
2222

2323
import torch
24-
2524
import tosa_serializer as ts
2625
from executorch.backends.arm.common.arm_compile_spec import ArmCompileSpec
2726
from executorch.backends.arm.common.debug import debug_fail, debug_tosa_dump
@@ -334,7 +333,8 @@ def _preprocess_module( # noqa: C901
334333
335334
"""
336335
tosa_spec = compile_spec.tosa_spec
337-
node_to_id_map = _annotate_external_ids(graph_module.graph)
336+
# node_to_id_map is unused while _sort_outputs is disabled (MLETORCH-1266)
337+
_annotate_external_ids(graph_module.graph)
338338
artifact_path = compile_spec.get_intermediate_path()
339339
output_order_workaround = compile_spec.get_output_order_workaround()
340340

@@ -350,11 +350,16 @@ def _preprocess_module( # noqa: C901
350350

351351
node_visitors = get_node_visitors(edge_program, tosa_spec, debug_hook)
352352

353+
# _sort_outputs is intentionally disabled: it reorders the TOSA
354+
# flatbuffer outputs but the runner reads output shapes from
355+
# original_module (a pre-preprocess copy), creating a mismatch.
356+
# The TOSA reference model preserves flatbuffer order, so no
357+
# sorting is needed.
353358
if output_order_workaround:
354-
logger.debug("Re-sorting outputs during TOSA lowering.")
355-
graph_module = _sort_outputs(graph_module, node_to_id_map)
356-
else:
357-
logger.debug("No re-sorting outputs (workaround) during TOSA lowering.")
359+
logger.debug(
360+
"output_order_workaround is set but _sort_outputs is "
361+
"disabled — see MLETORCH-1266."
362+
)
358363

359364
if submodule_name is not None:
360365
tosa_graph.startRegion(submodule_name)

0 commit comments

Comments
 (0)