Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
enable get_params alias for transforms v2 #7153
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
enable get_params alias for transforms v2 #7153
Changes from all commits
7fb1b98
ed487b7
8d72a24
7618d38
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As an alternative to
__init_subclass__()
(of which I keep forgetting the existence and the purpose), would this work too?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two problems here with JIT:
get_params
takes parameters in v1, e.g.vision/torchvision/transforms/transforms.py
Lines 617 to 618 in 7cf0f4c
Since I'm not aware of an arbitrary parameter passthrough like
(*args: Any, **kwargs: Any)
that works with JIT, we would have to implement this manually on every class that needs it.You used the
@staticmethod
decorator, but takecls
as first input. Since you needcls
, we need to switch to@classmethod
to make it work. That should work in eager mode, but for JIT this now means that the whole class needs to be scriptable. For example, manually definingget_params
forRandomCrop
as explained in 1. and trying to script it, leads toIt seems it can't infer the type of
cls
and usestorch.Tensor
as fallback. Annotationcls: Type[RandomCrop]
yieldsI agree using
__init_subclass__
is unconventional, but it seems like the cleanest solution here. Since we actually alias the function, we avoid all of the JIT crazyness that we would have to deal with otherwise. If you can find a working solution, I'm happy to adopt it though.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the details. My last try would be to declare
get_params
as a@property
but... let me guess... JIT doesn't support it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You guessed right. But even if did, it would wouldn't work for us here.
@property
needs an instance.