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

Quickfix generate tests #32546

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tests/models/electra/test_modeling_flax_electra.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,7 @@ def test_model_from_pretrained(self):
model = model_class_name.from_pretrained("google/electra-small-discriminator")
outputs = model(np.ones((1, 1)))
self.assertIsNotNone(outputs)

@unittest.skip(reason="Flax electra fails this test")
def test_inputs_embeds_matches_input_ids_with_generate(self):
pass
4 changes: 4 additions & 0 deletions tests/models/mamba2/test_modeling_mamba2.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ def test_initialization(self):
# check if it's a ones like
self.assertTrue(torch.allclose(param.data, torch.ones_like(param.data), atol=1e-5, rtol=1e-5))

@unittest.skip(reason="Mamba-2 fails this test, to fix")
def test_inputs_embeds_matches_input_ids_with_generate(self):
pass
Comment on lines +198 to +200
Copy link
Collaborator

Choose a reason for hiding this comment

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

bit unexpected for this one!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, opened #32555 for this and will look into it later


@unittest.skip(reason="Mamba 2 weights are not tied")
def test_tied_weights_keys(self):
pass
Expand Down
4 changes: 4 additions & 0 deletions tests/models/mbart/test_modeling_flax_mbart.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,10 @@ def decode_jitted(decoder_input_ids, decoder_attention_mask, encoder_outputs):
for jitted_output, output in zip(jitted_outputs, outputs):
self.assertEqual(jitted_output.shape, output.shape)

@unittest.skip(reason="Flax mbart fails this test")
def test_inputs_embeds_matches_input_ids_with_generate(self):
pass

@slow
def test_model_from_pretrained(self):
for model_class_name in self.all_model_classes:
Expand Down
4 changes: 4 additions & 0 deletions tests/models/reformer/test_modeling_reformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,10 @@ def _check_attentions_for_generate(
[layer_attention.shape for layer_attention in iter_attentions], [expected_shape] * len(iter_attentions)
)

@unittest.skip(reason="Reformer fails this test always")
def test_inputs_embeds_matches_input_ids_with_generate(self):
pass

def _check_hidden_states_for_generate(
self, batch_size, hidden_states, min_length, max_length, config, use_cache=False, num_beam_groups=1
):
Expand Down
4 changes: 4 additions & 0 deletions tests/models/roberta/test_modeling_flax_roberta.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,7 @@ def test_model_from_pretrained(self):
model = model_class_name.from_pretrained("FacebookAI/roberta-base", from_pt=True)
outputs = model(np.ones((1, 1)))
self.assertIsNotNone(outputs)

@unittest.skip(reason="Flax roberta fails this test")
def test_inputs_embeds_matches_input_ids_with_generate(self):
pass
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ def test_model_from_pretrained(self):
outputs = model(np.ones((1, 1)))
self.assertIsNotNone(outputs)

@unittest.skip(reason="Flax roberta fails this test")
def test_inputs_embeds_matches_input_ids_with_generate(self):
pass


@require_flax
class TFRobertaPreLayerNormModelIntegrationTest(unittest.TestCase):
Expand Down
20 changes: 17 additions & 3 deletions tests/test_modeling_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2776,7 +2776,6 @@ def test_inputs_embeds(self):

def test_inputs_embeds_matches_input_ids(self):
config, inputs_dict = self.model_tester.prepare_config_and_inputs_for_common()

for model_class in self.all_model_classes:
if model_class.__name__ not in get_values(MODEL_MAPPING_NAMES):
continue
Expand Down Expand Up @@ -2821,16 +2820,29 @@ def test_inputs_embeds_matches_input_ids(self):

def test_inputs_embeds_matches_input_ids_with_generate(self):
config, inputs_dict = self.model_tester.prepare_config_and_inputs_for_common()
model_found = False # flag to see if we found at least one model
for model_class in self.all_model_classes:
if model_class.__name__ not in get_values(MODEL_FOR_CAUSAL_LM_MAPPING_NAMES):
continue
model_found = True
model = model_class(config)
model.to(torch_device)
model.eval()

model_forward_args = inspect.signature(model.forward).parameters
if "inputs_embeds" not in model_forward_args:
self.skipTest(reason="This model doesn't use `inputs_embeds`")

required_args = ["inputs_embeds", "input_ids", "attention_mask", "position_ids"]
missing_args = [arg for arg in required_args if arg not in model_forward_args]

if missing_args:
self.skipTest(reason=f"This model is missing required arguments: {', '.join(missing_args)}")

has_inputs_embeds_forwarding = "inputs_embeds" in set(
inspect.signature(model.prepare_inputs_for_generation).parameters.keys()
)

if not has_inputs_embeds_forwarding:
self.skipTest(reason="This model doesn't have forwarding of `inputs_embeds` in its `generate()`.")

inputs = copy.deepcopy(self._prepare_for_class(inputs_dict, model_class))
pad_token_id = config.pad_token_id if config.pad_token_id is not None else 1
Expand Down Expand Up @@ -2865,6 +2877,8 @@ def test_inputs_embeds_matches_input_ids_with_generate(self):
max_new_tokens=2,
)
self.assertTrue(torch.allclose(out_embeds, out_ids))
if not model_found:
self.skipTest(reason="This model doesn't have a model class to test generate() on.")

@require_torch_multi_gpu
def test_multi_gpu_data_parallel_forward(self):
Expand Down
Loading