Skip to content

🚨🚨🚨 Uniformize kwargs for TrOCR Processor#34587

Merged
qubvel merged 6 commits into
huggingface:mainfrom
tibor-reiss:fix-31811-trocr
Nov 29, 2024
Merged

🚨🚨🚨 Uniformize kwargs for TrOCR Processor#34587
qubvel merged 6 commits into
huggingface:mainfrom
tibor-reiss:fix-31811-trocr

Conversation

@tibor-reiss

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

Copy link
Copy Markdown
Contributor

Adds uniformized processors for TrOCR following #31911

Added tests (which also pass in main branch).

@qubvel @molbap

@qubvel qubvel left a comment

Copy link
Copy Markdown
Contributor

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 🤗

Comment thread src/transformers/models/trocr/processing_trocr.py Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for adding tests ❤️

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Collaborator

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
Copy Markdown
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
Copy Markdown
Contributor

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
Copy Markdown
Contributor

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
Copy Markdown
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

@qubvel qubvel left a comment

Copy link
Copy Markdown
Contributor

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,
*,

@qubvel qubvel Nov 19, 2024

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Collaborator

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

@ArthurZucker ArthurZucker left a comment

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
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
Copy Markdown
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

qubvel commented Nov 29, 2024

Copy link
Copy Markdown
Contributor

Thanks for working on this @tibor-reiss!

@qubvel
qubvel merged commit 89d7bf5 into huggingface:main Nov 29, 2024
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
@farleyknight farleyknight mentioned this pull request Apr 19, 2025
40 tasks
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