Skip to content

Commit c7b6f52

Browse files
committed
Arm backend: exclude RESCALE from late FuseDuplicateUsersPass
Running FuseDuplicateUsersPass after TOSA lowering fuses value-identical tosa.RESCALE users of a shared producer onto one node feeding multiple consumers. Later passes and Vela assume each integer RESCALE feeds a single consumer, so this miscompiles quantized graphs (observed as all-zero Ethos-U55 output for addmm). The nodes are structurally and quantization-identical, so no signature refinement can separate them; exclude tosa.RESCALE from fusion instead. This pass's op-count wins are on TOSA-FP graphs, which carry no rescales, so the exclusion preserves the intended benefit. Update the pass test to assert identical RESCALE users are kept separate. Authored with AI assistance (Claude Code).
1 parent fd9e4d3 commit c7b6f52

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

‎backends/arm/_passes/fuse_duplicate_users_pass.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import torch
1010
from executorch.backends.arm._passes.arm_pass import ArmPass
11+
from executorch.exir.dialects._ops import ops as exir_ops
1112
from executorch.exir.dialects.edge._ops import EdgeOpOverload
1213
from executorch.exir.pass_base import ExportPass, PassResult
1314
from torch._ops import OpOverload
@@ -30,6 +31,14 @@ class FuseDuplicateUsersPass(ArmPass):
3031

3132
_passes_required_after: Set[Type[ExportPass]] = set()
3233

34+
# A fused RESCALE feeds its single output tensor to every original consumer.
35+
# Later passes and the Vela compiler assume each integer RESCALE feeds one
36+
# consumer, so collapsing duplicate RESCALE users onto a shared node corrupts
37+
# integer outputs (observed as all-zero results on Ethos-U). Exclude RESCALE
38+
# from fusion; the op-count wins this pass targets are on FP graphs, which
39+
# carry no rescales.
40+
_excluded_targets = frozenset({exir_ops.backend.tosa.RESCALE.default})
41+
3342
def call(self, graph_module: GraphModule) -> PassResult:
3443
graph = graph_module.graph
3544
modified = False
@@ -95,6 +104,9 @@ def _get_candidate_groups(self, node_order, user_nodes):
95104
if user.op != "call_function":
96105
continue
97106

107+
if user.target in self._excluded_targets:
108+
continue
109+
98110
target_key = self._get_target_key(user.target)
99111
target_signature = (user.op, target_key)
100112
users_by_target.setdefault(target_signature, []).append(user)

‎backends/arm/test/passes/test_fuse_duplicate_users_pass.py‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def test_fuse_duplicate_users_preserves_graph_order_for_representative():
163163
assert len(_add_node_names(result.graph_module)) == 1
164164

165165

166-
def test_fuse_duplicate_users_removes_identical_rescale_users():
166+
def test_fuse_duplicate_users_keeps_identical_rescale_users():
167167
graph_module = _graph_with_duplicate_rescale_users()
168168

169169
with TosaLoweringContext(TosaSpecification.create_from_string("TOSA-1.0+INT")):
@@ -172,10 +172,8 @@ def test_fuse_duplicate_users_removes_identical_rescale_users():
172172
rescale_nodes = _rescale_nodes(result.graph_module)
173173

174174
result.graph_module.graph.lint()
175-
assert result.modified
176-
assert len(rescale_nodes) == 1
177-
output_node = result.graph_module.graph.output_node()
178-
assert output_node.args[0] == (rescale_nodes[0], rescale_nodes[0])
175+
assert not result.modified
176+
assert len(rescale_nodes) == 2
179177

180178

181179
class LateDuplicateUsers(torch.nn.Module):

0 commit comments

Comments
 (0)