-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Update kwargs validation for preprocess
with decorator
#32024
Conversation
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
# validation done by @filter_out_non_signature_kwargs decorator | ||
if hasattr(image_processor.preprocess, "_filter_out_non_signature_kwargs"): | ||
if hasattr(self.image_processor_tester, "prepare_image_inputs"): | ||
inputs = self.image_processor_tester.prepare_image_inputs() | ||
elif hasattr(self.image_processor_tester, "prepare_video_inputs"): | ||
inputs = self.image_processor_tester.prepare_video_inputs() | ||
else: | ||
self.skipTest(reason="No valid input preparation method found") | ||
|
||
with warnings.catch_warnings(record=True) as raised_warnings: | ||
warnings.simplefilter("always") | ||
image_processor(inputs, extra_argument=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.
The decorated method will have _filter_out_non_signature_kwargs
argument, here we test that the warning is raised if an unknown argument is passed to the method.
CLIP/Git image processors require updating their processors first, DETR* image processors require adding deprecation. In this PR only simple cases are handled, where we need to replace |
@molbap whenever you have time, please have a look |
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.
LGTM! Much tidier. One comment is since now inspect.signature
is used everywhere, is there any impact on tests speed?
@molbap |
Yes you're right, it's only at import time. I was just curious since inspect-related calls have ended up costing me some precious ms before, so I steer away from it |
@amyeroberts please review whenever you have time |
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.
Beautiful ❤️
self.assertIn("extra_argument", messages) | ||
is_tested = True | ||
|
||
if not is_tested: |
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.
Nice :)
f995fdb
to
ee91581
Compare
* BLIP preprocess * BIT preprocess * BRIDGETOWER preprocess * CHAMELEON preprocess * CHINESE_CLIP preprocess * CONVNEXT preprocess * DEIT preprocess * DONUT preprocess * DPT preprocess * FLAVA preprocess * EFFICIENTNET preprocess * FUYU preprocess * GLPN preprocess * IMAGEGPT preprocess * INTRUCTBLIPVIDEO preprocess * VIVIT preprocess * ZOEDEPTH preprocess * VITMATTE preprocess * VIT preprocess * VILT preprocess * VIDEOMAE preprocess * VIDEOLLAVA * TVP processing * TVP fixup * SWIN2SR preprocess * SIGLIP preprocess * SAM preprocess * RT-DETR preprocess * PVT preprocess * POOLFORMER preprocess * PERCEIVER preprocess * OWLVIT preprocess * OWLV2 preprocess * NOUGAT preprocess * MOBILEVIT preprocess * MOBILENETV2 preprocess * MOBILENETV1 preprocess * LEVIT preprocess * LAYOUTLMV2 preprocess * LAYOUTLMV3 preprocess * Add test * Update tests
What does this PR do?
Update most of the image processors with
filter_out_non_signature_kwargs
decorator for kwargs validation instead of_valid_processor_keys
(continue of work started in #30799)Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.