Skip to content
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

add test for dispatcher kernel signature consistency #6904

Merged
merged 8 commits into from
Nov 7, 2022

Conversation

pmeier
Copy link
Collaborator

@pmeier pmeier commented Nov 4, 2022

This test makes sure the dispatchers and the kernels have the "same" signature within the rules we defined for exceptions. Meaning,

  1. The kernels are allowed to require extra metadata that is only passed explicitly to the dispatcher through the feature, e.g.

    def horizontal_flip(inpt: features.InputTypeJIT) -> features.InputTypeJIT:

    def horizontal_flip_bounding_box(
    bounding_box: torch.Tensor, format: features.BoundingBoxFormat, spatial_size: Tuple[int, int]
    ) -> torch.Tensor:

  2. The kernels are allowed to "drop" some parameters if they are nonsensical for the feature type in question, e.g.

    def resize(
    inpt: features.InputTypeJIT,
    size: List[int],
    interpolation: InterpolationMode = InterpolationMode.BILINEAR,
    max_size: Optional[int] = None,
    antialias: Optional[bool] = None,
    ) -> features.InputTypeJIT:

    def resize_mask(mask: torch.Tensor, size: List[int], max_size: Optional[int] = None) -> torch.Tensor:

Currently there are two failures:

_____________ TestDispatchers.test_dispatcher_kernel_signatures_consistency[resize-Image] _____________
Traceback (most recent call last):
  File "/home/user/vision/test/test_prototype_transforms_functional.py", line 351, in test_dispatcher_kernel_signatures_consistency
    assert dispatcher_param == kernel_param
AssertionError: assert <Parameter "antialias: Union[bool, NoneType] = None"> == <Parameter "antialias: bool = False">
__________ TestDispatchers.test_dispatcher_kernel_signatures_consistency[resized_crop-Image] __________
Traceback (most recent call last):
  File "/home/user/vision/test/test_prototype_transforms_functional.py", line 351, in test_dispatcher_kernel_signatures_consistency
    assert dispatcher_param == kernel_param
AssertionError: assert <Parameter "antialias: Union[bool, NoneType] = None"> == <Parameter "antialias: bool = False">

I don't know if they are deliberate or not.

cc @vfdev-5 @datumbox @bjuncek

@pmeier
Copy link
Collaborator Author

pmeier commented Nov 4, 2022

If you like me are wondering why the video kernels are not showing up, although they have the same issue as the image kernels above: we simply forgot to "tell" our tests that the dispatchers now also handle videos. See #6905 for a fix.

@datumbox
Copy link
Contributor

datumbox commented Nov 4, 2022

@pmeier Thanks for the fix. Will this handle cases where we have declared things optional like in #6902?

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, thanks!

@pmeier pmeier merged commit e3f7baa into pytorch:main Nov 7, 2022
@pmeier pmeier deleted the dispatcher-kernel-signature branch November 7, 2022 13:31
facebook-github-bot pushed a commit that referenced this pull request Nov 14, 2022
Summary:
* add test for dispatcher kernel signature consistency

* add dispatcher feature signature consistency test

* fix error message

Reviewed By: NicolasHug

Differential Revision: D41265185

fbshipit-source-id: 50274734d755875f7b3ffb858d82c13b53338a4d

Co-authored-by: Vasilis Vryniotis <datumbox@users.noreply.github.com>
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.

3 participants