Skip to content

Commit 77b4afa

Browse files
Yosua Michael Maranathafacebook-github-bot
authored andcommitted
[fbsync] add image or video tolerances for CUDA vs CPU tests (#6924)
Reviewed By: NicolasHug Differential Revision: D41265179 fbshipit-source-id: 718bbcb4d333ecff2533f4ec3b9ecd94c03bc0c5
1 parent c5ab007 commit 77b4afa

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

test/prototype_transforms_kernel_infos.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ def __init__(
6666
(("TestKernels", "test_against_reference"), torch.uint8, "cpu"): dict(atol=1e-5, rtol=0, agg_method="mean"),
6767
}
6868

69+
CUDA_VS_CPU_SINGLE_PIXEL_DIFFERENCE = {
70+
(("TestKernels", "test_cuda_vs_cpu"), dtype, "cuda"): dict(atol=atol, rtol=0)
71+
for dtype, atol in [(torch.uint8, 1), (torch.float32, 1 / 255)]
72+
}
73+
6974

7075
def pil_reference_wrapper(pil_kernel):
7176
@functools.wraps(pil_kernel)
@@ -319,7 +324,10 @@ def reference_inputs_resize_bounding_box():
319324
sample_inputs_fn=sample_inputs_resize_image_tensor,
320325
reference_fn=reference_resize_image_tensor,
321326
reference_inputs_fn=reference_inputs_resize_image_tensor,
322-
closeness_kwargs=DEFAULT_PIL_REFERENCE_CLOSENESS_KWARGS,
327+
closeness_kwargs={
328+
**DEFAULT_PIL_REFERENCE_CLOSENESS_KWARGS,
329+
**CUDA_VS_CPU_SINGLE_PIXEL_DIFFERENCE,
330+
},
323331
test_marks=[
324332
xfail_jit_python_scalar_arg("size"),
325333
],
@@ -346,6 +354,7 @@ def reference_inputs_resize_bounding_box():
346354
KernelInfo(
347355
F.resize_video,
348356
sample_inputs_fn=sample_inputs_resize_video,
357+
closeness_kwargs=CUDA_VS_CPU_SINGLE_PIXEL_DIFFERENCE,
349358
),
350359
]
351360
)
@@ -1011,7 +1020,10 @@ def sample_inputs_resized_crop_video():
10111020
sample_inputs_fn=sample_inputs_resized_crop_image_tensor,
10121021
reference_fn=reference_resized_crop_image_tensor,
10131022
reference_inputs_fn=reference_inputs_resized_crop_image_tensor,
1014-
closeness_kwargs=DEFAULT_PIL_REFERENCE_CLOSENESS_KWARGS,
1023+
closeness_kwargs={
1024+
**DEFAULT_PIL_REFERENCE_CLOSENESS_KWARGS,
1025+
**CUDA_VS_CPU_SINGLE_PIXEL_DIFFERENCE,
1026+
},
10151027
),
10161028
KernelInfo(
10171029
F.resized_crop_bounding_box,
@@ -1027,6 +1039,7 @@ def sample_inputs_resized_crop_video():
10271039
KernelInfo(
10281040
F.resized_crop_video,
10291041
sample_inputs_fn=sample_inputs_resized_crop_video,
1042+
closeness_kwargs=CUDA_VS_CPU_SINGLE_PIXEL_DIFFERENCE,
10301043
),
10311044
]
10321045
)
@@ -1226,7 +1239,10 @@ def sample_inputs_perspective_video():
12261239
sample_inputs_fn=sample_inputs_perspective_image_tensor,
12271240
reference_fn=pil_reference_wrapper(F.perspective_image_pil),
12281241
reference_inputs_fn=reference_inputs_perspective_image_tensor,
1229-
closeness_kwargs=DEFAULT_PIL_REFERENCE_CLOSENESS_KWARGS,
1242+
closeness_kwargs={
1243+
**DEFAULT_PIL_REFERENCE_CLOSENESS_KWARGS,
1244+
**CUDA_VS_CPU_SINGLE_PIXEL_DIFFERENCE,
1245+
},
12301246
),
12311247
KernelInfo(
12321248
F.perspective_bounding_box,
@@ -1242,6 +1258,7 @@ def sample_inputs_perspective_video():
12421258
KernelInfo(
12431259
F.perspective_video,
12441260
sample_inputs_fn=sample_inputs_perspective_video,
1261+
closeness_kwargs=CUDA_VS_CPU_SINGLE_PIXEL_DIFFERENCE,
12451262
),
12461263
]
12471264
)
@@ -1442,7 +1459,10 @@ def sample_inputs_gaussian_blur_video():
14421459
KernelInfo(
14431460
F.gaussian_blur_image_tensor,
14441461
sample_inputs_fn=sample_inputs_gaussian_blur_image_tensor,
1445-
closeness_kwargs=DEFAULT_PIL_REFERENCE_CLOSENESS_KWARGS,
1462+
closeness_kwargs={
1463+
**DEFAULT_PIL_REFERENCE_CLOSENESS_KWARGS,
1464+
**CUDA_VS_CPU_SINGLE_PIXEL_DIFFERENCE,
1465+
},
14461466
test_marks=[
14471467
xfail_jit_python_scalar_arg("kernel_size"),
14481468
xfail_jit_python_scalar_arg("sigma"),
@@ -1451,6 +1471,7 @@ def sample_inputs_gaussian_blur_video():
14511471
KernelInfo(
14521472
F.gaussian_blur_video,
14531473
sample_inputs_fn=sample_inputs_gaussian_blur_video,
1474+
closeness_kwargs=CUDA_VS_CPU_SINGLE_PIXEL_DIFFERENCE,
14541475
),
14551476
]
14561477
)

0 commit comments

Comments
 (0)