(self, graph_module: GraphModule)
| 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 | |
| 212 | class CanonicalizePermutePass(ExportPass): |
nothing calls this directly
no test coverage detected