-
Notifications
You must be signed in to change notification settings - Fork 31.9k
[Vision] .to function for ImageProcessors
#20536
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
Conversation
|
The documentation is not available anymore as the PR was closed or merged. |
|
Here is a quick v1, but I am afraid it's a bit too much in the sense that I am literally testing every possible combination |
|
You're looking at something too complicated: |
|
Yes I was thinking of something very complicated where someone could set EDIT: it seems that there is a workaround for that |
.to function for ImageProcessors.to function for ImageProcessors
src/transformers/utils/generic.py
Outdated
|
|
||
| if isinstance(x, str): | ||
| if hasattr(torch, x): | ||
| return True |
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.
I would be more careful -> i.e. to get that attribute, than test if it is indeed a torch.dtype
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 mean
if hasattr(torch, x):
x = getattr(torch, x)
else:
return False
?
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.
yeah, x = getattr(torch, x) and then test if it is a torch dtype, just as what you did a few line below.
Be careful, I always complicate things. You can hold on until sylvain's review.
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.
Adapted your suggestion in da35051 ;)
amyeroberts
left a comment
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 opening this PR! Looking good :)
Just a few small comments and +1 on @ydshieh's suggestions on _is_torch_dtype.
I'm still unsure about the behaviour with to when some of the inputs are ints, as it doesn't match PyTorch (I can cast ints to floats), however with logging it's probably OK. I wonder if logger.warning might be too aggressive a log level as it's not something the user can really change.
| class DeiTFeatureExtractionTest(FeatureExtractionSavingTestMixin, unittest.TestCase): | ||
|
|
||
| feature_extraction_class = DeiTFeatureExtractor if is_vision_available() else None | ||
| test_cast_dtype = True |
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.
Why is it needed here for DeiT and not other models?
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.
I just waited for everyone's approval on the concept and planned to add it on more models! Probably on the main models only as it may slow down the CI test suite
Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com>
|
Thanks everyone for the feedback! Let me know if you think it's relevant to add the |
sgugger
left a comment
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.
Good catch on the int tensors, I have comments on the actual implementation however.
| import torch # noqa | ||
|
|
||
| new_data = {} | ||
| device = self._parse_args_to_device(*args, **kwargs) |
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.
Still not fan of the name :-p
Also, until it's used in another place, I would avoid doing a separate method for this. Let's just put the code there!
sgugger
left a comment
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 bearing with me :-)
|
Ahaha no worries! thanks for all the iterations 💪 |
* add v1 with tests * add checker * simplified version * update docstring * better version * fix docstring + change order * make style * tests + change conditions * final tests * modify docstring * Update src/transformers/feature_extraction_utils.py Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com> * replace by `ValueError` * fix logic * apply suggestions * `dtype` is not needed * adapt suggestions * remove `_parse_args_to_device` Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com>
What does this PR do?
PoC for adding
.tosupport on ImageProcessorsrelated #20453