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

🚨🚨🚨 Uniformize kwargs for TrOCR Processor #34587

Merged
merged 6 commits into from
Nov 29, 2024

Conversation

tibor-reiss
Copy link
Contributor

@tibor-reiss tibor-reiss commented Nov 3, 2024

Adds uniformized processors for TrOCR following #31911

Added tests (which also pass in main branch).

@qubvel @molbap

Copy link
Member

@qubvel qubvel left a comment

Choose a reason for hiding this comment

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

Hi @tibor-reiss, thanks for working on this! And sorry for the delay, the team was on the offsite. Don't hesitate to ping for review a few times 🤗

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for adding tests ❤️

def __call__(
self,
images: ImageInput = None,
*args,
Copy link
Member

Choose a reason for hiding this comment

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

Not sure we need this *args, may lead to silent missing of text if it passed not as a keyword argument

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll add, it's acceptable to use this pattern to capture arguments that are absolutely necessary and are not capturable by any other means, and indeed it should typically be after at least images and text - are you trying to capture a specific arg?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the discussion. I don't have any specific arg in mind, it's purely for backwards compatibility. I agree though that best would be to remove *args completely, but that would break BC, because it is used both when calling tokenizer and image_processor. If this is not a concern here, I am happy to remove it :)

Regarding text: from the old code: text = kwargs.pop("text", None). If I am not mistaken, this is the only way to set text inside __call__. The proposed solution keeps this convention, i.e. if someone specifies text as positional, it will still not work. Unfortunately, it's not possible yet to combine variadic number of positional arguments with the keyword-only delimiter, so this is the best I was able to come up with.

Copy link
Member

Choose a reason for hiding this comment

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

I see, maybe a better tradeoff would be to remove it or to force users to use keyword arguments for everything other than images, I mean use pure * in the signature instead of *args.

Copy link
Member

Choose a reason for hiding this comment

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

We can also add 🚨 for current PR to indicate it is not fully BC

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have removed args.

@qubvel qubvel changed the title uniformize kwargs for TrOCR 🚨🚨🚨 Uniformize kwargs for TrOCR Processor Nov 19, 2024
Copy link
Member

@qubvel qubvel left a comment

Choose a reason for hiding this comment

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

@tibor-reiss thanks for working on this and adding tests 🤗

@ArthurZucker please review whenever you have bandwidth, see also a comment below.

def __call__(
self,
images: ImageInput = None,
*,
Copy link
Member

@qubvel qubvel Nov 19, 2024

Choose a reason for hiding this comment

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

Comment for @ArthurZucker:
Slight breaking change (*) to force users to use keyword arguments in case previously positional args were used. Otherwise, we might either miss some args or get it assigned to the wrong keyword parameters and getting not a clear error message.

Copy link
Contributor

Choose a reason for hiding this comment

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

tiny comment: let's add maybe a #TODO here to keep in mind to deprecate this pattern in this future 🙏

@qubvel qubvel requested a review from ArthurZucker November 25, 2024 14:39
Copy link
Collaborator

@ArthurZucker ArthurZucker left a comment

Choose a reason for hiding this comment

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

thanks for the description! Regarding the breaking change, let's either properly break or deprecate!

def __call__(
self,
images: ImageInput = None,
*, # TODO deprecate/remove this
Copy link
Collaborator

Choose a reason for hiding this comment

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

Up to you, there is no deprecation cycle so this is not very actionnable, neither for us nor for the user!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the *.
cc @molbap @qubvel

@qubvel
Copy link
Member

qubvel commented Nov 29, 2024

Thanks for working on this @tibor-reiss!

@qubvel qubvel merged commit 89d7bf5 into huggingface:main Nov 29, 2024
14 checks passed
BernardZach pushed a commit to BernardZach/transformers that referenced this pull request Dec 5, 2024
* Make kwargs uniform for TrOCR

* Add tests

* Put back current_processor

* Remove args

* Add todo comment

* Code review - breaking change
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.

4 participants