Skip to content

Commit 27b9c79

Browse files
CyrilvallezArthurZucker
authored andcommitted
Remove test_initialization (#41261)
remove it
1 parent a2de293 commit 27b9c79

File tree

136 files changed

+53
-3207
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

136 files changed

+53
-3207
lines changed

conftest.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
"test_gradient_checkpointing_backward_compatibility",
5555
"test_gradient_checkpointing_enable_disable",
5656
"test_torch_save_load",
57-
"test_initialization",
5857
"test_forward_signature",
5958
"test_model_get_set_embeddings",
6059
"test_model_main_input_name",

tests/models/aimv2/test_modeling_aimv2.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
from ...test_modeling_common import (
4040
TEST_EAGER_MATCHES_SDPA_INFERENCE_PARAMETERIZATION,
4141
ModelTesterMixin,
42-
_config_zero_init,
4342
_test_eager_matches_sdpa_inference,
4443
floats_tensor,
4544
ids_tensor,
@@ -430,30 +429,6 @@ def test_model_get_set_embeddings(self):
430429
def test_multi_gpu_data_parallel_forward(self):
431430
pass
432431

433-
# Override as the `logit_scale` parameter initialization is different for Aimv2
434-
def test_initialization(self):
435-
config, inputs_dict = self.model_tester.prepare_config_and_inputs_for_common()
436-
437-
configs_no_init = _config_zero_init(config)
438-
for model_class in self.all_model_classes:
439-
model = model_class(config=configs_no_init)
440-
for name, param in model.named_parameters():
441-
if param.requires_grad:
442-
# check if `logit_scale` is initialized as per the original implementation
443-
if name == "logit_scale":
444-
self.assertAlmostEqual(
445-
param.data.item(),
446-
np.log(1 / 0.07),
447-
delta=1e-3,
448-
msg=f"Parameter {name} of model {model_class} seems not properly initialized",
449-
)
450-
else:
451-
self.assertIn(
452-
((param.data.mean() * 1e9).round() / 1e9).item(),
453-
[0.0, 1.0],
454-
msg=f"Parameter {name} of model {model_class} seems not properly initialized",
455-
)
456-
457432
def test_load_vision_text_config(self):
458433
config, inputs_dict = self.model_tester.prepare_config_and_inputs_for_common()
459434

tests/models/align/test_modeling_align.py

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ def test_batching_equivalence(self, atol=3e-4, rtol=3e-4):
469469

470470
@unittest.skip(reason="Start to fail after using torch `cu118`.")
471471
def test_multi_gpu_data_parallel_forward(self):
472-
super().test_multi_gpu_data_parallel_forward()
472+
pass
473473

474474
@unittest.skip(reason="Hidden_states is tested in individual model tests")
475475
def test_hidden_states_output(self):
@@ -491,35 +491,6 @@ def test_retain_grad_hidden_states_attentions(self):
491491
def test_model_get_set_embeddings(self):
492492
pass
493493

494-
# override as the `temperature` parameter initialization is different for ALIGN
495-
def test_initialization(self):
496-
config, inputs_dict = self.model_tester.prepare_config_and_inputs_for_common()
497-
498-
configs_no_init = _config_zero_init(config)
499-
for model_class in self.all_model_classes:
500-
model = model_class(config=configs_no_init)
501-
for name, param in model.named_parameters():
502-
if param.requires_grad:
503-
# check if `temperature` is initialized as per the original implementation
504-
if name == "temperature":
505-
self.assertAlmostEqual(
506-
param.data.item(),
507-
1.0,
508-
delta=1e-3,
509-
msg=f"Parameter {name} of model {model_class} seems not properly initialized",
510-
)
511-
elif name == "text_projection.weight":
512-
self.assertTrue(
513-
-1.0 <= ((param.data.mean() * 1e9).round() / 1e9).item() <= 1.0,
514-
msg=f"Parameter {name} of model {model_class} seems not properly initialized",
515-
)
516-
else:
517-
self.assertIn(
518-
((param.data.mean() * 1e9).round() / 1e9).item(),
519-
[0.0, 1.0],
520-
msg=f"Parameter {name} of model {model_class} seems not properly initialized",
521-
)
522-
523494
def _create_and_check_torchscript(self, config, inputs_dict):
524495
if not self.test_torchscript:
525496
self.skipTest(reason="test_torchscript is set to False")

tests/models/altclip/test_modeling_altclip.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -467,29 +467,6 @@ def test_retain_grad_hidden_states_attentions(self):
467467
def test_model_get_set_embeddings(self):
468468
pass
469469

470-
# override as the `logit_scale` parameter initialization is different for AltCLIP
471-
def test_initialization(self):
472-
config, inputs_dict = self.model_tester.prepare_config_and_inputs_for_common()
473-
configs_no_init = _config_zero_init(config)
474-
for model_class in self.all_model_classes:
475-
model = model_class(config=configs_no_init)
476-
for name, param in model.named_parameters():
477-
if param.requires_grad:
478-
# check if `logit_scale` is initialized as per the original implementation
479-
if name == "logit_scale":
480-
self.assertAlmostEqual(
481-
param.data.item(),
482-
np.log(1 / 0.07),
483-
delta=1e-3,
484-
msg=f"Parameter {name} of model {model_class} seems not properly initialized",
485-
)
486-
else:
487-
self.assertIn(
488-
((param.data.mean() * 1e9).round() / 1e9).item(),
489-
[0.0, 1.0],
490-
msg=f"Parameter {name} of model {model_class} seems not properly initialized",
491-
)
492-
493470
def _create_and_check_torchscript(self, config, inputs_dict):
494471
if not self.test_torchscript:
495472
self.skipTest(reason="test_torchscript is set to False")

tests/models/aria/test_modeling_aria.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,6 @@ def setUp(self):
199199
self.model_tester = AriaVisionText2TextModelTester(self)
200200
self.config_tester = ConfigTester(self, config_class=AriaConfig, has_text_modality=False)
201201

202-
@unittest.skip(reason="Unstable test")
203-
def test_initialization(self):
204-
pass
205-
206202

207203
SKIP = False
208204
torch_accelerator_module = getattr(torch, torch_device)

tests/models/aya_vision/test_modeling_aya_vision.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,6 @@ def test_training_gradient_checkpointing_use_reentrant(self):
198198
def test_training_gradient_checkpointing_use_reentrant_false(self):
199199
pass
200200

201-
@unittest.skip(reason="Siglip uses the same initialization scheme as the Flax original implementation")
202-
def test_initialization(self):
203-
pass
204-
205201
@unittest.skip(reason="Compile not yet supported because in LLava models")
206202
@pytest.mark.torch_compile_test
207203
def test_sdpa_can_compile_dynamic(self):

tests/models/bamba/test_modeling_bamba.py

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
from ...generation.test_utils import GenerationTesterMixin
4343
from ...test_configuration_common import ConfigTester
44-
from ...test_modeling_common import ModelTesterMixin, _config_zero_init, ids_tensor
44+
from ...test_modeling_common import ModelTesterMixin, ids_tensor
4545
from ...test_pipeline_mixin import PipelineTesterMixin
4646

4747

@@ -336,30 +336,6 @@ def test_decoder_model_past_with_large_inputs(self):
336336
config_and_inputs = self.model_tester.prepare_config_and_inputs()
337337
self.model_tester.create_and_check_decoder_model_past_large_inputs(*config_and_inputs)
338338

339-
def test_initialization(self):
340-
r"""
341-
Overriding the test_initialization test as the A_log and D params of the Bamba mixer are initialized differently
342-
"""
343-
config, inputs_dict = self.model_tester.prepare_config_and_inputs_for_common()
344-
345-
configs_no_init = _config_zero_init(config)
346-
for model_class in self.all_model_classes:
347-
model = model_class(config=configs_no_init)
348-
for name, param in model.named_parameters():
349-
if param.requires_grad:
350-
if "A_log" in name:
351-
A = torch.arange(1, config.mamba_n_heads + 1, dtype=torch.float32)
352-
torch.testing.assert_close(param.data, torch.log(A), rtol=1e-5, atol=1e-5)
353-
elif "D" in name:
354-
D = torch.ones(config.mamba_n_heads, dtype=torch.float32)
355-
torch.testing.assert_close(param.data, D, rtol=1e-5, atol=1e-5)
356-
else:
357-
self.assertIn(
358-
((param.data.mean() * 1e9).round() / 1e9).item(),
359-
[0.0, 1.0],
360-
msg=f"Parameter {name} of model {model_class} seems not properly initialized",
361-
)
362-
363339
def test_attention_outputs(self):
364340
r"""
365341
Overriding the test_attention_outputs test as the Bamba model outputs attention only for its attention layers

tests/models/beit/test_modeling_beit.py

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
from ...test_backbone_common import BackboneTesterMixin
3636
from ...test_configuration_common import ConfigTester
37-
from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor
37+
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
3838
from ...test_pipeline_mixin import PipelineTesterMixin
3939

4040

@@ -383,24 +383,6 @@ def test_training_gradient_checkpointing_use_reentrant(self):
383383
def test_training_gradient_checkpointing_use_reentrant_false(self):
384384
pass
385385

386-
def test_initialization(self):
387-
config, inputs_dict = self.model_tester.prepare_config_and_inputs_for_common()
388-
389-
configs_no_init = _config_zero_init(config)
390-
for model_class in self.all_model_classes:
391-
model = model_class(config=configs_no_init)
392-
for name, param in model.named_parameters():
393-
# we skip lambda parameters as these require special initial values
394-
# determined by config.layer_scale_init_value
395-
if "lambda" in name:
396-
continue
397-
if param.requires_grad:
398-
self.assertIn(
399-
((param.data.mean() * 1e9).round() / 1e9).item(),
400-
[0.0, 1.0],
401-
msg=f"Parameter {name} of model {model_class} seems not properly initialized",
402-
)
403-
404386
@slow
405387
def test_model_from_pretrained(self):
406388
model_name = "microsoft/beit-base-patch16-224"

tests/models/bit/test_modeling_bit.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828

2929
if is_torch_available():
3030
import torch
31-
from torch import nn
3231

3332
from transformers import BitBackbone, BitForImageClassification, BitImageProcessor, BitModel
3433

@@ -201,22 +200,6 @@ def test_backbone(self):
201200
config_and_inputs = self.model_tester.prepare_config_and_inputs()
202201
self.model_tester.create_and_check_backbone(*config_and_inputs)
203202

204-
def test_initialization(self):
205-
config, inputs_dict = self.model_tester.prepare_config_and_inputs_for_common()
206-
207-
for model_class in self.all_model_classes:
208-
model = model_class(config=config)
209-
for name, module in model.named_modules():
210-
if isinstance(module, (nn.BatchNorm2d, nn.GroupNorm)):
211-
self.assertTrue(
212-
torch.all(module.weight == 1),
213-
msg=f"Parameter {name} of model {model_class} seems not properly initialized",
214-
)
215-
self.assertTrue(
216-
torch.all(module.bias == 0),
217-
msg=f"Parameter {name} of model {model_class} seems not properly initialized",
218-
)
219-
220203
def test_hidden_states_output(self):
221204
def check_hidden_states_output(inputs_dict, config, model_class):
222205
model = model_class(config)

tests/models/blip/test_modeling_blip.py

Lines changed: 0 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -459,41 +459,6 @@ def test_retain_grad_hidden_states_attentions(self):
459459
def test_model_get_set_embeddings(self):
460460
pass
461461

462-
# override as the `logit_scale` parameter initialization is different for Blip
463-
def test_initialization(self):
464-
config, inputs_dict = self.model_tester.prepare_config_and_inputs_for_common()
465-
466-
configs_no_init = _config_zero_init(config)
467-
for model_class in self.all_model_classes:
468-
model = model_class(config=configs_no_init)
469-
for name, param in model.named_parameters():
470-
if param.requires_grad:
471-
# check if `logit_scale` is initialized as per the original implementation
472-
if name == "logit_scale":
473-
self.assertAlmostEqual(
474-
param.data.item(),
475-
np.log(1 / 0.07),
476-
delta=1e-3,
477-
msg=f"Parameter {name} of model {model_class} seems not properly initialized",
478-
)
479-
else:
480-
# See PR #38607 (to avoid flakiness)
481-
data = torch.flatten(param.data)
482-
n_elements = torch.numel(data)
483-
# skip 2.5% of elements on each side to avoid issues caused by `nn.init.trunc_normal_` described in
484-
# https://github.com/huggingface/transformers/pull/27906#issuecomment-1846951332
485-
n_elements_to_skip_on_each_side = int(n_elements * 0.025)
486-
data_to_check = torch.sort(data).values
487-
if n_elements_to_skip_on_each_side > 0:
488-
data_to_check = data_to_check[
489-
n_elements_to_skip_on_each_side:-n_elements_to_skip_on_each_side
490-
]
491-
self.assertIn(
492-
((data_to_check.mean() * 1e9).round() / 1e9).item(),
493-
[0.0, 1.0],
494-
msg=f"Parameter {name} of model {model_class} seems not properly initialized",
495-
)
496-
497462
def _create_and_check_torchscript(self, config, inputs_dict):
498463
if not self.test_torchscript:
499464
self.skipTest(reason="test_torchscript is set to False")
@@ -990,30 +955,6 @@ def test_training_gradient_checkpointing_use_reentrant(self):
990955
def test_training_gradient_checkpointing_use_reentrant_false(self):
991956
pass
992957

993-
# override as the `logit_scale` parameter initialization is different for Blip
994-
def test_initialization(self):
995-
config, inputs_dict = self.model_tester.prepare_config_and_inputs_for_common()
996-
997-
configs_no_init = _config_zero_init(config)
998-
for model_class in self.all_model_classes:
999-
model = model_class(config=configs_no_init)
1000-
for name, param in model.named_parameters():
1001-
if param.requires_grad:
1002-
# check if `logit_scale` is initialized as per the original implementation
1003-
if name == "logit_scale":
1004-
self.assertAlmostEqual(
1005-
param.data.item(),
1006-
np.log(1 / 0.07),
1007-
delta=1e-3,
1008-
msg=f"Parameter {name} of model {model_class} seems not properly initialized",
1009-
)
1010-
else:
1011-
self.assertIn(
1012-
((param.data.mean() * 1e9).round() / 1e9).item(),
1013-
[0.0, 1.0],
1014-
msg=f"Parameter {name} of model {model_class} seems not properly initialized",
1015-
)
1016-
1017958
def _create_and_check_torchscript(self, config, inputs_dict):
1018959
if not self.test_torchscript:
1019960
self.skipTest(reason="test_torchscript is set to False")
@@ -1208,30 +1149,6 @@ def test_training_gradient_checkpointing(self):
12081149
loss = model(**inputs).loss
12091150
loss.backward()
12101151

1211-
# override as the `logit_scale` parameter initialization is different for Blip
1212-
def test_initialization(self):
1213-
config, inputs_dict = self.model_tester.prepare_config_and_inputs_for_common()
1214-
1215-
configs_no_init = _config_zero_init(config)
1216-
for model_class in self.all_model_classes:
1217-
model = model_class(config=configs_no_init)
1218-
for name, param in model.named_parameters():
1219-
if param.requires_grad:
1220-
# check if `logit_scale` is initialized as per the original implementation
1221-
if name == "logit_scale":
1222-
self.assertAlmostEqual(
1223-
param.data.item(),
1224-
np.log(1 / 0.07),
1225-
delta=1e-3,
1226-
msg=f"Parameter {name} of model {model_class} seems not properly initialized",
1227-
)
1228-
else:
1229-
self.assertIn(
1230-
((param.data.mean() * 1e9).round() / 1e9).item(),
1231-
[0.0, 1.0],
1232-
msg=f"Parameter {name} of model {model_class} seems not properly initialized",
1233-
)
1234-
12351152
def _create_and_check_torchscript(self, config, inputs_dict):
12361153
if not self.test_torchscript:
12371154
self.skipTest(reason="test_torchscript is set to False")

0 commit comments

Comments
 (0)