@@ -2197,85 +2197,99 @@ def aten_unflatten_dense_tensors(
2197
2197
raise NotImplementedError ()
2198
2198
2199
2199
2200
- @torch_op (("aten::upsample_bicubic2d" , "aten::upsample_bicubic2d.vec" ), trace_only = True )
2201
- def aten_upsample_bicubic2d (
2202
- self : TReal ,
2203
- output_size : INT64 ,
2204
- align_corners : bool ,
2205
- scale_factors : Optional [TFloat ] = None ,
2206
- ) -> TReal :
2207
- """upsample_bicubic2d.vec(Tensor input, SymInt[]? output_size, bool align_corners, float[]? scale_factors) -> Tensor
2208
- upsample_bicubic2d(Tensor self, SymInt[2] output_size, bool align_corners, float? scales_h=None, float? scales_w=None) -> Tensor
2209
- """
2210
-
2211
- if output_size is not None :
2212
- result = _aten_upsample_output_size (self , output_size , align_corners , "cubic" )
2213
- else :
2214
- result = _aten_upsample_scales (self , scale_factors , align_corners , "cubic" )
2215
- return result
2200
+ def _get_upsample_align_corners_mode (align_corners : bool ) -> str :
2201
+ return "align_corners" if align_corners else "pytorch_half_pixel"
2216
2202
2217
2203
2218
- @torch_op ("aten::upsample_bicubic2d" , private = True )
2204
+ @torch_op (( "aten::upsample_bicubic2d" , "aten::upsample_bilinear2d" ) , private = True )
2219
2205
def _aten_upsample_output_size (
2220
2206
self : TReal ,
2221
2207
output_size : INT64 ,
2222
- align_corners : bool ,
2223
- str_mode : str ,
2208
+ mode : str ,
2209
+ coordinate_transformation_mode : str ,
2224
2210
) -> TReal :
2225
2211
self_shape = op .Shape (self )
2226
2212
starts = op .Constant (value_ints = [0 ])
2227
2213
ends = op .Constant (value_ints = [2 ])
2228
2214
batch_channel = op .Slice (self_shape , starts , ends )
2229
2215
output_size = op .Concat (batch_channel , output_size , axis = 0 )
2230
- if align_corners :
2231
- result = op .Resize (
2232
- self ,
2233
- None ,
2234
- None ,
2235
- output_size ,
2236
- mode = str_mode ,
2237
- coordinate_transformation_mode = "align_corners" ,
2238
- )
2239
- else :
2240
- result = op .Resize (
2241
- self ,
2242
- None ,
2243
- None ,
2244
- output_size ,
2245
- mode = str_mode ,
2246
- coordinate_transformation_mode = "pytorch_half_pixel" ,
2247
- )
2248
-
2249
- return result
2216
+ return op .Resize (
2217
+ self ,
2218
+ None ,
2219
+ None ,
2220
+ output_size ,
2221
+ mode = mode ,
2222
+ coordinate_transformation_mode = coordinate_transformation_mode ,
2223
+ nearest_mode = "floor" ,
2224
+ )
2250
2225
2251
2226
2252
- @torch_op ("aten::upsample_bicubic2d" , private = True )
2227
+ @torch_op (( "aten::upsample_bicubic2d" , "aten::upsample_bilinear2d" ) , private = True )
2253
2228
def _aten_upsample_scales (
2254
2229
self : TReal ,
2255
2230
scale_factors : TFloat ,
2256
- align_corners : bool ,
2257
- str_mode : str ,
2231
+ mode : str ,
2232
+ coordinate_transformation_mode : str ,
2258
2233
) -> TReal :
2259
2234
scale_factors = op .Cast (scale_factors , to = FLOAT .dtype )
2260
2235
scale_factors = op .Concat (op .Constant (value_floats = [1.0 , 1.0 ]), scale_factors , axis = 0 )
2261
- if align_corners :
2262
- result = op .Resize (
2236
+ return op .Resize (
2237
+ self ,
2238
+ None ,
2239
+ scale_factors , # format should be: [1.0, 1.0, scale_h, scale_w]
2240
+ None ,
2241
+ mode = mode ,
2242
+ coordinate_transformation_mode = coordinate_transformation_mode ,
2243
+ nearest_mode = "floor" ,
2244
+ )
2245
+
2246
+
2247
+ @torch_op ("aten::upsample_bicubic2d" , trace_only = True )
2248
+ def aten_upsample_bicubic2d (
2249
+ self : TReal ,
2250
+ output_size : INT64 ,
2251
+ align_corners : bool ,
2252
+ scales_h : Optional [float ] = None ,
2253
+ scales_w : Optional [float ] = None ,
2254
+ ) -> TReal :
2255
+ """upsample_bicubic2d(Tensor self, SymInt[2] output_size, bool align_corners, float? scales_h=None, float? scales_w=None) -> Tensor"""
2256
+
2257
+ # NOTE: Based on experimentation, scales_h and scales_w are always ignored in PyTorch,
2258
+ # unless when align_corners is True, in which case we do not know what is going on.
2259
+ coordinate_transformation_mode = _get_upsample_align_corners_mode (align_corners )
2260
+ return _aten_upsample_output_size (
2261
+ self ,
2262
+ output_size ,
2263
+ mode = "cubic" ,
2264
+ coordinate_transformation_mode = coordinate_transformation_mode ,
2265
+ )
2266
+
2267
+
2268
+ @torch_op ("aten::upsample_bicubic2d.vec" , trace_only = True )
2269
+ def aten_upsample_bicubic2d_vec (
2270
+ self : TReal ,
2271
+ output_size : INT64 ,
2272
+ align_corners : bool ,
2273
+ scale_factors : Optional [Sequence [float ]],
2274
+ ) -> TReal :
2275
+ """upsample_bicubic2d.vec(Tensor input, SymInt[]? output_size, bool align_corners, float[]? scale_factors) -> Tensor"""
2276
+
2277
+ coordinate_transformation_mode = _get_upsample_align_corners_mode (align_corners )
2278
+ if scale_factors is not None :
2279
+ result = _aten_upsample_scales (
2263
2280
self ,
2264
- None ,
2265
- scale_factors , # format should be: [1.0, 1.0, scale_h, scale_w]
2266
- None ,
2267
- mode = str_mode ,
2268
- coordinate_transformation_mode = "align_corners" ,
2281
+ op .Constant (value_floats = scale_factors ),
2282
+ mode = "cubic" ,
2283
+ coordinate_transformation_mode = coordinate_transformation_mode ,
2269
2284
)
2270
2285
else :
2271
- result = op . Resize (
2286
+ result = _aten_upsample_output_size (
2272
2287
self ,
2273
- None ,
2274
- scale_factors , # format should be: [1.0, 1.0, scale_h, scale_w]
2275
- None ,
2276
- mode = str_mode ,
2277
- coordinate_transformation_mode = "pytorch_half_pixel" ,
2288
+ output_size ,
2289
+ mode = "cubic" ,
2290
+ coordinate_transformation_mode = coordinate_transformation_mode ,
2278
2291
)
2292
+
2279
2293
return result
2280
2294
2281
2295
@@ -2295,67 +2309,50 @@ def aten_upsample_bicubic2d_backward(
2295
2309
@torch_op ("aten::upsample_bilinear2d" , trace_only = True )
2296
2310
def aten_upsample_bilinear2d (
2297
2311
self : TReal ,
2298
- output_size : Optional [INT64 ] = None ,
2312
+ output_size : INT64 ,
2313
+ align_corners : bool ,
2299
2314
scales_h : Optional [float ] = None ,
2300
2315
scales_w : Optional [float ] = None ,
2301
- align_corners : bool = True , # pylint: disable=unused-argument
2302
- ) -> TReal :
2303
- """upsample_bilinear2d(Tensor self, SymInt[2] output_size, bool align_corners, float? scales_h=None, float? scales_w=None) -> Tensor"""
2304
-
2305
- if output_size is not None :
2306
- result = _aten_upsample_bilinear2d_output_size (self , output_size )
2307
- else :
2308
- assert scales_h is not None
2309
- assert scales_h == scales_w
2310
- result = _aten_upsample_bilinear2d_scales (self , scales_h , scales_w )
2311
- return result
2312
-
2313
-
2314
- @torch_op ("aten::upsample_bilinear2d" , private = True )
2315
- def _aten_upsample_bilinear2d_output_size (
2316
- self : TReal ,
2317
- output_size : INT64 ,
2318
2316
) -> TReal :
2319
2317
"""upsample_bilinear2d(Tensor self, SymInt[2] output_size, bool align_corners, float? scales_h=None, float? scales_w=None) -> Tensor"""
2320
2318
2321
- self_shape = op .Shape (self )
2322
- starts = op .Constant (value_ints = [0 ])
2323
- ends = op .Constant (value_ints = [2 ])
2324
- batch_channel = op .Slice (self_shape , starts , ends )
2325
- output_size = op .Concat (batch_channel , output_size , axis = 0 )
2326
- return op .Resize (
2319
+ # NOTE: Based on experimentation, scales_h and scales_w are always ignored in PyTorch,
2320
+ # unless when align_corners is True, in which case we do not know what is going on.
2321
+ coordinate_transformation_mode = _get_upsample_align_corners_mode (align_corners )
2322
+ return _aten_upsample_output_size (
2327
2323
self ,
2328
- None ,
2329
- None ,
2330
2324
output_size ,
2325
+ coordinate_transformation_mode = coordinate_transformation_mode ,
2331
2326
mode = "linear" ,
2332
- coordinate_transformation_mode = "align_corners" ,
2333
2327
)
2334
2328
2335
2329
2336
- @torch_op ("aten::upsample_bilinear2d" , private = True )
2337
- def _aten_upsample_bilinear2d_scales (
2330
+ @torch_op ("aten::upsample_bilinear2d.vec " , trace_only = True )
2331
+ def aten_upsample_bilinear2d_vec (
2338
2332
self : TReal ,
2339
- scales_h : float ,
2340
- scales_w : float ,
2333
+ output_size : Optional [INT64 ],
2334
+ align_corners : bool ,
2335
+ scale_factors : Optional [Sequence [float ]],
2341
2336
) -> TReal :
2342
- """upsample_bilinear2d(Tensor self , SymInt[2] output_size, bool align_corners, float? scales_h=None, float? scales_w=None ) -> Tensor"""
2337
+ """upsample_bilinear2d.vec (Tensor input , SymInt[]? output_size, bool align_corners, float[]? scale_factors ) -> Tensor"""
2343
2338
2344
- neg_1 = op .Constant (value_ints = [- 1 ])
2345
- scales = op .Concat (
2346
- op .Constant (value_floats = [1.0 , 1.0 ]),
2347
- op .Reshape (op .Constant (value_float = scales_h ), neg_1 ),
2348
- op .Reshape (op .Constant (value_float = scales_w ), neg_1 ),
2349
- axis = 0 ,
2350
- )
2351
- return op .Resize (
2352
- self ,
2353
- None ,
2354
- scales , # format should be: [1.0, 1.0, scale_h, scale_w]
2355
- None ,
2356
- mode = "linear" ,
2357
- coordinate_transformation_mode = "align_corners" ,
2358
- )
2339
+ coordinate_transformation_mode = _get_upsample_align_corners_mode (align_corners )
2340
+ if scale_factors is not None :
2341
+ result = _aten_upsample_scales (
2342
+ self ,
2343
+ op .Constant (value_floats = scale_factors ),
2344
+ mode = "linear" ,
2345
+ coordinate_transformation_mode = coordinate_transformation_mode ,
2346
+ )
2347
+ else :
2348
+ result = _aten_upsample_output_size (
2349
+ self ,
2350
+ output_size ,
2351
+ mode = "linear" ,
2352
+ coordinate_transformation_mode = coordinate_transformation_mode ,
2353
+ )
2354
+
2355
+ return result
2359
2356
2360
2357
2361
2358
def aten_upsample_bilinear2d_backward (
0 commit comments