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

Do not remove half seq length in generation tests #30016

Merged
merged 7 commits into from
Apr 19, 2024

Conversation

zucchini-nlp
Copy link
Member

What does this PR do?

Generation tests divided input ids into half, feeding only half-seq-length for generation. But this strategy may cause difficulties for multimodal models, which have dependency between images count and input ids. For ex, Llava models include special image tokens in input ids, and removing half-seq-length might result in failing test.

This is part of a work to add GenerationTesterMixin in multimodal models, which are not covered with tests now.

This PR:

  • removes dividing seq length into half
  • replaces "max length" with "max new tokens" for ease
  • gets rid of "min length" as we already have "config.eos_token=None" everywhere ensuring that exactly "max length" will be generated

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.

@gante

@zucchini-nlp zucchini-nlp requested a review from gante April 3, 2024 10:42
@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.

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.

LGTM, thank you for working on this 🙏

@@ -752,7 +752,7 @@ def test_attention_outputs(self):

def _check_encoder_attention_for_generate(self, attentions, batch_size, config, seq_length):
block_len = getattr(self.model_tester, "block_len", None)
encoder_expected_shape = (batch_size, 1, config.num_attention_heads, block_len, 3 * block_len)
encoder_expected_shape = (batch_size, 2, config.num_attention_heads, block_len, 3 * block_len)
Copy link
Member

Choose a reason for hiding this comment

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

is this because of the input_ids shape change?

Copy link
Member Author

@zucchini-nlp zucchini-nlp Apr 3, 2024

Choose a reason for hiding this comment

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

yes, I guess we can hardcode it this way since previously "1" was also hardcoded

Copy link
Member

Choose a reason for hiding this comment

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

no need to add imo

Copy link
Member Author

Choose a reason for hiding this comment

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

You mean bringing back "1"? That causes test failures...

@gante gante requested a review from ArthurZucker April 3, 2024 15:01
@gante
Copy link
Member

gante commented Apr 3, 2024

@zucchini-nlp Can you trigger all tests, to double-check? (i.e. commit message = "[test_all] ...")

Co-authored-by: Joao Gante <joaofranciscocardosogante@gmail.com>
@zucchini-nlp
Copy link
Member Author

All tests are passing, except for the attached PR and another which seemingly failed to download files.

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 cleanup overall 😄

@@ -691,40 +667,39 @@ def test_model_parallel_beam_search(self):
new_model.generate(
input_ids,
attention_mask=attention_mask,
max_length=max_length,
max_new_tokens=self.max_new_tokens,
Copy link
Collaborator

Choose a reason for hiding this comment

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

everywhere we call model.generate, if we pas this max_new_token, why not in the setup update the model.generation_config.max_new_tokens?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, you mean the "setup" in each model's test file, so that we already have the "max_new_tokens" linked to model? That means we need to initialize model from config when calling _get_input_ids_and_config and then set model.generation_config.max_new_tokens.

I can do it, seems like it will not cause any errors. But I am not sure if that's what you mean

zucchini-nlp and others added 3 commits April 8, 2024 12:26
Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com>
@gante gante merged commit b1cd487 into huggingface:main Apr 19, 2024
18 checks passed
ydshieh pushed a commit that referenced this pull request Apr 23, 2024
* remove seq length from generation tests

* style and quality

* [test_all] & PR suggestion

Co-authored-by: Joao Gante <joaofranciscocardosogante@gmail.com>

* Update tests/generation/test_utils.py

Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com>

* [test all] remove unused variables

---------

Co-authored-by: Joao Gante <joaofranciscocardosogante@gmail.com>
Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com>
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.

None yet

4 participants