fix typos in the tests directory (#36932)
* chore: fix typos in test codes * chore: fix typos in test codes * chore: fix typos in test codes * chore: fix typos in test codes * chore: fix typos in test codes * chore: fix typos in test codes * chore: fix typos in test codes * chore: fix typos in test codes * chore: format codes
This commit is contained in:
@@ -130,7 +130,7 @@ class ChameleonModelTester:
|
|||||||
|
|
||||||
def get_config(self):
|
def get_config(self):
|
||||||
# create dummy vocab map for image2bpe mapping if it needs remapping
|
# create dummy vocab map for image2bpe mapping if it needs remapping
|
||||||
# we assume that vocab size is big enough to accoun for image tokens somewhere in the beginning
|
# we assume that vocab size is big enough to account for image tokens somewhere in the beginning
|
||||||
# same way as in real ckpt, when img tokens are in first half of embeds
|
# same way as in real ckpt, when img tokens are in first half of embeds
|
||||||
# we will need "vq_num_embeds" amount of tokens
|
# we will need "vq_num_embeds" amount of tokens
|
||||||
|
|
||||||
|
|||||||
@@ -699,10 +699,10 @@ class DabDetrModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase)
|
|||||||
self.model_tester.num_labels,
|
self.model_tester.num_labels,
|
||||||
)
|
)
|
||||||
self.assertEqual(outputs.logits.shape, expected_shape)
|
self.assertEqual(outputs.logits.shape, expected_shape)
|
||||||
# Confirm out_indices was propogated to backbone
|
# Confirm out_indices was propagated to backbone
|
||||||
self.assertEqual(len(model.model.backbone.conv_encoder.intermediate_channel_sizes), 3)
|
self.assertEqual(len(model.model.backbone.conv_encoder.intermediate_channel_sizes), 3)
|
||||||
else:
|
else:
|
||||||
# Confirm out_indices was propogated to backbone
|
# Confirm out_indices was propagated to backbone
|
||||||
self.assertEqual(len(model.backbone.conv_encoder.intermediate_channel_sizes), 3)
|
self.assertEqual(len(model.backbone.conv_encoder.intermediate_channel_sizes), 3)
|
||||||
|
|
||||||
self.assertTrue(outputs)
|
self.assertTrue(outputs)
|
||||||
@@ -726,7 +726,7 @@ class DabDetrModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase)
|
|||||||
abs(param.data.max().item()),
|
abs(param.data.max().item()),
|
||||||
msg=f"Parameter {name} of model {model_class} seems not properly initialized",
|
msg=f"Parameter {name} of model {model_class} seems not properly initialized",
|
||||||
)
|
)
|
||||||
# Modifed from RT-DETR
|
# Modified from RT-DETR
|
||||||
elif "class_embed" in name and "bias" in name:
|
elif "class_embed" in name and "bias" in name:
|
||||||
bias_tensor = torch.full_like(param.data, bias_value)
|
bias_tensor = torch.full_like(param.data, bias_value)
|
||||||
torch.testing.assert_close(
|
torch.testing.assert_close(
|
||||||
|
|||||||
@@ -358,7 +358,9 @@ class GraniteMoeSharedModelTest(ModelTesterMixin, GenerationTesterMixin, unittes
|
|||||||
long_input_length = int(config.max_position_embeddings * 1.5)
|
long_input_length = int(config.max_position_embeddings * 1.5)
|
||||||
|
|
||||||
# Inputs
|
# Inputs
|
||||||
x = torch.randn(1, dtype=torch.float32, device=torch_device) # used exlusively to get the dtype and the device
|
x = torch.randn(
|
||||||
|
1, dtype=torch.float32, device=torch_device
|
||||||
|
) # used exclusively to get the dtype and the device
|
||||||
position_ids_short = torch.arange(short_input_length, dtype=torch.long, device=torch_device)
|
position_ids_short = torch.arange(short_input_length, dtype=torch.long, device=torch_device)
|
||||||
position_ids_short = position_ids_short.unsqueeze(0)
|
position_ids_short = position_ids_short.unsqueeze(0)
|
||||||
position_ids_long = torch.arange(long_input_length, dtype=torch.long, device=torch_device)
|
position_ids_long = torch.arange(long_input_length, dtype=torch.long, device=torch_device)
|
||||||
|
|||||||
@@ -521,7 +521,7 @@ class IdeficsModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase)
|
|||||||
with torch.no_grad():
|
with torch.no_grad():
|
||||||
outputs = model(**self._prepare_for_class(inputs_dict, model_class))
|
outputs = model(**self._prepare_for_class(inputs_dict, model_class))
|
||||||
attentions = outputs.attentions
|
attentions = outputs.attentions
|
||||||
# IDEFICS does not support outputting attention score becuase it uses SDPA under the hood
|
# IDEFICS does not support outputting attention score because it uses SDPA under the hood
|
||||||
self.assertTrue(attentions[0] is None)
|
self.assertTrue(attentions[0] is None)
|
||||||
out_len = len(outputs)
|
out_len = len(outputs)
|
||||||
|
|
||||||
@@ -539,7 +539,7 @@ class IdeficsModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase)
|
|||||||
self_attentions = outputs.encoder_attentions if config.is_encoder_decoder else outputs.attentions
|
self_attentions = outputs.encoder_attentions if config.is_encoder_decoder else outputs.attentions
|
||||||
|
|
||||||
self.assertEqual(len(self_attentions), self.model_tester.num_hidden_layers)
|
self.assertEqual(len(self_attentions), self.model_tester.num_hidden_layers)
|
||||||
# IDEFICS does not support outputting attention score becuase it uses SDPA under the hood
|
# IDEFICS does not support outputting attention score because it uses SDPA under the hood
|
||||||
self.assertTrue(self_attentions[0] is None)
|
self.assertTrue(self_attentions[0] is None)
|
||||||
|
|
||||||
def test_hidden_states_output(self):
|
def test_hidden_states_output(self):
|
||||||
|
|||||||
@@ -372,7 +372,7 @@ class TFIdeficsModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestC
|
|||||||
model = model_class(config)
|
model = model_class(config)
|
||||||
outputs = model(**self._prepare_for_class(inputs_dict, model_class))
|
outputs = model(**self._prepare_for_class(inputs_dict, model_class))
|
||||||
attentions = outputs.attentions
|
attentions = outputs.attentions
|
||||||
# IDEFICS does not support outputting attention score becuase it uses SDPA under the hood
|
# IDEFICS does not support outputting attention score because it uses SDPA under the hood
|
||||||
self.assertTrue(attentions[0] is None)
|
self.assertTrue(attentions[0] is None)
|
||||||
out_len = len(outputs)
|
out_len = len(outputs)
|
||||||
|
|
||||||
@@ -386,7 +386,7 @@ class TFIdeficsModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestC
|
|||||||
self_attentions = outputs.encoder_attentions if config.is_encoder_decoder else outputs.attentions
|
self_attentions = outputs.encoder_attentions if config.is_encoder_decoder else outputs.attentions
|
||||||
|
|
||||||
self.assertEqual(len(self_attentions), self.model_tester.num_hidden_layers)
|
self.assertEqual(len(self_attentions), self.model_tester.num_hidden_layers)
|
||||||
# IDEFICS does not support outputting attention score becuase it uses SDPA under the hood
|
# IDEFICS does not support outputting attention score because it uses SDPA under the hood
|
||||||
self.assertTrue(self_attentions[0] is None)
|
self.assertTrue(self_attentions[0] is None)
|
||||||
|
|
||||||
def test_hidden_states_output(self):
|
def test_hidden_states_output(self):
|
||||||
|
|||||||
@@ -485,7 +485,7 @@ class MimiIntegrationTest(unittest.TestCase):
|
|||||||
|
|
||||||
for num_codebooks, expected_rmse in expected_rmse.items():
|
for num_codebooks, expected_rmse in expected_rmse.items():
|
||||||
with torch.no_grad():
|
with torch.no_grad():
|
||||||
# use max bandwith for best possible reconstruction
|
# use max bandwidth for best possible reconstruction
|
||||||
encoder_outputs = model.encode(inputs["input_values"], num_quantizers=int(num_codebooks))
|
encoder_outputs = model.encode(inputs["input_values"], num_quantizers=int(num_codebooks))
|
||||||
|
|
||||||
audio_codes = encoder_outputs[0]
|
audio_codes = encoder_outputs[0]
|
||||||
@@ -537,7 +537,7 @@ class MimiIntegrationTest(unittest.TestCase):
|
|||||||
model = MimiModel.from_pretrained(model_id, use_cache=use_cache).to(torch_device)
|
model = MimiModel.from_pretrained(model_id, use_cache=use_cache).to(torch_device)
|
||||||
for num_codebooks, expected_rmse in expected_rmses.items():
|
for num_codebooks, expected_rmse in expected_rmses.items():
|
||||||
with torch.no_grad():
|
with torch.no_grad():
|
||||||
# use max bandwith for best possible reconstruction
|
# use max bandwidth for best possible reconstruction
|
||||||
encoder_outputs = model.encode(inputs["input_values"], num_quantizers=int(num_codebooks))
|
encoder_outputs = model.encode(inputs["input_values"], num_quantizers=int(num_codebooks))
|
||||||
|
|
||||||
audio_code_sums = encoder_outputs[0].sum().cpu().item()
|
audio_code_sums = encoder_outputs[0].sum().cpu().item()
|
||||||
|
|||||||
@@ -547,10 +547,10 @@ class RTDetrModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase):
|
|||||||
self.model_tester.num_labels,
|
self.model_tester.num_labels,
|
||||||
)
|
)
|
||||||
self.assertEqual(outputs.logits.shape, expected_shape)
|
self.assertEqual(outputs.logits.shape, expected_shape)
|
||||||
# Confirm out_indices was propogated to backbone
|
# Confirm out_indices was propagated to backbone
|
||||||
self.assertEqual(len(model.model.backbone.intermediate_channel_sizes), 3)
|
self.assertEqual(len(model.model.backbone.intermediate_channel_sizes), 3)
|
||||||
else:
|
else:
|
||||||
# Confirm out_indices was propogated to backbone
|
# Confirm out_indices was propagated to backbone
|
||||||
self.assertEqual(len(model.backbone.intermediate_channel_sizes), 3)
|
self.assertEqual(len(model.backbone.intermediate_channel_sizes), 3)
|
||||||
|
|
||||||
self.assertTrue(outputs)
|
self.assertTrue(outputs)
|
||||||
@@ -579,10 +579,10 @@ class RTDetrModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase):
|
|||||||
self.model_tester.num_labels,
|
self.model_tester.num_labels,
|
||||||
)
|
)
|
||||||
self.assertEqual(outputs.logits.shape, expected_shape)
|
self.assertEqual(outputs.logits.shape, expected_shape)
|
||||||
# Confirm out_indices was propogated to backbone
|
# Confirm out_indices was propagated to backbone
|
||||||
self.assertEqual(len(model.model.backbone.intermediate_channel_sizes), 3)
|
self.assertEqual(len(model.model.backbone.intermediate_channel_sizes), 3)
|
||||||
else:
|
else:
|
||||||
# Confirm out_indices was propogated to backbone
|
# Confirm out_indices was propagated to backbone
|
||||||
self.assertEqual(len(model.backbone.intermediate_channel_sizes), 3)
|
self.assertEqual(len(model.backbone.intermediate_channel_sizes), 3)
|
||||||
|
|
||||||
self.assertTrue(outputs)
|
self.assertTrue(outputs)
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ class ShieldGemma2ProcessorTest(ProcessorTesterMixin, unittest.TestCase):
|
|||||||
if processor.chat_template is None:
|
if processor.chat_template is None:
|
||||||
self.skipTest("Processor has no chat template")
|
self.skipTest("Processor has no chat template")
|
||||||
|
|
||||||
# Test policies adapated from https://ailuminate.mlcommons.org/benchmarks/ hazard categories
|
# Test policies adapted from https://ailuminate.mlcommons.org/benchmarks/ hazard categories
|
||||||
custom_policies = {
|
custom_policies = {
|
||||||
"cbrne": "Test policy related to indiscriminate weapons.",
|
"cbrne": "Test policy related to indiscriminate weapons.",
|
||||||
"ip": "Test policy related to intellectual property.",
|
"ip": "Test policy related to intellectual property.",
|
||||||
|
|||||||
@@ -391,7 +391,7 @@ class VideoLlavaForConditionalGenerationModelTest(ModelTesterMixin, GenerationTe
|
|||||||
config, input_dict = self.model_tester.prepare_config_and_inputs_for_common()
|
config, input_dict = self.model_tester.prepare_config_and_inputs_for_common()
|
||||||
for model_class in self.all_model_classes:
|
for model_class in self.all_model_classes:
|
||||||
model = model_class(config).to(torch_device)
|
model = model_class(config).to(torch_device)
|
||||||
_ = model(**input_dict) # successfull forward with no modifications
|
_ = model(**input_dict) # successful forward with no modifications
|
||||||
|
|
||||||
# remove one image but leave the image token in text
|
# remove one image but leave the image token in text
|
||||||
input_dict["pixel_values_images"] = input_dict["pixel_values_images"][-1:, ...]
|
input_dict["pixel_values_images"] = input_dict["pixel_values_images"][-1:, ...]
|
||||||
|
|||||||
Reference in New Issue
Block a user