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

Remove repeated test_model_from_pretrained, test_model, test_config #33576

Open
wants to merge 8 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
14 changes: 1 addition & 13 deletions tests/models/albert/test_modeling_albert.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ class AlbertModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase):
else {}
)
fx_compatible = True
pretrained_checkpoint = "albert/albert-base-v1"

# special case for ForPreTraining model
def _prepare_for_class(self, inputs_dict, model_class, return_labels=False):
Expand All @@ -286,13 +287,6 @@ def setUp(self):
self.model_tester = AlbertModelTester(self)
self.config_tester = ConfigTester(self, config_class=AlbertConfig, hidden_size=37)

def test_config(self):
self.config_tester.run_common_tests()

def test_model(self):
config_and_inputs = self.model_tester.prepare_config_and_inputs()
self.model_tester.create_and_check_model(*config_and_inputs)

def test_for_pretraining(self):
config_and_inputs = self.model_tester.prepare_config_and_inputs()
self.model_tester.create_and_check_for_pretraining(*config_and_inputs)
Expand All @@ -319,12 +313,6 @@ def test_model_various_embeddings(self):
config_and_inputs[0].position_embedding_type = type
self.model_tester.create_and_check_model(*config_and_inputs)

@slow
def test_model_from_pretrained(self):
model_name = "albert/albert-base-v1"
model = AlbertModel.from_pretrained(model_name)
self.assertIsNotNone(model)


@require_torch
class AlbertModelIntegrationTest(unittest.TestCase):
Expand Down
8 changes: 1 addition & 7 deletions tests/models/albert/test_modeling_flax_albert.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,11 @@ class FlaxAlbertModelTest(FlaxModelTesterMixin, unittest.TestCase):
if is_flax_available()
else ()
)
pretrained_checkpoint = "albert/albert-base-v2"

def setUp(self):
self.model_tester = FlaxAlbertModelTester(self)

@slow
def test_model_from_pretrained(self):
for model_class_name in self.all_model_classes:
model = model_class_name.from_pretrained("albert/albert-base-v2")
outputs = model(np.ones((1, 1)))
self.assertIsNotNone(outputs)


@require_flax
class FlaxAlbertModelIntegrationTest(unittest.TestCase):
Expand Down
39 changes: 3 additions & 36 deletions tests/models/align/test_modeling_align.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ class AlignVisionModelTest(ModelTesterMixin, unittest.TestCase):
test_resize_embeddings = False
test_head_masking = False
has_attentions = False
pretrained_checkpoint = "kakaobrain/align-base"

def setUp(self):
self.model_tester = AlignVisionModelTester(self)
Expand All @@ -149,9 +150,6 @@ def setUp(self):
common_properties=["num_channels", "image_size"],
)

def test_config(self):
self.config_tester.run_common_tests()

@unittest.skip(reason="AlignVisionModel does not use inputs_embeds")
def test_inputs_embeds(self):
pass
Expand All @@ -176,10 +174,6 @@ def test_forward_signature(self):
expected_arg_names = ["pixel_values"]
self.assertListEqual(arg_names[:1], expected_arg_names)

def test_model(self):
config_and_inputs = self.model_tester.prepare_config_and_inputs()
self.model_tester.create_and_check_model(*config_and_inputs)

def test_hidden_states_output(self):
def check_hidden_states_output(inputs_dict, config, model_class):
model = model_class(config)
Expand Down Expand Up @@ -230,12 +224,6 @@ def test_training_gradient_checkpointing_use_reentrant(self):
def test_training_gradient_checkpointing_use_reentrant_false(self):
pass

@slow
def test_model_from_pretrained(self):
model_name = "kakaobrain/align-base"
model = AlignVisionModel.from_pretrained(model_name)
self.assertIsNotNone(model)


class AlignTextModelTester:
def __init__(
Expand Down Expand Up @@ -340,18 +328,12 @@ class AlignTextModelTest(ModelTesterMixin, unittest.TestCase):
fx_compatible = False
test_pruning = False
test_head_masking = False
pretrained_checkpoint = "kakaobrain/align-base"

def setUp(self):
self.model_tester = AlignTextModelTester(self)
self.config_tester = ConfigTester(self, config_class=AlignTextConfig, hidden_size=37)

def test_config(self):
self.config_tester.run_common_tests()

def test_model(self):
config_and_inputs = self.model_tester.prepare_config_and_inputs()
self.model_tester.create_and_check_model(*config_and_inputs)

@unittest.skip
def test_training(self):
pass
Expand Down Expand Up @@ -388,12 +370,6 @@ def test_save_load_fast_init_from_base(self):
def test_save_load_fast_init_to_base(self):
pass

@slow
def test_model_from_pretrained(self):
model_name = "kakaobrain/align-base"
model = AlignTextModel.from_pretrained(model_name)
self.assertIsNotNone(model)


class AlignModelTester:
def __init__(self, parent, text_kwargs=None, vision_kwargs=None, is_training=True):
Expand Down Expand Up @@ -454,14 +430,11 @@ class AlignModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase):
test_pruning = False
test_resize_embeddings = False
test_attention_outputs = False
pretrained_checkpoint = "kakaobrain/align-base"

def setUp(self):
self.model_tester = AlignModelTester(self)

def test_model(self):
config_and_inputs = self.model_tester.prepare_config_and_inputs()
self.model_tester.create_and_check_model(*config_and_inputs)

@unittest.skip(reason="Start to fail after using torch `cu118`.")
def test_multi_gpu_data_parallel_forward(self):
super().test_multi_gpu_data_parallel_forward()
Expand Down Expand Up @@ -601,12 +574,6 @@ def test_load_vision_text_config(self):
text_config = AlignTextConfig.from_pretrained(tmp_dir_name)
self.assertDictEqual(config.text_config.to_dict(), text_config.to_dict())

@slow
def test_model_from_pretrained(self):
model_name = "kakaobrain/align-base"
model = AlignModel.from_pretrained(model_name)
self.assertIsNotNone(model)


# We will verify our results on an image of cute cats
def prepare_img():
Expand Down
32 changes: 2 additions & 30 deletions tests/models/altclip/test_modeling_altclip.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,6 @@ def setUp(self):
self, config_class=AltCLIPVisionConfig, has_text_modality=False, hidden_size=37
)

def test_config(self):
self.config_tester.run_common_tests()

@unittest.skip(reason="CLIP does not use inputs_embeds")
def test_inputs_embeds(self):
pass
Expand All @@ -174,10 +171,6 @@ def test_forward_signature(self):
expected_arg_names = ["pixel_values"]
self.assertListEqual(arg_names[:1], expected_arg_names)

def test_model(self):
config_and_inputs = self.model_tester.prepare_config_and_inputs()
self.model_tester.create_and_check_model(*config_and_inputs)

@unittest.skip
def test_training(self):
pass
Expand Down Expand Up @@ -309,6 +302,7 @@ class AltCLIPTextModelTest(ModelTesterMixin, unittest.TestCase):
fx_compatible = True
test_pruning = False
test_head_masking = False
pretrained_checkpoint = "BAAI/AltCLIP"

# TODO (@SunMarc): Fix me
@unittest.skip(reason="It's broken.")
Expand All @@ -319,13 +313,6 @@ def setUp(self):
self.model_tester = AltCLIPTextModelTester(self)
self.config_tester = ConfigTester(self, config_class=AltCLIPTextConfig, hidden_size=37)

def test_config(self):
self.config_tester.run_common_tests()

def test_model(self):
config_and_inputs = self.model_tester.prepare_config_and_inputs()
self.model_tester.create_and_check_model(*config_and_inputs)

@unittest.skip
def test_training(self):
pass
Expand Down Expand Up @@ -365,12 +352,6 @@ def test_save_load_fast_init_from_base(self):
def test_save_load_fast_init_to_base(self):
pass

@slow
def test_model_from_pretrained(self):
model_name = "BAAI/AltCLIP"
model = AltCLIPTextModel.from_pretrained(model_name)
self.assertIsNotNone(model)


class AltCLIPModelTester:
def __init__(self, parent, text_kwargs=None, vision_kwargs=None, is_training=True):
Expand Down Expand Up @@ -433,6 +414,7 @@ class AltCLIPModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase)
test_pruning = False
test_resize_embeddings = False
test_attention_outputs = False
pretrained_checkpoint = "BAAI/AltCLIP"

# TODO: Fix the failed tests when this model gets more usage
def is_pipeline_test_to_skip(
Expand All @@ -446,10 +428,6 @@ def is_pipeline_test_to_skip(
def setUp(self):
self.model_tester = AltCLIPModelTester(self)

def test_model(self):
config_and_inputs = self.model_tester.prepare_config_and_inputs()
self.model_tester.create_and_check_model(*config_and_inputs)

@unittest.skip(reason="Hidden_states is tested in individual model tests")
def test_hidden_states_output(self):
pass
Expand Down Expand Up @@ -560,12 +538,6 @@ def _create_and_check_torchscript(self, config, inputs_dict):

self.assertTrue(models_equal)

@slow
def test_model_from_pretrained(self):
model_name = "BAAI/AltCLIP"
model = AltCLIPModel.from_pretrained(model_name)
self.assertIsNotNone(model)


@require_vision
@require_torch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ class ASTModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase):
test_pruning = False
test_resize_embeddings = False
test_head_masking = False
pretrained_checkpoint = "MIT/ast-finetuned-audioset-10-10-0.4593"

# TODO: Fix the failed tests when this model gets more usage
def is_pipeline_test_to_skip(
Expand All @@ -178,9 +179,6 @@ def setUp(self):
self.model_tester = ASTModelTester(self)
self.config_tester = ConfigTester(self, config_class=ASTConfig, has_text_modality=False, hidden_size=37)

def test_config(self):
self.config_tester.run_common_tests()

@unittest.skip(reason="AST does not use inputs_embeds")
def test_inputs_embeds(self):
pass
Expand All @@ -206,16 +204,6 @@ def test_forward_signature(self):
expected_arg_names = ["input_values"]
self.assertListEqual(arg_names[:1], expected_arg_names)

def test_model(self):
config_and_inputs = self.model_tester.prepare_config_and_inputs()
self.model_tester.create_and_check_model(*config_and_inputs)

@slow
def test_model_from_pretrained(self):
model_name = "MIT/ast-finetuned-audioset-10-10-0.4593"
model = ASTModel.from_pretrained(model_name)
self.assertIsNotNone(model)


# We will verify our results on some audio from AudioSet
def prepare_audio():
Expand Down
20 changes: 17 additions & 3 deletions tests/models/autoformer/test_modeling_autoformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,23 @@ def get_config(self):
scaling="std", # we need std to get non-zero `loc`
)

def create_and_check_model(self, config, input_values):
model = AutoformerModel(config=config)
model.to(torch_device)
model.eval()
result = model(**input_values)

past_time_features = input_values["past_time_features"]
future_time_features = input_values["future_time_features"]
past_length = config.context_length + max(config.lags_sequence)
time_feat = torch.cat(
[past_time_features[:, past_length - config.context_length :, ...], future_time_features], dim=1
)
sequence_length = time_feat.shape[1] - (config.context_length - config.label_length)
self.parent.assertEqual(
tuple(result.last_hidden_state.shape), (self.batch_size, sequence_length, self.hidden_size)
)

def prepare_autoformer_inputs_dict(self, config):
_past_length = config.context_length + max(config.lags_sequence)

Expand Down Expand Up @@ -217,9 +234,6 @@ def setUp(self):
self.model_tester = AutoformerModelTester(self)
self.config_tester = ConfigTester(self, config_class=AutoformerConfig, has_text_modality=False)

def test_config(self):
self.config_tester.run_common_tests()

def test_save_load_strict(self):
config, inputs_dict = self.model_tester.prepare_config_and_inputs()
for model_class in self.all_model_classes:
Expand Down
9 changes: 0 additions & 9 deletions tests/models/bark/test_modeling_bark.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,9 +542,6 @@ def setUp(self):
self.model_tester = BarkSemanticModelTester(self)
self.config_tester = ConfigTester(self, config_class=BarkSemanticConfig, n_embd=37)

def test_config(self):
self.config_tester.run_common_tests()

def test_save_load_strict(self):
config, inputs_dict = self.model_tester.prepare_config_and_inputs()
for model_class in self.all_model_classes:
Expand Down Expand Up @@ -631,9 +628,6 @@ def setUp(self):
self.model_tester = BarkCoarseModelTester(self)
self.config_tester = ConfigTester(self, config_class=BarkCoarseConfig, n_embd=37)

def test_config(self):
self.config_tester.run_common_tests()

def test_save_load_strict(self):
config, inputs_dict = self.model_tester.prepare_config_and_inputs()
for model_class in self.all_model_classes:
Expand Down Expand Up @@ -721,9 +715,6 @@ def setUp(self):
self.model_tester = BarkFineModelTester(self)
self.config_tester = ConfigTester(self, config_class=BarkFineConfig, n_embd=37)

def test_config(self):
self.config_tester.run_common_tests()

def test_save_load_strict(self):
config, inputs_dict = self.model_tester.prepare_config_and_inputs()
for model_class in self.all_model_classes:
Expand Down
6 changes: 0 additions & 6 deletions tests/models/bart/test_modeling_bart.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,9 +443,6 @@ def setUp(self):
self.model_tester = BartModelTester(self)
self.config_tester = ConfigTester(self, config_class=BartConfig)

def test_config(self):
self.config_tester.run_common_tests()

def test_save_load_strict(self):
config, inputs_dict = self.model_tester.prepare_config_and_inputs()
for model_class in self.all_model_classes:
Expand Down Expand Up @@ -1514,9 +1511,6 @@ def setUp(
self.model_tester = BartStandaloneDecoderModelTester(self, is_training=False)
self.config_tester = ConfigTester(self, config_class=BartConfig)

def test_config(self):
self.config_tester.run_common_tests()

def test_decoder_model_past(self):
config_and_inputs = self.model_tester.prepare_config_and_inputs()
self.model_tester.create_and_check_decoder_model_past(*config_and_inputs)
Expand Down
Loading
Loading