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

Method define_node

backends/xnnpack/operators/op_max_dim.py:31–96  ·  view source on GitHub ↗
(
        self,
        node: torch.fx.Node,
        xnn_graph: XNNGraph,
        vals_to_ids: Dict[torch.fx.Node, int],
        debug_handle: int,
    )

Source from the content-addressed store, hash-verified

29 super().__init__(*args)
30
31 def define_node(
32 self,
33 node: torch.fx.Node,
34 xnn_graph: XNNGraph,
35 vals_to_ids: Dict[torch.fx.Node, int],
36 debug_handle: int,
37 ) -> None:
38
39 check_or_raise(
40 len(node.args) == 3,
41 "amax.default only supports keep_dim == True",
42 )
43
44 dim_val = cast(int, node.args[1])
45 check_or_raise(
46 dim_val == 2 or dim_val == 3,
47 "amax.default only supports dim == 2 or dim == 3",
48 )
49
50 input_id = vals_to_ids[get_input_node(node, 0)]
51
52 self.define_nodes_tensor_inputs_outputs(
53 node, xnn_graph, vals_to_ids, convert_to_nhwc=True
54 )
55
56 output_id = vals_to_ids[node]
57
58 input_shape = get_tensor_value(xnn_graph.xvalues[input_id]).dims
59 check_or_raise(
60 len(input_shape) == 4, "Require input to max.dim be 4 dimensional"
61 )
62
63 # This is in NHWC
64 pooling_height = 1
65 pooling_width = 1
66 stride_height = 1
67 stride_width = 1
68 if dim_val == 2:
69 pooling_height = input_shape[1]
70 pooling_width = 1
71 stride_height = input_shape[1]
72 elif dim_val == 3:
73 pooling_height = 1
74 pooling_width = input_shape[2]
75 stride_width = input_shape[2]
76
77 ser_node = XNode(
78 xnode_union=XNNMaxPooling2d(
79 padding_top=0,
80 padding_right=0,
81 padding_bottom=0,
82 padding_left=0,
83 pooling_height=pooling_height,
84 pooling_width=pooling_width,
85 stride_height=stride_height,
86 stride_width=stride_width,
87 dilation_height=1,
88 dilation_width=1,

Callers

nothing calls this directly

Calls 7

check_or_raiseFunction · 0.90
get_input_nodeFunction · 0.90
get_tensor_valueFunction · 0.90
XNodeClass · 0.90
XNNMaxPooling2dClass · 0.90
appendMethod · 0.45

Tested by

no test coverage detected