Skip to content

Commit e12e637

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 3904346 commit e12e637

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

backends/arm/tosa/backend.py

Lines changed: 9 additions & 5 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
@@ -347,11 +346,16 @@ def _preprocess_module( # noqa: C901
347346

348347
node_visitors = get_node_visitors(edge_program, tosa_spec, debug_hook)
349348

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

356360
if submodule_name is not None:
357361
tosa_graph.startRegion(submodule_name)

0 commit comments

Comments
 (0)