Skip to content

Conversation

@ydshieh
Copy link
Collaborator

@ydshieh ydshieh commented Nov 1, 2024

What does this PR do?

And make it less flaky

  • Use smaller (short) inputs
  • Use larger epsilon in norm layers

@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.

@ydshieh ydshieh force-pushed the fix_more_matching branch 4 times, most recently from ad647f2 to 2afd90e Compare November 4, 2024 09:36
@ydshieh ydshieh changed the title run sdpa Make test_eager_matches_sdpa_inference less flaky Nov 4, 2024
@ydshieh ydshieh requested a review from gante November 4, 2024 10:23
@ydshieh ydshieh changed the title Make test_eager_matches_sdpa_inference less flaky Remove @slow for test_eager_matches_sdpa_inference less flaky Nov 4, 2024
@ydshieh ydshieh changed the title Remove @slow for test_eager_matches_sdpa_inference less flaky Remove @slow for test_eager_matches_sdpa_inference Nov 4, 2024
Comment on lines 188 to 191
for key in ["image_token_index", "image_token_id", "video_token_index", "video_token_id", "vision_start_token_id"]:
token_index = getattr(config, key, None)
if token_index is not None and token_index < config.get_text_config().vocab_size:
logits_processor_kwargs["bad_words_ids"].append([token_index])
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

make it more general.

vision_start_token_id is required for qwen2_vl

Copy link
Contributor

@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.

Yay fewer slow tests 🙌

Added a few questions/suggestions to see if we can remove a few more overwritten cases 😈

Comment on lines +292 to +296
@parameterized.expand([("float16",), ("bfloat16",), ("float32",)])
@require_torch_sdpa
@unittest.skip("Albert requires `head_mask` which is currently not done in this test.")
def test_eager_matches_sdpa_inference(self):
pass
Copy link
Contributor

Choose a reason for hiding this comment

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

On skips like this, on Albert and other models: the test pulls the main input and the attention mask to manipulate them, finally sending them to the model. We could pop these items from inputs_dict, and then pass **inputs_dict to the model (e.g. model_eager(**prepared_inputs, **inputs_dict)) -- I think then we wouldn't need to skip tests due to missing inputs 🤗

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe let's merge and do this in a follow-up PR. It's never worked before.


@parameterized.expand([("float16",), ("bfloat16",), ("float32",)])
@require_torch_sdpa
@slow
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't we just delete the test? (it has # Copied from tests.test_modeling_common.ModelTesterMixin.test_eager_matches_sdpa_inference and it inherits the mixin, so it should run the original test!)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

no, it fails. I don't dive into why it's failing (input issues) though.

Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting -- in that case, how does # Copied from work? 👀

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

# Copied from is only applied to files under src I believe :-) but people sometimes use it in the tests/ 😆

@gante gante requested a review from zucchini-nlp November 4, 2024 17:20
@gante
Copy link
Contributor

gante commented Nov 4, 2024

Tagging @zucchini-nlp to double-check VLM test changes :)

@ydshieh ydshieh requested a review from ArthurZucker November 4, 2024 19:46
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, LGTM! Left a few questions and things we can clean up more

return floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size])

@require_torch_sdpa
@slow
Copy link
Member

Choose a reason for hiding this comment

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

i think this test dont need skip anymore since we dont check if model has SDPA layers within this test anymore. But it can be skipped due to the same flakiness

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It still has input preparation issues, where I added below to another model test class

"Idefics requires both text and image inputs which is currently not done in this test."

As mentioned in a reply to Joao's comment, let's try to do it in a follow up PR

input_ids = ids_tensor([self.batch_size, self.seq_length], self.vocab_size)
attention_mask = torch.ones(input_ids.shape, dtype=torch.long, device=torch_device)

input_ids[:, -1] = self.pad_token_id
Copy link
Member

Choose a reason for hiding this comment

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

for my understanding, any reason why last token has to be a pad?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

to avoid index error

(modeling code)

vision_tokens = input_ids[vision_start_indices + 1]

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 🤗

@ydshieh ydshieh merged commit f2d5dfb into main Nov 5, 2024
@ydshieh ydshieh deleted the fix_more_matching branch November 5, 2024 15:10
BernardZach pushed a commit to BernardZach/transformers that referenced this pull request Dec 5, 2024
…4558)

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

* update

---------

Co-authored-by: ydshieh <[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.

5 participants