1414 Partitioner ,
1515 PartitionResult ,
1616)
17- from executorch .exir .backend .utils import tag_constant_data , tag_mutated_buffer
17+ from executorch .exir .backend .utils import (
18+ get_non_lowered_nodes ,
19+ tag_constant_data ,
20+ tag_mutated_buffer ,
21+ )
1822from torch ._export .utils import is_buffer , is_lifted_tensor_constant , is_param
1923from torch .export .exported_program import ExportedProgram
2024
@@ -60,8 +64,17 @@ def is_control_flow(node: torch.fx.Node) -> bool:
6064 torch .ops .higher_order .while_loop ,
6165 ]
6266
67+ # Nodes already lowered by an earlier partitioner (e.g. a preceding
68+ # TensorRT partition) appear as executorch_call_delegate calls and their
69+ # output getitems; re-delegating them would nest a foreign delegate. Tag
70+ # only the remaining non-lowered ops so this partitioner composes after
71+ # others.
72+ non_lowered_nodes = set (get_non_lowered_nodes (exported_program .graph ))
73+
6374 for node in exported_program .graph .nodes :
6475 if node .op == "call_function" :
76+ if node not in non_lowered_nodes :
77+ continue
6578 node .meta ["delegation_tag" ] = tag
6679 # Tag get_attr nodes that are used by control flow operations
6780 elif node .op == "get_attr" :
@@ -76,17 +89,22 @@ def is_control_flow(node: torch.fx.Node) -> bool:
7689 tag_constant_data (exported_program )
7790 tag_mutated_buffer (exported_program )
7891
79- # Tag constant placeholders that have no users
80- # tag_constant_data only tags constants that have users with delegation_tag
81- # but we need to tag all constants for this partition
92+ # A constant that still has users feeds only a prior delegate; tagging it
93+ # would fail backend lowering's same-tag check (its user keeps the prior
94+ # tag). tag_constant_data already claimed the ones this partition uses, so
95+ # tag only the genuinely unused constants here.
8296 for node in exported_program .graph .nodes :
83- if node .op == "placeholder" and (
84- is_param (exported_program , node )
85- or is_buffer (exported_program , node )
86- or is_lifted_tensor_constant (exported_program , node )
97+ if (
98+ node .op == "placeholder"
99+ and not node .users
100+ and "delegation_tag" not in node .meta
101+ and (
102+ is_param (exported_program , node )
103+ or is_buffer (exported_program , node )
104+ or is_lifted_tensor_constant (exported_program , node )
105+ )
87106 ):
88- if "delegation_tag" not in node .meta :
89- node .meta ["delegation_tag" ] = tag
107+ node .meta ["delegation_tag" ] = tag
90108
91109 return PartitionResult (
92110 tagged_exported_program = exported_program , partition_tags = partition_tags
0 commit comments