@@ -214,10 +214,16 @@ def register_fake(
214214)
215215
216216lib .define (
217- "quantized_max_pool2d (Tensor input, int[] kernel_size, int[] stride, int[] padding, int[] dilation, bool ceil_mode) -> Tensor"
217+ "quantized_max_pool2d_nchw (Tensor input, int[] kernel_size, int[] stride, int[] padding, int[] dilation, bool ceil_mode) -> Tensor"
218218)
219219lib .define (
220- "quantized_max_pool2d.out(Tensor input, int[] kernel_size, int[] stride, int[] padding, int[] dilation, bool ceil_mode, *, Tensor(a!) out) -> Tensor(a!)"
220+ "quantized_max_pool2d_nchw.out(Tensor input, int[] kernel_size, int[] stride, int[] padding, int[] dilation, bool ceil_mode, *, Tensor(a!) out) -> Tensor(a!)"
221+ )
222+ lib .define (
223+ "quantized_max_pool2d_nhwc(Tensor input, int[] kernel_size, int[] stride, int[] padding, int[] dilation, bool ceil_mode) -> Tensor"
224+ )
225+ lib .define (
226+ "quantized_max_pool2d_nhwc.out(Tensor input, int[] kernel_size, int[] stride, int[] padding, int[] dilation, bool ceil_mode, *, Tensor(a!) out) -> Tensor(a!)"
221227)
222228
223229lib .define (
@@ -2301,8 +2307,8 @@ def quantized_relu_asym8u_asym8u_per_tensor_meta(
23012307 return input .new_empty (input .size (), dtype = input .dtype )
23022308
23032309
2304- @register_fake ("cadence::quantized_max_pool2d " )
2305- def quantized_max_pool2d_meta (
2310+ @register_fake ("cadence::quantized_max_pool2d_nchw " )
2311+ def quantized_max_pool2d_nchw_meta (
23062312 input : torch .Tensor ,
23072313 kernel_size : list [int ],
23082314 stride : list [int ],
@@ -2342,6 +2348,47 @@ def quantized_max_pool2d_meta(
23422348 return input .new_empty ([batch , channels , height_out , width_out ], dtype = input .dtype )
23432349
23442350
2351+ @register_fake ("cadence::quantized_max_pool2d_nhwc" )
2352+ def quantized_max_pool2d_nhwc_meta (
2353+ input : torch .Tensor ,
2354+ kernel_size : list [int ],
2355+ stride : list [int ],
2356+ padding : list [int ],
2357+ dilation : list [int ],
2358+ ceil_mode : bool ,
2359+ ) -> torch .Tensor :
2360+ assert (
2361+ len (kernel_size ) == 2
2362+ ), f"kernel_size must have 2 elements, got { len (kernel_size )} "
2363+ assert len (stride ) == 2 , f"stride must have 2 elements, got { len (stride )} "
2364+ assert len (padding ) == 2 , f"padding must have 2 elements, got { len (padding )} "
2365+ assert len (dilation ) == 2 , f"dilation must have 2 elements, got { len (dilation )} "
2366+ assert (
2367+ len (input .size ()) == 4
2368+ ), f"input must be 4D (N, H, W, C), got { len (input .size ())} D"
2369+
2370+ batch = input .size (0 )
2371+ height_in = input .size (1 )
2372+ width_in = input .size (2 )
2373+ channels = input .size (3 )
2374+
2375+ height_out_raw = (
2376+ height_in + 2 * padding [0 ] - dilation [0 ] * (kernel_size [0 ] - 1 ) - 1
2377+ ) / stride [0 ] + 1
2378+ width_out_raw = (
2379+ width_in + 2 * padding [1 ] - dilation [1 ] * (kernel_size [1 ] - 1 ) - 1
2380+ ) / stride [1 ] + 1
2381+
2382+ if ceil_mode :
2383+ height_out = ceil (height_out_raw )
2384+ width_out = ceil (width_out_raw )
2385+ else :
2386+ height_out = int (height_out_raw )
2387+ width_out = int (width_out_raw )
2388+
2389+ return input .new_empty ([batch , height_out , width_out , channels ], dtype = input .dtype )
2390+
2391+
23452392@register_fake ("cadence::fully_connected" )
23462393def fully_connected_meta (
23472394 src : torch .Tensor ,
0 commit comments