Skip to content

use non-random images for interpolation kernels for testing #6977

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 28, 2022

Conversation

pmeier
Copy link
Collaborator

@pmeier pmeier commented Nov 25, 2022

Fixes #6937 by using option 1. proposed in #6937 (comment).

cc @vfdev-5 @datumbox @bjuncek

@@ -69,6 +70,7 @@ def compare(self) -> None:
self._compare_attributes(actual, expected)

actual, expected = self._equalize_attributes(actual, expected)
actual, expected = self._promote_for_comparison(actual, expected)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a bug. Without this promotion, we are later subtracting uint8 values for the absolute difference. They wrap around:

>>> a = torch.tensor(10, dtype=torch.uint8)
>>> b = torch.tensor(11, dtype=torch.uint8)
>>> a - b
tensor(255, dtype=torch.uint8)
>>> abs(a - b)
tensor(255, dtype=torch.uint8)

If we convert to a singed integer dtype first (here int64) we get the correct absolute diff:

>>> a = torch.tensor(10, dtype=torch.int64)
>>> b = torch.tensor(11, dtype=torch.int64)
>>> a - b
tensor(-1, dtype=torch.int64)
>>> abs(a - b)
tensor(1, dtype=torch.int64)

This bug only affected the comparisons that used agg_method=....

@@ -319,17 +320,6 @@ def sample_inputs_resize_mask():
yield ArgsKwargs(mask_loader, size=[min(mask_loader.shape[-2:]) + 1])


@pil_reference_wrapper
def reference_resize_mask(*args, **kwargs):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since all of our mask kernels are just wrapping the image ones, there is no need to compare both against a reference. Checking the image kernel is sufficient.



def make_image_loaders_for_interpolation(
sizes=((233, 147),),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't use the default shapes here since they are pretty small and thus the area of the border of the ellipse is quite large compared to the overall image and thus larger tolerances would need to be larger. Open for discussion about this.

closeness_kwargs=float32_vs_uint8_pixel_difference(60, agg_method="mean"),
closeness_kwargs={
**float32_vs_uint8_pixel_difference(6, agg_method="mean"),
**cuda_vs_cpu_pixel_difference(),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Driveby that seems to have snuck in since the last time I was testing against CUDA.

),
KernelInfo(
F.elastic_video,
sample_inputs_fn=sample_inputs_elastic_video,
closeness_kwargs=cuda_vs_cpu_pixel_difference(),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

@pmeier pmeier requested review from datumbox and vfdev-5 November 25, 2022 15:34
@pmeier pmeier marked this pull request as ready for review November 25, 2022 15:34
Copy link
Contributor

@datumbox datumbox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. IMO the proposed approach is the better alternative from the other 4 described at #6937 (comment)

Copy link
Collaborator

@vfdev-5 vfdev-5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks !

@pmeier pmeier merged commit 50b77fa into pytorch:main Nov 28, 2022
@pmeier pmeier deleted the fix-proto-tolerances branch November 28, 2022 13:28
facebook-github-bot pushed a commit that referenced this pull request Dec 1, 2022
…6977)

Summary:
* use non-random images for interpolation kernels for testing

* use real image rather than artificial

* cleanup

Reviewed By: YosuaMichael

Differential Revision: D41648540

fbshipit-source-id: d3685e4ade1e6729c64e9ec6002d6914ff070a52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Check tolerances for prototype transforms kernel reference tests
4 participants