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

VLMs: enable generation tests #33533

Merged
merged 14 commits into from
Sep 19, 2024
Merged

Conversation

zucchini-nlp
Copy link
Member

@zucchini-nlp zucchini-nlp commented Sep 17, 2024

What does this PR do?

Part of #33374. This PR adds GenerationTesterMixin in all VLMs (except BLIP) and modifies tests to accept all input kwargs, not only input_ids. That way we can test the whole logic, including merging image and text embeddings.

I also ran a few tests for other models, and locally nothing seemed broken

cc @amyeroberts if you want to take a look :)

@@ -98,9 +98,16 @@ class GenerationTesterMixin:

def _get_input_ids_and_config(self, batch_size=2):
config, inputs_dict = self.model_tester.prepare_config_and_inputs_for_common()
input_ids = inputs_dict[self.input_name]
input_ids = inputs_dict.pop(self.input_name)[:batch_size, :]
Copy link
Member Author

Choose a reason for hiding this comment

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

I'd day we use model.main_input_name here but let's leave it for the next PR. Seems it will cause many tests to fail 😓

Copy link
Member

Choose a reason for hiding this comment

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

let's add a todo then! :)

@@ -80,7 +81,7 @@ def __init__(
"initializer_range": 0.02,
"num_labels": 3,
"num_choices": 4,
"pad_token_id": 0,
"pad_token_id": 1,
Copy link
Member Author

Choose a reason for hiding this comment

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

I chaneg this so that it doesn't clash with special image token, so when we artificially pad input sequence it won't get extra image placeholders than needed

Comment on lines 105 to 110
# we don't want encoder-decoder models to start from filled decoder ids
_ = inputs_dict.pop("decoder_input_ids", None)
_ = inputs_dict.pop("decoder_attention_mask", None)

# we'll set cache use in each test differently
_ = inputs_dict.pop("use_cache", None)
Copy link
Member Author

Choose a reason for hiding this comment

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

Hope it's okay this way, otherwise we can override this in each model which returns decoder inputs. I don't think we need a new helper like get_input_for_generation as the current one works good already

@HuggingFaceDocBuilderDev

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.

@zucchini-nlp zucchini-nlp mentioned this pull request Sep 18, 2024
5 tasks
Copy link
Member

@gante gante left a comment

Choose a reason for hiding this comment

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

🔥🔥

(having tests makes me happy!)

@@ -98,9 +98,16 @@ class GenerationTesterMixin:

def _get_input_ids_and_config(self, batch_size=2):
config, inputs_dict = self.model_tester.prepare_config_and_inputs_for_common()
input_ids = inputs_dict[self.input_name]
input_ids = inputs_dict.pop(self.input_name)[:batch_size, :]
Copy link
Member

Choose a reason for hiding this comment

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

let's add a todo then! :)

tests/generation/test_utils.py Outdated Show resolved Hide resolved
Comment on lines 719 to 723
if any(name in model.__class__.__name__.lower() for name in ("blip", "llava", "paligemma")):
self.skipTest(
"For VLMs inputs embeds won't match input ids unless images are encoded and merged with ids properly"
)

Copy link
Member

Choose a reason for hiding this comment

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

This tags the whole test as skipped, which doesn't seem to be the goal (if the skip is reached, then the test above passes).

Let's simply run the rest of the test if a if condition is satisfied, and leave a TODO to work on these models

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, btw, just so you know, the below part is not running right now because it should be cache_position in singular. I didn't fix it here because fixing -> many hidden failures. I can work on it as separate PR or feel free to fix it if you have bandwidth 😄

Copy link
Member

Choose a reason for hiding this comment

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

oh no -- let's work it on a separate PR

outputs_from_ids = model.generate(input_ids)
self.assertEqual(outputs_from_ids.shape, (2, 20))
outputs_from_ids = model.generate(input_ids, max_new_tokens=5)
self.assertEqual(outputs_from_ids.shape, (input_ids.shape[0], input_ids.shape[1] + 5))
Copy link
Member

Choose a reason for hiding this comment

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

yes, let's not rely on defaults 👍

@zucchini-nlp
Copy link
Member Author

Will try to find the root reason for flaky tests, otherwise we'll need to override and add is_flaky for VLMs. Maybe related to VLMs generating special image tokens because weights are not trained and technically anything can be generated

@zucchini-nlp zucchini-nlp merged commit d7975a5 into huggingface:main Sep 19, 2024
23 checks passed
@gante
Copy link
Member

gante commented Sep 19, 2024

@zucchini-nlp the PR still missed a review from a core maintainer :P

(cc @LysandreJik for a quick look at the PR)

@zucchini-nlp
Copy link
Member Author

Omg! O_o you're right, sorry, completely missed that

itazap pushed a commit to NielsRogge/transformers that referenced this pull request Sep 20, 2024
* add tests

* fix whisper

* update

* nit

* add qwen2-vl

* more updates!

* better this way

* fix this one

* fix more tests

* fix final tests, hope so

* fix led

* Update tests/generation/test_utils.py

Co-authored-by: Joao Gante <[email protected]>

* pr comments

* not pass pixels and extra for low-mem tests, very flaky because of visio tower

---------

Co-authored-by: Joao Gante <[email protected]>
amyeroberts pushed a commit to amyeroberts/transformers that referenced this pull request Oct 2, 2024
* add tests

* fix whisper

* update

* nit

* add qwen2-vl

* more updates!

* better this way

* fix this one

* fix more tests

* fix final tests, hope so

* fix led

* Update tests/generation/test_utils.py

Co-authored-by: Joao Gante <[email protected]>

* pr comments

* not pass pixels and extra for low-mem tests, very flaky because of visio tower

---------

Co-authored-by: Joao Gante <[email protected]>
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.

3 participants