Repository navigation
[FA] Fix FA tests for unique models
#50632
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -288,6 +288,9 @@ def test_initialization(self): | |
| @is_flaky() | ||
| def test_flash_attn_2_inference_equivalence(self): | ||
| for model_class in self.all_model_classes: | ||
| if not model_class._supports_flash_attn: | ||
| self.skipTest(f"{model_class.__name__} does not support Flash Attention 2") | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you are looping |
||
|
|
||
| config, inputs_dict = self.model_tester.prepare_config_and_inputs_for_common() | ||
| model = model_class(config) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ | |
| import tempfile | ||
| import unittest | ||
| from pathlib import Path | ||
| from unittest.mock import patch | ||
|
|
||
| from transformers import ( | ||
| AutoModelForMultimodalLM, | ||
|
|
@@ -66,8 +67,8 @@ def __init__(self, parent, **kwargs): | |
| kwargs.setdefault("head_dim", 16) | ||
| kwargs.setdefault("moe_intermediate_size", 16) | ||
| kwargs.setdefault("moe_shared_expert_intermediate_size", 16) | ||
| kwargs.setdefault("mamba_num_heads", 4) | ||
| kwargs.setdefault("mamba_n_groups", 1) | ||
| kwargs.setdefault("mamba_num_heads", 8) | ||
| kwargs.setdefault("mamba_n_groups", 8) | ||
| kwargs.setdefault("mamba_head_dim", 16) | ||
| kwargs.setdefault("ssm_state_size", 8) | ||
| kwargs.setdefault("mamba_chunk_size", 16) | ||
|
|
@@ -81,13 +82,13 @@ def __init__(self, parent, **kwargs): | |
| kwargs.setdefault("audio_asr_num_hidden_layers", 2) | ||
| kwargs.setdefault("audio_asr_num_attention_heads", 2) | ||
|
|
||
| kwargs.setdefault("audio_diarization_audio_hidden_size", 16) | ||
| kwargs.setdefault("audio_diarization_audio_hidden_size", 32) | ||
| kwargs.setdefault("audio_diarization_audio_intermediate_size", 32) | ||
| kwargs.setdefault("audio_diarization_audio_num_hidden_layers", 1) | ||
| kwargs.setdefault("audio_diarization_audio_num_attention_heads", 2) | ||
|
|
||
| kwargs.setdefault("audio_diarization_head_hidden_size", 8) | ||
| kwargs.setdefault("audio_hidden_size", 16) | ||
| kwargs.setdefault("audio_diarization_head_hidden_size", 16) | ||
| kwargs.setdefault("audio_hidden_size", 32) | ||
|
|
||
| kwargs.setdefault("chunk_size", 16) | ||
| kwargs.setdefault("chunk_length", 500) | ||
|
|
@@ -297,6 +298,26 @@ def test_audio_token_past_the_vocabulary(self): | |
| prompt_length = input_ids.shape[1] | ||
| torch.testing.assert_close(sequences[:, prompt_length:], expected_sequences[:, prompt_length:], rtol=0, atol=0) | ||
|
|
||
| def test_sdpa_can_dispatch_on_flash(self): | ||
| """Audio encoder can produce fp32 (attention) outputs => avoid by autocasting + a mask is required so dummy replace it""" | ||
|
|
||
| def full_ones_mask(batch_size: int | None = None): | ||
| batch_size = batch_size if batch_size is not None else self.model_tester.batch_size | ||
| return torch.ones( | ||
| [batch_size, self.model_tester.feat_seq_length], | ||
| dtype=torch.bool, | ||
| device=torch_device, | ||
| ) | ||
|
|
||
| with patch.object(self.model_tester, "create_audio_mask", new=full_ones_mask): | ||
| with torch.autocast(device_type=torch_device, dtype=torch.float16): | ||
| super().test_sdpa_can_dispatch_on_flash() | ||
|
|
||
| def _test_attention_implementation(self, attn_implementation): | ||
| """Audio encoder can produce fp32 (attention) outputs => avoid by autocasting""" | ||
| with torch.autocast(device_type=torch_device, dtype=torch.float16): | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I opted for autocast for now but maybe in the end it would be best to fix it in modeling directly cc @eustlb |
||
| super()._test_attention_implementation(attn_implementation) | ||
|
|
||
|
|
||
| @require_torch | ||
| @require_torch_accelerator_memory(memory=70) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was an actual error and the shape was destroying cache updates