@@ -99,49 +99,8 @@ def call(self, exported_program) -> ExportedProgramPassResult:
9999 }
100100 if ops_to_inplace :
101101 reinplace_pass (exported_program , ops_to_inplace = ops_to_inplace )
102- self ._resync_output_specs (exported_program )
103102 return ExportedProgramPassResult (exported_program , True )
104103
105- @staticmethod
106- def _resync_output_specs (exported_program ) -> None :
107- """Re-sync graph-signature output names after reinplace.
108-
109- ``reinplace_pass`` rewrites an output-producing node (e.g. the final
110- ``exp`` -> ``exp_``) via ``replace_all_uses_with`` + erase, but does not
111- update ``graph_signature.output_specs``. Output order is preserved, so we
112- positionally re-sync each spec's argument name to the current output node
113- arg; otherwise ``ExportedProgram.validate()`` (run by the pass manager)
114- raises a SpecViolationError.
115-
116- This positional pairing is only valid because reinplace does a 1:1
117- ``replace_all_uses_with`` + erase and never drops, adds, or reorders
118- outputs. We assert ``len(output_specs) == len(out_args)`` so that a
119- future change violating that invariant fails loudly here instead of
120- silently mis-pairing names (``zip`` would otherwise truncate). Specs
121- whose ``arg`` is not a named tensor (e.g. ``ConstantArgument``) carry no
122- ``name`` and are skipped by the ``getattr`` guard below.
123- """
124- out_node = next (
125- n for n in reversed (exported_program .graph .nodes ) if n .op == "output"
126- )
127- out_args = out_node .args [0 ]
128- if not isinstance (out_args , (tuple , list )):
129- out_args = (out_args ,)
130- output_specs = exported_program .graph_signature .output_specs
131- assert len (output_specs ) == len (out_args ), (
132- "reinplace changed graph output count: "
133- f"{ len (output_specs )} output_specs vs { len (out_args )} output args. "
134- "Positional output-spec re-sync assumes a 1:1, order-preserving "
135- "rewrite."
136- )
137- for spec , arg in zip (output_specs , out_args ):
138- if (
139- isinstance (arg , torch .fx .Node )
140- and getattr (spec .arg , "name" , None ) is not None
141- and spec .arg .name != arg .name
142- ):
143- spec .arg .name = arg .name
144-
145104
146105@dataclass
147106class RMSNormMatch (PatternMatch ):
0 commit comments