Skip to content

Commit 66d457b

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 09f48cc commit 66d457b

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
@@ -20,7 +20,6 @@
2020
from typing import cast, Dict, final, List
2121

2222
import torch
23-
2423
import tosa_serializer as ts
2524
from executorch.backends.arm.common.arm_compile_spec import ArmCompileSpec
2625
from executorch.backends.arm.common.debug import debug_fail, debug_tosa_dump
@@ -328,7 +327,8 @@ def _preprocess_module( # noqa: C901
328327
329328
"""
330329
tosa_spec = compile_spec.tosa_spec
331-
node_to_id_map = _annotate_external_ids(graph_module.graph)
330+
# node_to_id_map is unused while _sort_outputs is disabled (MLETORCH-1266)
331+
_annotate_external_ids(graph_module.graph)
332332
artifact_path = compile_spec.get_intermediate_path()
333333
output_order_workaround = compile_spec.get_output_order_workaround()
334334

@@ -344,11 +344,16 @@ def _preprocess_module( # noqa: C901
344344

345345
node_visitors = get_node_visitors(edge_program, tosa_spec, debug_hook)
346346

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

353358
if submodule_name is not None:
354359
tosa_graph.startRegion(submodule_name)

0 commit comments

Comments
 (0)