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

Allow register_kernel() to take dispatcher name as input #7796

Merged
merged 3 commits into from
Aug 3, 2023

Conversation

NicolasHug
Copy link
Member

@NicolasHug NicolasHug commented Aug 2, 2023

plus some minor tests for register_kernel.

Writing the tutorials in #7795 I thought that we should allow to register kernels by name, not just by callables. Typically if I'm a dev and I just care about Resize() (the transform class), I should just be able to register my kernel with @register_kernel("resize", MyDatapoint) instead of having to do @register_kernel(resize, MyDatapoint) which forces me to import the functional dispatcher for no obvious reason.

Side note: I thought about allowing the transform name as well e.g. @register_kernel("Resize", MyDatapoint), but I don't think we should do that because that won't work in general anyway, as some transforms rely on more than one dispatcher.

cc @vfdev-5

@NicolasHug NicolasHug requested a review from pmeier August 2, 2023 20:48
@pytorch-bot
Copy link

pytorch-bot bot commented Aug 2, 2023

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/vision/7796

Note: Links to docs will display an error until the docs builds have been completed.

❌ 1 New Failure, 2 Unrelated Failures

As of commit 12fb8e1:

NEW FAILURE - The following job has failed:

BROKEN TRUNK - The following jobs failed but were present on the merge base f3c89cc:

👉 Rebase onto the `viable/strict` branch to avoid these failures

This comment was automatically generated by Dr. CI and updates every 15 minutes.

import torchvision.transforms.v2.functional # noqa

try:
return next(
Copy link
Member Author

Choose a reason for hiding this comment

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

Not the most efficient, we could store the mapping somewhere. I don't think we care anyway since this is just executed during registration, not when calling the dispatcher.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure I understand the iteration here. Can't we just do

try:
    return getattr(torchvision.transforms.v2.functional, name)
except AttributeError:
    raise ValueError(...) from None

Copy link
Member Author

Choose a reason for hiding this comment

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

yes much better!

Copy link
Collaborator

@pmeier pmeier left a comment

Choose a reason for hiding this comment

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

I'm ok with this.

Side note: I thought about allowing the transform name as well e.g. @register_kernel("Resize", MyDatapoint), but I don't think we should do that because that won't work in general anyway, as some transforms rely on more than one dispatcher.

👍 for the reason you mentioned.

import torchvision.transforms.v2.functional # noqa

try:
return next(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure I understand the iteration here. Can't we just do

try:
    return getattr(torchvision.transforms.v2.functional, name)
except AttributeError:
    raise ValueError(...) from None

@NicolasHug NicolasHug merged commit 9ebf10a into pytorch:main Aug 3, 2023
58 of 61 checks passed
facebook-github-bot pushed a commit that referenced this pull request Aug 25, 2023
)

Reviewed By: matteobettini

Differential Revision: D48642284

fbshipit-source-id: ae6e8bb56a1921bfdd0baddefe48c32f48b79f65
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