(
self,
node: torch.fx.Node,
xnn_graph: XNNGraph,
vals_to_ids: Dict[torch.fx.Node, int],
debug_handle: int,
)
| 104 | super().__init__(*args) |
| 105 | |
| 106 | def define_node( |
| 107 | self, |
| 108 | node: torch.fx.Node, |
| 109 | xnn_graph: XNNGraph, |
| 110 | vals_to_ids: Dict[torch.fx.Node, int], |
| 111 | debug_handle: int, |
| 112 | ) -> None: |
| 113 | |
| 114 | check_or_raise( |
| 115 | len(node.args) == 3, |
| 116 | "max.dim only supports keep_dim == True", |
| 117 | ) |
| 118 | |
| 119 | dim_val = cast(int, node.args[1]) |
| 120 | check_or_raise( |
| 121 | dim_val == 2 or dim_val == 3, |
| 122 | "max.dim only supports dim == 2 or dim == 3", |
| 123 | ) |
| 124 | |
| 125 | # node.meta["val"] is a tuple (values_tensor, indices_tensor) |
| 126 | # We don't care about how it is defined, so we can adjust val to be a |
| 127 | # single tensor rather than a tuple arbitrarily just to make |
| 128 | # define_nodes_tensor_inputs_outputs work |
| 129 | original_val = node.meta["val"] |
| 130 | node.meta["val"] = original_val[0] |
| 131 | |
| 132 | self.define_nodes_tensor_inputs_outputs( |
| 133 | node, xnn_graph, vals_to_ids, convert_to_nhwc=True |
| 134 | ) |
| 135 | for user in node.users: |
| 136 | self.define_nodes_tensor_inputs_outputs( |
| 137 | user, xnn_graph, vals_to_ids, convert_to_nhwc=True |
| 138 | ) |
| 139 | |
| 140 | # Restore node.meta["val"] |
| 141 | node.meta["val"] = original_val |
| 142 | |
| 143 | input_id = vals_to_ids[get_input_node(node, 0)] |
| 144 | |
| 145 | input_shape = get_tensor_value(xnn_graph.xvalues[input_id]).dims |
| 146 | check_or_raise( |
| 147 | len(input_shape) == 4, "Require input to max.dim be 4 dimensional" |
| 148 | ) |
| 149 | |
| 150 | users = list(node.users.keys()) |
| 151 | |
| 152 | if len(users) != 2: |
| 153 | raise AssertionError( |
| 154 | f"Invalid number of users for max.dim (Expected 2, Got: {len(users)})" |
| 155 | ) |
| 156 | |
| 157 | values_node = None |
| 158 | indices_node = None |
| 159 | |
| 160 | for getitem_node in users: |
| 161 | taget_name = cast(torch._ops.OpOverload, getitem_node.target).__name__ |
| 162 | if taget_name != "getitem": |
| 163 | raise AssertionError( |
nothing calls this directly
no test coverage detected