10
10
from torch .testing import \
11
11
(make_non_contiguous ,
12
12
_dispatch_dtypes ,
13
- floating_types , floating_types_and ,
13
+ floating_types , floating_types_and , floating_types_and_half ,
14
14
floating_and_complex_types , floating_and_complex_types_and ,
15
15
all_types_and_complex_and )
16
16
from torch .testing ._internal .common_device_type import \
@@ -62,6 +62,7 @@ def __init__(self,
62
62
dtypesIfCPU = None , # dtypes this function is expected to work with on CPU
63
63
dtypesIfCUDA = None , # dtypes this function is expected to work with on CUDA
64
64
dtypesIfROCM = None , # dtypes this function is expected to work with on ROCM
65
+ test_inplace_grad = True , # whether to gradcheck and gradgradcheck the inplace variant
65
66
skips = tuple (), # information about which tests to skip
66
67
decorators = None ): # decorators to apply to generated tests
67
68
# Validates the dtypes are generated from the dispatch-related functions
@@ -83,6 +84,8 @@ def __init__(self,
83
84
inplace_name = name + "_"
84
85
self .inplace_variant = getattr (torch .Tensor , inplace_name ) if hasattr (torch .Tensor , name ) else None
85
86
87
+ self .test_inplace_grad = test_inplace_grad
88
+
86
89
self .skips = skips
87
90
self .decorators = decorators
88
91
@@ -197,7 +200,7 @@ def sample_inputs(self, device, dtype, requires_grad=False):
197
200
198
201
199
202
200
- # Operator database
203
+ # Operator database (sorted alphabetically)
201
204
op_db = [
202
205
# NOTE: CPU complex acos produces incorrect outputs (https://github.com/pytorch/pytorch/issues/42952)
203
206
UnaryUfuncInfo ('acos' ,
@@ -212,13 +215,56 @@ def sample_inputs(self, device, dtype, requires_grad=False):
212
215
device_type = 'cpu' , dtypes = [torch .cfloat , torch .cdouble ]),
213
216
SkipInfo ('TestUnaryUfuncs' , 'test_reference_numerics' ,
214
217
dtypes = [torch .cfloat , torch .cdouble ], active_if = IS_WINDOWS ),
218
+ SkipInfo ('TestUnaryUfuncs' , 'test_reference_numerics' ,
219
+ device_type = 'cuda' , dtypes = [torch .float16 ],
220
+ active_if = TEST_WITH_ROCM ),
215
221
SkipInfo ('TestGradients' , 'test_fn_grad' ,
216
222
dtypes = [torch .cdouble ], active_if = IS_WINDOWS ),
217
223
SkipInfo ('TestGradients' , 'test_method_grad' ,
218
224
dtypes = [torch .cdouble ], active_if = IS_WINDOWS ),
219
225
SkipInfo ('TestGradients' , 'test_inplace_grad' ,
220
226
dtypes = [torch .cdouble ], active_if = IS_WINDOWS ),
221
227
)),
228
+ # NOTE: the derivative for inplace acosh is not implemented
229
+ UnaryUfuncInfo ('acosh' ,
230
+ ref = np .arccosh ,
231
+ domain = (1 , float ('inf' )),
232
+ dtypesIfCPU = floating_types (),
233
+ dtypesIfCUDA = floating_types_and_half (),
234
+ test_inplace_grad = False ),
235
+ UnaryUfuncInfo ('asin' ,
236
+ ref = np .arcsin ,
237
+ domain = (- 1 , 1 ),
238
+ decorators = (precisionOverride ({torch .bfloat16 : 1e-2 }),),
239
+ skips = (
240
+ SkipInfo ('TestUnaryUfuncs' , 'test_reference_numerics' ,
241
+ device_type = 'cpu' , dtypes = [torch .cfloat , torch .cdouble ]),
242
+ SkipInfo ('TestUnaryUfuncs' , 'test_reference_numerics' ,
243
+ device_type = 'cuda' , dtypes = [torch .cfloat , torch .cdouble ],
244
+ active_if = IS_WINDOWS ),
245
+ )),
246
+ # NOTE: derivative for inplace asinh is not implemented
247
+ UnaryUfuncInfo ('asinh' ,
248
+ ref = np .arcsinh ,
249
+ dtypesIfCPU = floating_types (),
250
+ dtypesIfCUDA = floating_types_and_half (),
251
+ test_inplace_grad = False ),
252
+ UnaryUfuncInfo ('atan' ,
253
+ ref = np .arctan ,
254
+ decorators = (precisionOverride ({torch .bfloat16 : 1e-2 }),),
255
+ skips = (
256
+ SkipInfo ('TestUnaryUfuncs' , 'test_reference_numerics' ,
257
+ device_type = 'cpu' , dtypes = [torch .cfloat , torch .cdouble ]),
258
+ SkipInfo ('TestUnaryUfuncs' , 'test_reference_numerics' ,
259
+ device_type = 'cuda' , dtypes = [torch .cfloat , torch .cdouble ],
260
+ active_if = IS_WINDOWS ),
261
+ )),
262
+ UnaryUfuncInfo ('atanh' ,
263
+ ref = np .arctanh ,
264
+ domain = (- 1 , 1 ),
265
+ dtypesIfCPU = floating_types (),
266
+ dtypesIfCUDA = floating_types_and_half (),
267
+ test_inplace_grad = False ),
222
268
UnaryUfuncInfo ('cos' ,
223
269
ref = np .cos ,
224
270
dtypesIfCUDA = floating_and_complex_types_and (torch .half , torch .bfloat16 ),
@@ -241,6 +287,49 @@ def sample_inputs(self, device, dtype, requires_grad=False):
241
287
SkipInfo ('TestUnaryUfuncs' , 'test_reference_numerics' , device_type = 'cpu' ,
242
288
dtypes = [torch .cfloat , torch .cdouble ], active_if = IS_MACOS ),
243
289
)),
290
+ UnaryUfuncInfo ('log' ,
291
+ ref = np .log ,
292
+ domain = (0 , float ('inf' )),
293
+ skips = (
294
+ SkipInfo ('TestUnaryUfuncs' , 'test_reference_numerics' ,
295
+ device_type = 'cpu' , dtypes = [torch .bfloat16 ]),
296
+ SkipInfo ('TestUnaryUfuncs' , 'test_reference_numerics' ,
297
+ device_type = 'cuda' , dtypes = [torch .cfloat , torch .cdouble ]),
298
+ SkipInfo ('TestUnaryUfuncs' , 'test_reference_numerics' ,
299
+ device_type = 'cpu' , dtypes = [torch .cfloat , torch .cdouble ],
300
+ active_if = IS_WINDOWS ),
301
+ )),
302
+ UnaryUfuncInfo ('log10' ,
303
+ ref = np .log10 ,
304
+ domain = (0 , float ('inf' )),
305
+ decorators = (precisionOverride ({torch .bfloat16 : 1e-2 }),),
306
+ skips = (
307
+ SkipInfo ('TestUnaryUfuncs' , 'test_reference_numerics' ,
308
+ device_type = 'cuda' , dtypes = [torch .cfloat , torch .cdouble ]),
309
+ SkipInfo ('TestUnaryUfuncs' , 'test_reference_numerics' ,
310
+ device_type = 'cpu' , dtypes = [torch .cfloat , torch .cdouble ],
311
+ active_if = IS_WINDOWS ),
312
+ )),
313
+ UnaryUfuncInfo ('log1p' ,
314
+ ref = np .log1p ,
315
+ domain = (- 1 , float ('inf' )),
316
+ dtypesIfCPU = floating_types_and (torch .bfloat16 ),
317
+ dtypesIfCUDA = floating_types_and_half (),
318
+ decorators = (precisionOverride ({torch .bfloat16 : 1e-1 }),)),
319
+ UnaryUfuncInfo ('log2' ,
320
+ ref = np .log2 ,
321
+ domain = (0 , float ('inf' )),
322
+ skips = (
323
+ SkipInfo ('TestUnaryUfuncs' , 'test_reference_numerics' ,
324
+ device_type = 'cpu' , dtypes = [torch .bfloat16 ]),
325
+ SkipInfo ('TestUnaryUfuncs' , 'test_reference_numerics' ,
326
+ dtypes = [torch .cfloat , torch .cdouble ]),
327
+ )),
328
+ UnaryUfuncInfo ('neg' ,
329
+ ref = np .negative ,
330
+ dtypes = all_types_and_complex_and (torch .half , torch .bfloat16 ),
331
+ dtypesIfCPU = all_types_and_complex_and (torch .half , torch .bfloat16 ),
332
+ dtypesIfCUDA = all_types_and_complex_and (torch .half )),
244
333
UnaryUfuncInfo ('sin' ,
245
334
ref = np .sin ,
246
335
handles_large_floats = False ,
@@ -252,11 +341,39 @@ def sample_inputs(self, device, dtype, requires_grad=False):
252
341
SkipInfo ('TestUnaryUfuncs' , 'test_reference_numerics' ,
253
342
dtypes = [torch .float ], active_if = TEST_WITH_ROCM ),
254
343
)),
255
- UnaryUfuncInfo ('neg' ,
256
- ref = np .negative ,
257
- dtypes = all_types_and_complex_and (torch .half , torch .bfloat16 ),
258
- dtypesIfCPU = all_types_and_complex_and (torch .half , torch .bfloat16 ),
259
- dtypesIfCUDA = all_types_and_complex_and (torch .half )),
344
+ UnaryUfuncInfo ('sinh' ,
345
+ ref = np .sinh ,
346
+ dtypesIfCPU = floating_and_complex_types (),
347
+ decorators = (precisionOverride ({torch .float16 : 1e-2 }),),
348
+ skips = (
349
+ SkipInfo ('TestUnaryUfuncs' , 'test_reference_numerics' ,
350
+ device_type = 'cpu' , dtypes = [torch .cfloat , torch .cdouble ],
351
+ active_if = (IS_MACOS or IS_WINDOWS )),
352
+ SkipInfo ('TestUnaryUfuncs' , 'test_reference_numerics' ,
353
+ device_type = 'cuda' , dtypes = [torch .cfloat , torch .cdouble ],
354
+ active_if = IS_WINDOWS ),
355
+ )),
356
+ UnaryUfuncInfo ('tan' ,
357
+ ref = np .tan ,
358
+ skips = (
359
+ SkipInfo ('TestUnaryUfuncs' , 'test_reference_numerics' ,
360
+ device_type = 'cuda' , dtypes = [torch .cfloat , torch .cdouble ]),
361
+ SkipInfo ('TestUnaryUfuncs' , 'test_reference_numerics' ,
362
+ device_type = 'cpu' , dtypes = [torch .bfloat16 ]),
363
+ SkipInfo ('TestUnaryUfuncs' , 'test_reference_numerics' ,
364
+ device_type = 'cpu' , dtypes = [torch .cfloat , torch .cdouble ],
365
+ active_if = (IS_MACOS or IS_WINDOWS )),
366
+ )),
367
+ UnaryUfuncInfo ('tanh' ,
368
+ ref = np .tanh ,
369
+ decorators = (precisionOverride ({torch .bfloat16 : 1e-2 }),),
370
+ skips = (
371
+ SkipInfo ('TestUnaryUfuncs' , 'test_reference_numerics' ,
372
+ device_type = 'cuda' , dtypes = [torch .cfloat , torch .cdouble ]),
373
+ SkipInfo ('TestUnaryUfuncs' , 'test_reference_numerics' ,
374
+ device_type = 'cpu' , dtypes = [torch .cfloat , torch .cdouble ],
375
+ active_if = (IS_MACOS or IS_WINDOWS )),
376
+ )),
260
377
]
261
378
262
379
# Common operator groupings
0 commit comments