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 Layoutlm (2, 3, X) processors #32180

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

leloykun
Copy link
Contributor

@leloykun leloykun commented Jul 24, 2024

What does this PR do?

  • Uniformizes kwargs for LayoutLM (2, 3, X) processors as discussed in Uniform kwargs for processors #31911
  • Also fixes the bug in tests_exotic_models which totally prevents any test from being run

Fixes # (issue)

Who can review?

@zucchini-nlp @molbap @NielsRogge

Copy link
Member

@zucchini-nlp zucchini-nlp 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 working on this! I left a few comments, regarding the apply_ocr arg. I got you point, but we need to test it and make sure it's working for different cases.

So can you add the Mixin test to run general tests + write a special test for apply_ocr with different scenarios ?

src/transformers/processing_utils.py Outdated Show resolved Hide resolved
src/transformers/processing_utils.py Outdated Show resolved Hide resolved
src/transformers/processing_utils.py Outdated Show resolved Hide resolved
@zucchini-nlp zucchini-nlp mentioned this pull request Aug 7, 2024
40 tasks
@leloykun leloykun force-pushed the fc--uniform-kwargs-layoutlmv branch 2 times, most recently from 1fafbe9 to 85b4aec Compare August 15, 2024 15:04
output_kwargs = self._merge_kwargs(
LayoutLMv3ProcessorKwargs,
tokenizer_init_kwargs=self.tokenizer.init_kwargs,
image_processor_init_kwargs=self.image_processor.init_kwargs,
Copy link
Contributor Author

@leloykun leloykun Aug 15, 2024

Choose a reason for hiding this comment

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

@zucchini-nlp @NielsRogge

The test group tests_exotic_models may be broken. It's not running any tests at all. And the tests for the layoutlm models can only be ran on this test group (cuz they require pytesseract which is only installed in the docker container for this test).

I've already fixed the bug above but while it was there, it didn't cause any of the tests to fail.

@NielsRogge are the layoutlmv3 models deprecated?

@leloykun
Copy link
Contributor Author

Note for reviewer(s): the failing tests are caused by the Jamba model

Comment on lines 366 to 307
"tests/models/*layoutlmv*",
"tests/models/*nat",
"tests/models/deta",
"tests/models/udop",
"tests/models/nougat",
*glob.glob("tests/models/layoutlm*/*.py", recursive=True),
*glob.glob("tests/models/layoutxlm/*.py", recursive=True),
*glob.glob("tests/models/*nat/*.py", recursive=True),
*glob.glob("tests/models/deta/*.py", recursive=True),
*glob.glob("tests/models/udop/*.py", recursive=True),
*glob.glob("tests/models/nougat/*.py", recursive=True),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@zucchini-nlp @NielsRogge

Update: I've just fixed it!

This test may have been broken for months now (perhaps up to 22 months). I'm not sure why, but I think it has to do with CircleCI's filtering mechanism. Directly listing out the files to test fixed the issue.

Copy link
Member

Choose a reason for hiding this comment

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

cc @ydshieh for CI

Copy link
Member

@zucchini-nlp zucchini-nlp left a comment

Choose a reason for hiding this comment

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

Looks good to me overall! One thing left is to move all kwargs to ModalityKwargs and handle backwards compatibility for that

Comment on lines 1009 to 1049
if len(args):
warnings.warn(
"Passing positional arguments to the processor call is now deprecated and will be disallowed in future versions. "
"Please pass all arguments as keyword arguments."
)
if len(args) > len(self.optional_call_args):
raise ValueError(
f"Expected *at most* {len(self.optional_call_args)} optional positional arguments in processor call but received {len(args)}."
"Passing positional arguments to the processor call is not recommended"
)
return {arg_name: arg_value for arg_value, arg_name in zip(args, self.optional_call_args)}
Copy link
Member

Choose a reason for hiding this comment

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

Cool! We can modify this later after everyone agrees on this workaround. Overall looks good to me, except for some nits I left in another PR.

IMO we can get a core maintainer review on this one which is easier to iterate and then use the agreed deprecation format in PR "all processors with extra args"

And ofc we'll need a test here 😄

@leloykun
Copy link
Contributor Author

@zucchini-nlp @yonigozlan I've just rebased this to main

the failing tests are due to Llava-Next:
image

but yah, this PR should now be ready for review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants