-
Notifications
You must be signed in to change notification settings - Fork 27.8k
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
Fix max size deprecated warning #34998
base: main
Are you sure you want to change the base?
Fix max size deprecated warning #34998
Conversation
…` and triggered unnecessary deprecated warning
…` and triggered unnecessary deprecated warning
While working in this PR I've notices some other possible improvement, to advance with the expected depreciation of the Here I'm not sure what type transformers/src/transformers/models/detr/image_processing_detr.py Lines 992 to 1000 in 5e8c1d7
If it is a only size = size if size is not None else {"shortest_edge": 800, "longest_edge": 1333}
if "max_size" in kwargs:
logger.warning_once(
"The `max_size` parameter is deprecated and will be removed in v4.26. "
"Please specify in `size['longest_edge'] instead`.",
)
size['longest_edge'] = kwargs.pop("max_size")
size = get_size_dict(size, default_to_square=False) I've also noticed weird use of size in transformers/src/transformers/models/sam/image_processing_sam.py Lines 136 to 137 in 5e8c1d7
I think we should normalized to use of And here also the typing of the function specify the If I get more precision, I'd be happy to contribute and may be work on the suppression of the |
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.
@HichTala Thanks for cleaning this up!
No worries, if you'd like me to clean up a bit more as I explained in my previous comment, don't hesitate to let me know! |
I suppose max_size can be entirely removed here, because we are at version 4.47 right now
|
There might be configs on the Hub that still have an integer as a size parameter. Thats why here we make it for backward compatability |
Ok then, I'll try to clean up the detr variants a bit more and try not to break everything. 🫡 |
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. |
Add a test to ensure test can pass successfully and backward compatibility
The tests pipelines still use transformers/tests/models/detr/test_image_processing_detr.py Lines 167 to 169 in 0b5b5e6
I don't know if I'm allowed to modify those ? |
Remove `max_size` from test pipelines and replace by `size` by a `Dict` with `'shortest_edge'` `'longest_edge'` as keys
Thanks for iterating! it seems its a breaking change, you can check with https://huggingface.co/microsoft/table-transformer-detection/ model on your branch and main: from transformers import AutoProcessor
image_processor = AutoProcessor.from_pretrained(model.id)
print(image_processor.size) |
size = ( | ||
{"shortest_edge": size, "longest_edge": 1333} if isinstance(size, int) else size | ||
) # Backwards compatibility | ||
size = get_size_dict(size, default_to_square=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.
comment should be above to avoid this line break
The model you sent use Do we raise an error saying it's deprecated, or do we put back the deprecation warnings? |
Ideally, it would be great to make PRs with updated I'm happy with whichever decision you make! |
I'm ok to work on this. I think I'll rollback this PR to point where backward compatibility is ensured with warning, I'll update the "version 4.26" to "future version" it's may be more meaning full. That way, it can be merged and my code will finally be able to launch without those flooding warning messages. I'll then open some new PRs to start eliminating the max size. It would be great if you can share the draft script with me. |
Here is a draft I used to fetch object detection models image processor's configs: from transformers import AutoProcessor
from huggingface_hub import list_models, hf_hub_download
import json
import os
# Filter models with the tag 'pipeline_tag=object-detection'
models = list_models(tags="object-detection", gated=False, sort="downloads", limit=1000)
count = 0
for model in models:
try:
# Download preprocessing_config.json
config_path = hf_hub_download(repo_id=model.id, filename="preprocessor_config.json")
with open(config_path, "r") as file:
config = json.load(file)
# Check if 'size' is a dict
if not isinstance(config.get("size"), dict):
print(f"#{count} Model: {model.id}")
print(f"Created: {model.created_at}")
print(f"Downloads: {model.downloads}\n")
print()
count += 1
# resotor processor
image_processor = AutoProcessor.from_pretrained(model.id)
print(image_processor.size)
except Exception as e:
print(f"Error processing model {model.id}: {e}") The idea is to run this on main to load configs and then push them You first load it image_processor = AutoProcessor.from_pretrained(model.id) And then push back + open a PR image_processor.save_preatrained(model.id, create_pr=True) # or smth similar I will also need links to all the PRs, to share them with someone who can merge them. Please be careful in order not to spam all models, lets do it batch-wise, for the first iteration we can do it for the first five models. |
Thanks for sharing! I’ll probably work on this at the start of next week. Could you let me know how can I provide links to the PRs once they’re created? |
Probably, save_pretrained returns something, but I'm not sure! It's something that has to be explored. Alternatively, you can use the |
No worries at all! Manage your time according to your preferences, and we will always be happy with your contributions. 🤗 |
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! We can merge it in this state and continue in a follow-up PR.
@ArthurZucker, a minor cleanup for |
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.
Hey! Scanned a bit, I am guessing this was breaking for a few models so we are not removing support?
IMO we should still break as we had a deprecation cycle but try to help the models on the hub, unless our deprecation cycle did not cover a certain case -> we do another deprecation cycle for the missing cases!
@ArthurZucker this one should not break anything, just a minor clean-up. The second one (linked) is breaking, we are working to update hub config first |
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.
Sure! Let's juste remove the futur version, it's vague and unhelpful. We can leave it as is people know it's already deprecated!
"The `max_size` parameter is deprecated and will be removed in v4.26. " | ||
"The `max_size` parameter is deprecated and will be removed in a future version. " |
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.
to revert!
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.
Done 👍
@@ -1347,7 +1346,7 @@ def preprocess( | |||
|
|||
do_resize = self.do_resize if do_resize is None else do_resize | |||
size = self.size if size is None else size | |||
size = get_size_dict(size=size, max_size=max_size, default_to_square=False) | |||
size = get_size_dict(size=size, default_to_square=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.
cool! thanks
This reverts commit 2b53f9e
This pull request focuses on removing the deprecated
max_size
argument from thepreprocess
method across multiple image processing modules in thetransformers
library. This change simplifies the code and aligns with the planned deprecation of themax_size
argument.Key changes include:
Removal of
max_size
argument:src/transformers/models/conditional_detr/image_processing_conditional_detr.py
: Removedmax_size
argument from thepreprocess
method and its usage in theget_size_dict
andresize
calls. [1] [2] [3]src/transformers/models/deformable_detr/image_processing_deformable_detr.py
: Removedmax_size
argument from thepreprocess
method and its usage in theget_size_dict
andresize
calls. [1] [2] [3]src/transformers/models/detr/image_processing_detr.py
: Removedmax_size
argument from thepreprocess
method and its usage in theget_size_dict
andresize
calls. [1] [2] [3]src/transformers/models/grounding_dino/image_processing_grounding_dino.py
: Removedmax_size
argument from thepreprocess
method and its usage in theget_size_dict
andresize
calls. [1] [2] [3]src/transformers/models/yolos/image_processing_yolos.py
: Removedmax_size
argument from thepreprocess
method and its usage in theget_size_dict
andresize
calls. [1] [2] [3]# What does this PR do?Fixes #34977
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.
@qubvel here is my pull request.