MCPcopy Create free account
hub / github.com/pytorch/executorch / call

Method call

backends/mlx/passes.py:172–209  ·  view source on GitHub ↗
(self, graph_module: GraphModule)

Source from the content-addressed store, hash-verified

170 """
171
172 def call(self, graph_module: GraphModule) -> PassResult:
173 graph = graph_module.graph
174 modified = False
175
176 for node in list(graph.nodes):
177 match = RMSNormMatch.maybe_create(node)
178 if match is None:
179 continue
180
181 # Get input shape for normalized_shape
182 input_meta = match.input_node.meta.get("val")
183 if input_meta is None:
184 continue
185
186 # Create fused rms_norm node
187 with graph.inserting_before(node):
188 normalized_shape = [input_meta.shape[-1]]
189 rms_norm_node = graph.call_function(
190 torch.ops.aten.rms_norm.default,
191 args=(
192 match.input_node,
193 normalized_shape,
194 match.weight_node,
195 match.eps,
196 ),
197 )
198 rms_norm_node.meta = node.meta.copy()
199
200 node.replace_all_uses_with(rms_norm_node)
201 match.remove_body_nodes(graph)
202 graph.erase_node(node)
203 modified = True
204
205 if modified:
206 graph.eliminate_dead_code()
207 graph.lint()
208
209 return PassResult(graph_module, modified)
210
211
212class CanonicalizePermutePass(ExportPass):

Callers

nothing calls this directly

Calls 7

inserting_beforeMethod · 0.80
remove_body_nodesMethod · 0.80
erase_nodeMethod · 0.80
maybe_createMethod · 0.45
getMethod · 0.45
call_functionMethod · 0.45
copyMethod · 0.45

Tested by

no test coverage detected