(self, final_mul_node: torch.fx.Node)
| 58 | """ |
| 59 | |
| 60 | def __init__(self, final_mul_node: torch.fx.Node) -> None: # noqa: C901 |
| 61 | self.anchor_node = final_mul_node |
| 62 | self.match_found = False |
| 63 | self.all_nodes = [self.anchor_node] |
| 64 | |
| 65 | # final_mul: mul(normalized_cast, weight_cast) |
| 66 | # Unwrap casts to reach the underlying norm_mul and weight. |
| 67 | norm_mul_node, self.weight_node = self._identify_norm_mul_and_weight( |
| 68 | final_mul_node |
| 69 | ) |
| 70 | if norm_mul_node is None: |
| 71 | return |
| 72 | |
| 73 | self.all_nodes.append(norm_mul_node) |
| 74 | |
| 75 | # norm_mul: mul(x_f32, rstd_f32) |
| 76 | rsqrt_node, x_for_norm = self._identify_rsqrt_and_input(norm_mul_node) |
| 77 | if rsqrt_node is None: |
| 78 | return |
| 79 | |
| 80 | self.all_nodes.append(rsqrt_node) |
| 81 | |
| 82 | # rsqrt -> add(mean_sq, eps) -> mean(x_sq, dim=-1, keepdim=True) |
| 83 | add_node = self._get_single_arg_node( |
| 84 | rsqrt_node, exir_ops.edge.aten.rsqrt.default |
| 85 | ) |
| 86 | if add_node is None or add_node.target != exir_ops.edge.aten.add.Tensor: |
| 87 | return |
| 88 | |
| 89 | self.all_nodes.append(add_node) |
| 90 | |
| 91 | self.eps_node = None |
| 92 | mean_node = None |
| 93 | for arg in add_node.args[:2]: |
| 94 | if ( |
| 95 | isinstance(arg, torch.fx.Node) |
| 96 | and arg.target == exir_ops.edge.aten.mean.dim |
| 97 | ): |
| 98 | mean_node = arg |
| 99 | else: |
| 100 | self.eps_node = arg |
| 101 | |
| 102 | if mean_node is None or self.eps_node is None: |
| 103 | return |
| 104 | |
| 105 | self.all_nodes.append(mean_node) |
| 106 | |
| 107 | # Verify mean has keepdim=True and dim=[-1] |
| 108 | if len(mean_node.args) < 3: |
| 109 | return |
| 110 | mean_dims = mean_node.args[1] |
| 111 | if mean_dims != [-1]: |
| 112 | return |
| 113 | if not mean_node.args[2]: |
| 114 | return |
| 115 | |
| 116 | # mean's input should be x_sq = mul(x, x) or pow(x, 2) |
| 117 | sq_node = mean_node.args[0] |
nothing calls this directly
no test coverage detected