Apply ruff flake8-comprehensions (#21694)
This commit is contained in:
@@ -939,7 +939,7 @@ class BartModelIntegrationTests(unittest.TestCase):
|
||||
|
||||
def test_xsum_config_generation_params(self):
|
||||
config = BartConfig.from_pretrained("facebook/bart-large-xsum")
|
||||
expected_params = dict(num_beams=6, do_sample=False, early_stopping=True, length_penalty=1.0)
|
||||
expected_params = {"num_beams": 6, "do_sample": False, "early_stopping": True, "length_penalty": 1.0}
|
||||
config_params = {k: getattr(config, k, "MISSING") for k, v in expected_params.items()}
|
||||
self.assertDictEqual(expected_params, config_params)
|
||||
|
||||
|
||||
@@ -299,8 +299,8 @@ class Blenderbot3BIntegrationTests(unittest.TestCase):
|
||||
|
||||
@slow
|
||||
def test_generation_from_short_input_same_as_parlai_3B(self):
|
||||
FASTER_GEN_KWARGS = dict(num_beams=1, early_stopping=True, min_length=15, max_length=25)
|
||||
TOK_DECODE_KW = dict(skip_special_tokens=True, clean_up_tokenization_spaces=True)
|
||||
FASTER_GEN_KWARGS = {"num_beams": 1, "early_stopping": True, "min_length": 15, "max_length": 25}
|
||||
TOK_DECODE_KW = {"skip_special_tokens": True, "clean_up_tokenization_spaces": True}
|
||||
|
||||
torch.cuda.empty_cache()
|
||||
model = BlenderbotForConditionalGeneration.from_pretrained(self.ckpt).half().to(torch_device)
|
||||
|
||||
@@ -402,8 +402,8 @@ class FlaxBlenderbotModelTest(FlaxModelTesterMixin, unittest.TestCase, FlaxGener
|
||||
@unittest.skipUnless(jax_device != "cpu", "3B test too slow on CPU.")
|
||||
@slow
|
||||
def test_generation_from_short_input_same_as_parlai_3B(self):
|
||||
FASTER_GEN_KWARGS = dict(num_beams=1, early_stopping=True, min_length=15, max_length=25)
|
||||
TOK_DECODE_KW = dict(skip_special_tokens=True, clean_up_tokenization_spaces=True)
|
||||
FASTER_GEN_KWARGS = {"num_beams": 1, "early_stopping": True, "min_length": 15, "max_length": 25}
|
||||
TOK_DECODE_KW = {"skip_special_tokens": True, "clean_up_tokenization_spaces": True}
|
||||
|
||||
model = FlaxBlenderbotForConditionalGeneration.from_pretrained("facebook/blenderbot-3B", from_pt=True)
|
||||
tokenizer = BlenderbotTokenizer.from_pretrained("facebook/blenderbot-3B")
|
||||
|
||||
@@ -124,7 +124,7 @@ class BloomTokenizationTest(TokenizerTesterMixin, unittest.TestCase):
|
||||
input_text = list(sample_data.values())
|
||||
|
||||
output_tokens = list(map(tokenizer.encode, input_text))
|
||||
predicted_text = list(map(lambda x: tokenizer.decode(x, clean_up_tokenization_spaces=False), output_tokens))
|
||||
predicted_text = [tokenizer.decode(x, clean_up_tokenization_spaces=False) for x in output_tokens]
|
||||
self.assertListEqual(predicted_text, input_text)
|
||||
|
||||
def test_pretrained_model_lists(self):
|
||||
|
||||
@@ -551,7 +551,7 @@ class TFCLIPModelTest(TFModelTesterMixin, unittest.TestCase):
|
||||
if self.__class__.__name__ == "TFCLIPModelTest":
|
||||
inputs_dict.pop("return_loss", None)
|
||||
|
||||
tf_main_layer_classes = set(
|
||||
tf_main_layer_classes = {
|
||||
module_member
|
||||
for model_class in self.all_model_classes
|
||||
for module in (import_module(model_class.__module__),)
|
||||
@@ -563,7 +563,7 @@ class TFCLIPModelTest(TFModelTesterMixin, unittest.TestCase):
|
||||
if isinstance(module_member, type)
|
||||
and tf.keras.layers.Layer in module_member.__bases__
|
||||
and getattr(module_member, "_keras_serializable", False)
|
||||
)
|
||||
}
|
||||
for main_layer_class in tf_main_layer_classes:
|
||||
# T5MainLayer needs an embed_tokens parameter when called without the inputs_embeds parameter
|
||||
if "T5" in main_layer_class.__name__:
|
||||
|
||||
@@ -398,7 +398,7 @@ class TFData2VecVisionModelTest(TFModelTesterMixin, unittest.TestCase):
|
||||
# The number of elements in the loss should be the same as the number of elements in the label
|
||||
_, prepared_for_class = self.model_tester.prepare_config_and_inputs_for_keras_fit()
|
||||
added_label = prepared_for_class[
|
||||
sorted(list(prepared_for_class.keys() - inputs_dict.keys()), reverse=True)[0]
|
||||
sorted(prepared_for_class.keys() - inputs_dict.keys(), reverse=True)[0]
|
||||
]
|
||||
loss_size = tf.size(added_label)
|
||||
|
||||
|
||||
@@ -628,7 +628,7 @@ class TFGroupViTModelTest(TFModelTesterMixin, unittest.TestCase):
|
||||
if self.__class__.__name__ == "TFGroupViTModelTest":
|
||||
inputs_dict.pop("return_loss", None)
|
||||
|
||||
tf_main_layer_classes = set(
|
||||
tf_main_layer_classes = {
|
||||
module_member
|
||||
for model_class in self.all_model_classes
|
||||
for module in (import_module(model_class.__module__),)
|
||||
@@ -640,7 +640,7 @@ class TFGroupViTModelTest(TFModelTesterMixin, unittest.TestCase):
|
||||
if isinstance(module_member, type)
|
||||
and tf.keras.layers.Layer in module_member.__bases__
|
||||
and getattr(module_member, "_keras_serializable", False)
|
||||
)
|
||||
}
|
||||
for main_layer_class in tf_main_layer_classes:
|
||||
# T5MainLayer needs an embed_tokens parameter when called without the inputs_embeds parameter
|
||||
if "T5" in main_layer_class.__name__:
|
||||
|
||||
@@ -30,10 +30,10 @@ if is_torch_available():
|
||||
class Jukebox1bModelTester(unittest.TestCase):
|
||||
all_model_classes = (JukeboxModel,) if is_torch_available() else ()
|
||||
model_id = "openai/jukebox-1b-lyrics"
|
||||
metas = dict(
|
||||
artist="Zac Brown Band",
|
||||
genres="Country",
|
||||
lyrics="""I met a traveller from an antique land,
|
||||
metas = {
|
||||
"artist": "Zac Brown Band",
|
||||
"genres": "Country",
|
||||
"lyrics": """I met a traveller from an antique land,
|
||||
Who said "Two vast and trunkless legs of stone
|
||||
Stand in the desert. . . . Near them, on the sand,
|
||||
Half sunk a shattered visage lies, whose frown,
|
||||
@@ -48,7 +48,7 @@ class Jukebox1bModelTester(unittest.TestCase):
|
||||
Of that colossal Wreck, boundless and bare
|
||||
The lone and level sands stretch far away
|
||||
""",
|
||||
)
|
||||
}
|
||||
# fmt: off
|
||||
EXPECTED_OUTPUT_2 = [
|
||||
1864, 1536, 1213, 1870, 1357, 1536, 519, 880, 1323, 789, 1082, 534,
|
||||
@@ -180,7 +180,7 @@ class Jukebox1bModelTester(unittest.TestCase):
|
||||
model = JukeboxModel.from_pretrained(self.model_id, min_duration=0).eval()
|
||||
set_seed(0)
|
||||
waveform = torch.rand((1, 5120, 1))
|
||||
tokens = [i for i in self.prepare_inputs()]
|
||||
tokens = list(self.prepare_inputs())
|
||||
|
||||
zs = [model.vqvae.encode(waveform, start_level=2, bs_chunks=waveform.shape[0])[0], None, None]
|
||||
zs = model._sample(
|
||||
@@ -220,10 +220,10 @@ class Jukebox1bModelTester(unittest.TestCase):
|
||||
class Jukebox5bModelTester(unittest.TestCase):
|
||||
all_model_classes = (JukeboxModel,) if is_torch_available() else ()
|
||||
model_id = "openai/jukebox-5b-lyrics"
|
||||
metas = dict(
|
||||
artist="Zac Brown Band",
|
||||
genres="Country",
|
||||
lyrics="""I met a traveller from an antique land,
|
||||
metas = {
|
||||
"artist": "Zac Brown Band",
|
||||
"genres": "Country",
|
||||
"lyrics": """I met a traveller from an antique land,
|
||||
Who said "Two vast and trunkless legs of stone
|
||||
Stand in the desert. . . . Near them, on the sand,
|
||||
Half sunk a shattered visage lies, whose frown,
|
||||
@@ -238,7 +238,7 @@ class Jukebox5bModelTester(unittest.TestCase):
|
||||
Of that colossal Wreck, boundless and bare
|
||||
The lone and level sands stretch far away
|
||||
""",
|
||||
)
|
||||
}
|
||||
|
||||
# fmt: off
|
||||
EXPECTED_OUTPUT_2 = [
|
||||
|
||||
@@ -21,10 +21,10 @@ from transformers.testing_utils import require_torch
|
||||
|
||||
class JukeboxTokenizationTest(unittest.TestCase):
|
||||
tokenizer_class = JukeboxTokenizer
|
||||
metas = dict(
|
||||
artist="Zac Brown Band",
|
||||
genres="Country",
|
||||
lyrics="""I met a traveller from an antique land,
|
||||
metas = {
|
||||
"artist": "Zac Brown Band",
|
||||
"genres": "Country",
|
||||
"lyrics": """I met a traveller from an antique land,
|
||||
Who said "Two vast and trunkless legs of stone
|
||||
Stand in the desert. . . . Near them, on the sand,
|
||||
Half sunk a shattered visage lies, whose frown,
|
||||
@@ -39,7 +39,7 @@ class JukeboxTokenizationTest(unittest.TestCase):
|
||||
Of that colossal Wreck, boundless and bare
|
||||
The lone and level sands stretch far away
|
||||
""",
|
||||
)
|
||||
}
|
||||
|
||||
@require_torch
|
||||
def test_1b_lyrics_tokenizer(self):
|
||||
|
||||
@@ -233,7 +233,7 @@ class LayoutLMv2ProcessorIntegrationTests(unittest.TestCase):
|
||||
|
||||
# verify keys
|
||||
expected_keys = ["attention_mask", "bbox", "image", "input_ids", "token_type_ids"]
|
||||
actual_keys = sorted(list(input_processor.keys()))
|
||||
actual_keys = sorted(input_processor.keys())
|
||||
self.assertListEqual(actual_keys, expected_keys)
|
||||
|
||||
# verify image
|
||||
@@ -253,7 +253,7 @@ class LayoutLMv2ProcessorIntegrationTests(unittest.TestCase):
|
||||
|
||||
# verify keys
|
||||
expected_keys = ["attention_mask", "bbox", "image", "input_ids", "token_type_ids"]
|
||||
actual_keys = sorted(list(input_processor.keys()))
|
||||
actual_keys = sorted(input_processor.keys())
|
||||
self.assertListEqual(actual_keys, expected_keys)
|
||||
|
||||
# verify images
|
||||
@@ -301,7 +301,7 @@ class LayoutLMv2ProcessorIntegrationTests(unittest.TestCase):
|
||||
|
||||
# verify keys
|
||||
expected_keys = ["attention_mask", "bbox", "image", "input_ids", "token_type_ids"]
|
||||
actual_keys = sorted(list(input_processor.keys()))
|
||||
actual_keys = sorted(input_processor.keys())
|
||||
self.assertListEqual(actual_keys, expected_keys)
|
||||
|
||||
# verify input_ids
|
||||
@@ -340,7 +340,7 @@ class LayoutLMv2ProcessorIntegrationTests(unittest.TestCase):
|
||||
|
||||
# verify keys
|
||||
expected_keys = ["attention_mask", "bbox", "image", "input_ids", "labels", "token_type_ids"]
|
||||
actual_keys = sorted(list(input_processor.keys()))
|
||||
actual_keys = sorted(input_processor.keys())
|
||||
self.assertListEqual(actual_keys, expected_keys)
|
||||
|
||||
# verify input_ids
|
||||
@@ -362,7 +362,7 @@ class LayoutLMv2ProcessorIntegrationTests(unittest.TestCase):
|
||||
|
||||
# verify keys
|
||||
expected_keys = ["attention_mask", "bbox", "image", "input_ids", "labels", "token_type_ids"]
|
||||
actual_keys = sorted(list(input_processor.keys()))
|
||||
actual_keys = sorted(input_processor.keys())
|
||||
self.assertListEqual(actual_keys, expected_keys)
|
||||
|
||||
# verify input_ids
|
||||
@@ -403,7 +403,7 @@ class LayoutLMv2ProcessorIntegrationTests(unittest.TestCase):
|
||||
|
||||
# verify keys
|
||||
expected_keys = ["attention_mask", "bbox", "image", "input_ids", "token_type_ids"]
|
||||
actual_keys = sorted(list(input_processor.keys()))
|
||||
actual_keys = sorted(input_processor.keys())
|
||||
self.assertListEqual(actual_keys, expected_keys)
|
||||
|
||||
# verify input_ids
|
||||
@@ -422,7 +422,7 @@ class LayoutLMv2ProcessorIntegrationTests(unittest.TestCase):
|
||||
|
||||
# verify keys
|
||||
expected_keys = ["attention_mask", "bbox", "image", "input_ids", "token_type_ids"]
|
||||
actual_keys = sorted(list(input_processor.keys()))
|
||||
actual_keys = sorted(input_processor.keys())
|
||||
self.assertListEqual(actual_keys, expected_keys)
|
||||
|
||||
# verify input_ids
|
||||
@@ -456,7 +456,7 @@ class LayoutLMv2ProcessorIntegrationTests(unittest.TestCase):
|
||||
|
||||
# verify keys
|
||||
expected_keys = ["attention_mask", "bbox", "image", "input_ids", "token_type_ids"]
|
||||
actual_keys = sorted(list(input_processor.keys()))
|
||||
actual_keys = sorted(input_processor.keys())
|
||||
self.assertListEqual(actual_keys, expected_keys)
|
||||
|
||||
# verify input_ids
|
||||
@@ -472,7 +472,7 @@ class LayoutLMv2ProcessorIntegrationTests(unittest.TestCase):
|
||||
|
||||
# verify keys
|
||||
expected_keys = ["attention_mask", "bbox", "image", "input_ids", "token_type_ids"]
|
||||
actual_keys = sorted(list(input_processor.keys()))
|
||||
actual_keys = sorted(input_processor.keys())
|
||||
self.assertListEqual(actual_keys, expected_keys)
|
||||
|
||||
# verify input_ids
|
||||
|
||||
@@ -320,7 +320,7 @@ class TFLayoutLMv3ModelTest(TFModelTesterMixin, unittest.TestCase):
|
||||
# The number of elements in the loss should be the same as the number of elements in the label
|
||||
prepared_for_class = self._prepare_for_class(inputs_dict.copy(), model_class, return_labels=True)
|
||||
added_label = prepared_for_class[
|
||||
sorted(list(prepared_for_class.keys() - inputs_dict.keys()), reverse=True)[0]
|
||||
sorted(prepared_for_class.keys() - inputs_dict.keys(), reverse=True)[0]
|
||||
]
|
||||
expected_loss_size = added_label.shape.as_list()[:1]
|
||||
|
||||
|
||||
@@ -213,7 +213,7 @@ class LayoutLMv3ProcessorIntegrationTests(unittest.TestCase):
|
||||
|
||||
# verify keys
|
||||
expected_keys = ["attention_mask", "bbox", "input_ids", "pixel_values"]
|
||||
actual_keys = sorted(list(input_processor.keys()))
|
||||
actual_keys = sorted(input_processor.keys())
|
||||
self.assertListEqual(actual_keys, expected_keys)
|
||||
|
||||
# verify image
|
||||
@@ -235,7 +235,7 @@ class LayoutLMv3ProcessorIntegrationTests(unittest.TestCase):
|
||||
|
||||
# verify keys
|
||||
expected_keys = ["attention_mask", "bbox", "input_ids", "pixel_values"]
|
||||
actual_keys = sorted(list(input_processor.keys()))
|
||||
actual_keys = sorted(input_processor.keys())
|
||||
self.assertListEqual(actual_keys, expected_keys)
|
||||
|
||||
# verify images
|
||||
@@ -285,7 +285,7 @@ class LayoutLMv3ProcessorIntegrationTests(unittest.TestCase):
|
||||
|
||||
# verify keys
|
||||
expected_keys = ["attention_mask", "bbox", "input_ids", "pixel_values"]
|
||||
actual_keys = sorted(list(input_processor.keys()))
|
||||
actual_keys = sorted(input_processor.keys())
|
||||
self.assertListEqual(actual_keys, expected_keys)
|
||||
|
||||
# verify input_ids
|
||||
@@ -324,7 +324,7 @@ class LayoutLMv3ProcessorIntegrationTests(unittest.TestCase):
|
||||
|
||||
# verify keys
|
||||
expected_keys = ["attention_mask", "bbox", "input_ids", "labels", "pixel_values"]
|
||||
actual_keys = sorted(list(input_processor.keys()))
|
||||
actual_keys = sorted(input_processor.keys())
|
||||
self.assertListEqual(actual_keys, expected_keys)
|
||||
|
||||
# verify input_ids
|
||||
@@ -346,7 +346,7 @@ class LayoutLMv3ProcessorIntegrationTests(unittest.TestCase):
|
||||
|
||||
# verify keys
|
||||
expected_keys = ["attention_mask", "bbox", "input_ids", "labels", "pixel_values"]
|
||||
actual_keys = sorted(list(input_processor.keys()))
|
||||
actual_keys = sorted(input_processor.keys())
|
||||
self.assertListEqual(actual_keys, expected_keys)
|
||||
|
||||
# verify input_ids
|
||||
@@ -387,7 +387,7 @@ class LayoutLMv3ProcessorIntegrationTests(unittest.TestCase):
|
||||
|
||||
# verify keys
|
||||
expected_keys = ["attention_mask", "bbox", "input_ids", "pixel_values"]
|
||||
actual_keys = sorted(list(input_processor.keys()))
|
||||
actual_keys = sorted(input_processor.keys())
|
||||
self.assertListEqual(actual_keys, expected_keys)
|
||||
|
||||
# verify input_ids
|
||||
@@ -406,7 +406,7 @@ class LayoutLMv3ProcessorIntegrationTests(unittest.TestCase):
|
||||
|
||||
# verify keys
|
||||
expected_keys = ["attention_mask", "bbox", "input_ids", "pixel_values"]
|
||||
actual_keys = sorted(list(input_processor.keys()))
|
||||
actual_keys = sorted(input_processor.keys())
|
||||
self.assertListEqual(actual_keys, expected_keys)
|
||||
|
||||
# verify input_ids
|
||||
@@ -440,7 +440,7 @@ class LayoutLMv3ProcessorIntegrationTests(unittest.TestCase):
|
||||
|
||||
# verify keys
|
||||
expected_keys = ["attention_mask", "bbox", "input_ids", "pixel_values"]
|
||||
actual_keys = sorted(list(input_processor.keys()))
|
||||
actual_keys = sorted(input_processor.keys())
|
||||
self.assertListEqual(actual_keys, expected_keys)
|
||||
|
||||
# verify input_ids
|
||||
@@ -456,7 +456,7 @@ class LayoutLMv3ProcessorIntegrationTests(unittest.TestCase):
|
||||
|
||||
# verify keys
|
||||
expected_keys = ["attention_mask", "bbox", "input_ids", "pixel_values"]
|
||||
actual_keys = sorted(list(input_processor.keys()))
|
||||
actual_keys = sorted(input_processor.keys())
|
||||
self.assertListEqual(actual_keys, expected_keys)
|
||||
|
||||
# verify input_ids
|
||||
|
||||
@@ -228,7 +228,7 @@ class LayoutXLMProcessorIntegrationTests(unittest.TestCase):
|
||||
|
||||
# verify keys
|
||||
expected_keys = ["attention_mask", "bbox", "image", "input_ids"]
|
||||
actual_keys = sorted(list(input_processor.keys()))
|
||||
actual_keys = sorted(input_processor.keys())
|
||||
self.assertListEqual(actual_keys, expected_keys)
|
||||
|
||||
# verify image
|
||||
@@ -250,7 +250,7 @@ class LayoutXLMProcessorIntegrationTests(unittest.TestCase):
|
||||
|
||||
# verify keys
|
||||
expected_keys = ["attention_mask", "bbox", "image", "input_ids"]
|
||||
actual_keys = sorted(list(input_processor.keys()))
|
||||
actual_keys = sorted(input_processor.keys())
|
||||
self.assertListEqual(actual_keys, expected_keys)
|
||||
|
||||
# verify images
|
||||
@@ -300,7 +300,7 @@ class LayoutXLMProcessorIntegrationTests(unittest.TestCase):
|
||||
|
||||
# verify keys
|
||||
expected_keys = ["attention_mask", "bbox", "image", "input_ids"]
|
||||
actual_keys = sorted(list(input_processor.keys()))
|
||||
actual_keys = sorted(input_processor.keys())
|
||||
self.assertListEqual(actual_keys, expected_keys)
|
||||
|
||||
# verify input_ids
|
||||
@@ -339,7 +339,7 @@ class LayoutXLMProcessorIntegrationTests(unittest.TestCase):
|
||||
|
||||
# verify keys
|
||||
expected_keys = ["attention_mask", "bbox", "image", "input_ids", "labels"]
|
||||
actual_keys = sorted(list(input_processor.keys()))
|
||||
actual_keys = sorted(input_processor.keys())
|
||||
self.assertListEqual(actual_keys, expected_keys)
|
||||
|
||||
# verify input_ids
|
||||
@@ -361,7 +361,7 @@ class LayoutXLMProcessorIntegrationTests(unittest.TestCase):
|
||||
|
||||
# verify keys
|
||||
expected_keys = ["attention_mask", "bbox", "image", "input_ids", "labels"]
|
||||
actual_keys = sorted(list(input_processor.keys()))
|
||||
actual_keys = sorted(input_processor.keys())
|
||||
self.assertListEqual(actual_keys, expected_keys)
|
||||
|
||||
# verify input_ids
|
||||
@@ -402,7 +402,7 @@ class LayoutXLMProcessorIntegrationTests(unittest.TestCase):
|
||||
|
||||
# verify keys
|
||||
expected_keys = ["attention_mask", "bbox", "image", "input_ids"]
|
||||
actual_keys = sorted(list(input_processor.keys()))
|
||||
actual_keys = sorted(input_processor.keys())
|
||||
self.assertListEqual(actual_keys, expected_keys)
|
||||
|
||||
# verify input_ids
|
||||
@@ -421,7 +421,7 @@ class LayoutXLMProcessorIntegrationTests(unittest.TestCase):
|
||||
|
||||
# verify keys
|
||||
expected_keys = ["attention_mask", "bbox", "image", "input_ids"]
|
||||
actual_keys = sorted(list(input_processor.keys()))
|
||||
actual_keys = sorted(input_processor.keys())
|
||||
self.assertListEqual(actual_keys, expected_keys)
|
||||
|
||||
# verify input_ids
|
||||
@@ -455,7 +455,7 @@ class LayoutXLMProcessorIntegrationTests(unittest.TestCase):
|
||||
|
||||
# verify keys
|
||||
expected_keys = ["attention_mask", "bbox", "image", "input_ids"]
|
||||
actual_keys = sorted(list(input_processor.keys()))
|
||||
actual_keys = sorted(input_processor.keys())
|
||||
self.assertListEqual(actual_keys, expected_keys)
|
||||
|
||||
# verify input_ids
|
||||
@@ -471,7 +471,7 @@ class LayoutXLMProcessorIntegrationTests(unittest.TestCase):
|
||||
|
||||
# verify keys
|
||||
expected_keys = ["attention_mask", "bbox", "image", "input_ids"]
|
||||
actual_keys = sorted(list(input_processor.keys()))
|
||||
actual_keys = sorted(input_processor.keys())
|
||||
self.assertListEqual(actual_keys, expected_keys)
|
||||
|
||||
# verify input_ids
|
||||
|
||||
@@ -204,7 +204,7 @@ class MarkupLMProcessorIntegrationTests(unittest.TestCase):
|
||||
|
||||
# verify keys
|
||||
expected_keys = ["attention_mask", "input_ids", "token_type_ids", "xpath_subs_seq", "xpath_tags_seq"]
|
||||
actual_keys = sorted(list(inputs.keys()))
|
||||
actual_keys = sorted(inputs.keys())
|
||||
self.assertListEqual(actual_keys, expected_keys)
|
||||
|
||||
# verify input_ids
|
||||
@@ -216,7 +216,7 @@ class MarkupLMProcessorIntegrationTests(unittest.TestCase):
|
||||
|
||||
# verify keys
|
||||
expected_keys = ["attention_mask", "input_ids", "token_type_ids", "xpath_subs_seq", "xpath_tags_seq"]
|
||||
actual_keys = sorted(list(inputs.keys()))
|
||||
actual_keys = sorted(inputs.keys())
|
||||
self.assertListEqual(actual_keys, expected_keys)
|
||||
|
||||
# verify input_ids
|
||||
@@ -260,7 +260,7 @@ class MarkupLMProcessorIntegrationTests(unittest.TestCase):
|
||||
|
||||
# verify keys
|
||||
expected_keys = ["attention_mask", "input_ids", "token_type_ids", "xpath_subs_seq", "xpath_tags_seq"]
|
||||
actual_keys = sorted(list(inputs.keys()))
|
||||
actual_keys = sorted(inputs.keys())
|
||||
self.assertListEqual(actual_keys, expected_keys)
|
||||
|
||||
# verify input_ids
|
||||
@@ -294,7 +294,7 @@ class MarkupLMProcessorIntegrationTests(unittest.TestCase):
|
||||
"xpath_subs_seq",
|
||||
"xpath_tags_seq",
|
||||
]
|
||||
actual_keys = sorted(list(inputs.keys()))
|
||||
actual_keys = sorted(inputs.keys())
|
||||
self.assertListEqual(actual_keys, expected_keys)
|
||||
|
||||
# verify input_ids
|
||||
@@ -331,7 +331,7 @@ class MarkupLMProcessorIntegrationTests(unittest.TestCase):
|
||||
"xpath_subs_seq",
|
||||
"xpath_tags_seq",
|
||||
]
|
||||
actual_keys = sorted(list(inputs.keys()))
|
||||
actual_keys = sorted(inputs.keys())
|
||||
self.assertListEqual(actual_keys, expected_keys)
|
||||
|
||||
# verify input_ids
|
||||
@@ -367,7 +367,7 @@ class MarkupLMProcessorIntegrationTests(unittest.TestCase):
|
||||
|
||||
# verify keys
|
||||
expected_keys = ["attention_mask", "input_ids", "token_type_ids", "xpath_subs_seq", "xpath_tags_seq"]
|
||||
actual_keys = sorted(list(inputs.keys()))
|
||||
actual_keys = sorted(inputs.keys())
|
||||
self.assertListEqual(actual_keys, expected_keys)
|
||||
|
||||
# verify input_ids
|
||||
@@ -390,7 +390,7 @@ class MarkupLMProcessorIntegrationTests(unittest.TestCase):
|
||||
|
||||
# verify keys
|
||||
expected_keys = ["attention_mask", "input_ids", "token_type_ids", "xpath_subs_seq", "xpath_tags_seq"]
|
||||
actual_keys = sorted(list(inputs.keys()))
|
||||
actual_keys = sorted(inputs.keys())
|
||||
self.assertListEqual(actual_keys, expected_keys)
|
||||
|
||||
# verify input_ids
|
||||
@@ -425,7 +425,7 @@ class MarkupLMProcessorIntegrationTests(unittest.TestCase):
|
||||
|
||||
# verify keys
|
||||
expected_keys = ["attention_mask", "input_ids", "token_type_ids", "xpath_subs_seq", "xpath_tags_seq"]
|
||||
actual_keys = sorted(list(inputs.keys()))
|
||||
actual_keys = sorted(inputs.keys())
|
||||
self.assertListEqual(actual_keys, expected_keys)
|
||||
|
||||
# verify input_ids
|
||||
@@ -444,7 +444,7 @@ class MarkupLMProcessorIntegrationTests(unittest.TestCase):
|
||||
|
||||
# verify keys
|
||||
expected_keys = ["attention_mask", "input_ids", "token_type_ids", "xpath_subs_seq", "xpath_tags_seq"]
|
||||
actual_keys = sorted(list(inputs.keys()))
|
||||
actual_keys = sorted(inputs.keys())
|
||||
self.assertListEqual(actual_keys, expected_keys)
|
||||
|
||||
# verify input_ids
|
||||
|
||||
@@ -295,7 +295,7 @@ class MobileViTModelTest(TFModelTesterMixin, unittest.TestCase):
|
||||
# The number of elements in the loss should be the same as the number of elements in the label
|
||||
prepared_for_class = self._prepare_for_class(inputs_dict.copy(), model_class, return_labels=True)
|
||||
added_label = prepared_for_class[
|
||||
sorted(list(prepared_for_class.keys() - inputs_dict.keys()), reverse=True)[0]
|
||||
sorted(prepared_for_class.keys() - inputs_dict.keys(), reverse=True)[0]
|
||||
]
|
||||
expected_loss_size = added_label.shape.as_list()[:1]
|
||||
|
||||
|
||||
@@ -166,9 +166,11 @@ class PerceiverModelTester:
|
||||
audio = torch.randn(
|
||||
(self.batch_size, self.num_frames * self.audio_samples_per_frame, 1), device=torch_device
|
||||
)
|
||||
inputs = dict(
|
||||
image=images, audio=audio, label=torch.zeros((self.batch_size, self.num_labels), device=torch_device)
|
||||
)
|
||||
inputs = {
|
||||
"image": images,
|
||||
"audio": audio,
|
||||
"label": torch.zeros((self.batch_size, self.num_labels), device=torch_device),
|
||||
}
|
||||
else:
|
||||
raise ValueError(f"Model class {model_class} not supported")
|
||||
|
||||
@@ -734,7 +736,7 @@ class PerceiverModelTest(ModelTesterMixin, unittest.TestCase):
|
||||
continue
|
||||
|
||||
config, inputs, input_mask, _, _ = self.model_tester.prepare_config_and_inputs(model_class=model_class)
|
||||
inputs_dict = dict(inputs=inputs, attention_mask=input_mask)
|
||||
inputs_dict = {"inputs": inputs, "attention_mask": input_mask}
|
||||
|
||||
for problem_type in problem_types:
|
||||
with self.subTest(msg=f"Testing {model_class} with {problem_type['title']}"):
|
||||
|
||||
@@ -44,8 +44,8 @@ class BertTokenizationTest(TokenizerTesterMixin, unittest.TestCase):
|
||||
super().setUp()
|
||||
|
||||
vocab_tokens = ["[UNK]", "[CLS]", "[SEP]", "[PAD]", "[MASK]", "你", "好", "是", "谁", "a", "b", "c", "d"]
|
||||
word_shape = dict()
|
||||
word_pronunciation = dict()
|
||||
word_shape = {}
|
||||
word_pronunciation = {}
|
||||
for i, value in enumerate(vocab_tokens):
|
||||
word_shape[value] = i
|
||||
word_pronunciation[value] = i
|
||||
|
||||
@@ -362,9 +362,7 @@ class TFSegformerModelTest(TFModelTesterMixin, unittest.TestCase):
|
||||
_, prepared_for_class = self.model_tester.prepare_config_and_inputs_for_keras_fit(
|
||||
for_segmentation=for_segmentation
|
||||
)
|
||||
added_label = prepared_for_class[
|
||||
sorted(list(prepared_for_class.keys() - inputs_dict.keys()), reverse=True)[0]
|
||||
]
|
||||
added_label = prepared_for_class[sorted(prepared_for_class.keys() - inputs_dict.keys(), reverse=True)[0]]
|
||||
loss_size = tf.size(added_label)
|
||||
|
||||
# Test that model correctly compute the loss with kwargs
|
||||
|
||||
@@ -372,7 +372,7 @@ class SpeechT5FeatureExtractionTest(SequenceFeatureExtractionTestMixin, unittest
|
||||
)
|
||||
self.assertIn("attention_mask", processed_pad)
|
||||
self.assertListEqual(
|
||||
list(processed_pad.attention_mask.shape), list((processed_pad[input_name].shape[0], max_length))
|
||||
list(processed_pad.attention_mask.shape), [processed_pad[input_name].shape[0], max_length]
|
||||
)
|
||||
self.assertListEqual(
|
||||
processed_pad.attention_mask[:, :max_length].sum(-1).tolist(), [max_length for x in speech_inputs]
|
||||
|
||||
@@ -387,7 +387,7 @@ class T5TokenizationTest(TokenizerTesterMixin, unittest.TestCase):
|
||||
|
||||
def test_get_sentinel_token_ids(self):
|
||||
tokenizer = T5Tokenizer(SAMPLE_VOCAB, extra_ids=10)
|
||||
self.assertListEqual(sorted(tokenizer.get_sentinel_token_ids()), sorted([i for i in range(1000, 1010)]))
|
||||
self.assertListEqual(sorted(tokenizer.get_sentinel_token_ids()), sorted(range(1000, 1010)))
|
||||
|
||||
def test_get_sentinel_tokens_for_fasttokenizer(self):
|
||||
tokenizer = T5TokenizerFast(SAMPLE_VOCAB, extra_ids=10)
|
||||
@@ -398,4 +398,4 @@ class T5TokenizationTest(TokenizerTesterMixin, unittest.TestCase):
|
||||
|
||||
def test_get_sentinel_token_ids_for_fasttokenizer(self):
|
||||
tokenizer = T5TokenizerFast(SAMPLE_VOCAB, extra_ids=10)
|
||||
self.assertListEqual(sorted(tokenizer.get_sentinel_token_ids()), sorted([i for i in range(1000, 1010)]))
|
||||
self.assertListEqual(sorted(tokenizer.get_sentinel_token_ids()), sorted(range(1000, 1010)))
|
||||
|
||||
@@ -347,7 +347,7 @@ class TransfoXLModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestC
|
||||
# Retrieve the cutoffs and copy them
|
||||
copied_cutoffs = copy.copy(model_embed.cutoffs)
|
||||
|
||||
test_layers = [x for x in range(config.div_val)]
|
||||
test_layers = list(range(config.div_val))
|
||||
for layer in test_layers:
|
||||
# Check that resizing the token embeddings with a larger vocab size increases the model's vocab size
|
||||
model_embed = model.resize_token_embeddings(model_vocab_size + 10, layer)
|
||||
|
||||
@@ -581,7 +581,7 @@ class TvltModelIntegrationTest(unittest.TestCase):
|
||||
audio = prepare_audio()
|
||||
video_inputs = image_processor(video, return_tensors="pt").to(torch_device)
|
||||
audio_inputs = audio_feature_extractor(audio, return_tensors="pt").to(torch_device)
|
||||
inputs = dict()
|
||||
inputs = {}
|
||||
inputs.update(video_inputs)
|
||||
inputs.update(audio_inputs)
|
||||
|
||||
@@ -606,7 +606,7 @@ class TvltModelIntegrationTest(unittest.TestCase):
|
||||
video_mixed_inputs = image_processor(video_mixed, is_mixed=True, return_tensors="pt").to(torch_device)
|
||||
audio_inputs = audio_feature_extractor(audio, return_tensors="pt", mask_audio=True).to(torch_device)
|
||||
labels = torch.tensor([[0.0]], device=torch_device)
|
||||
inputs = dict()
|
||||
inputs = {}
|
||||
inputs.update(video_inputs)
|
||||
inputs.update(video_mixed_inputs)
|
||||
inputs.update(audio_inputs)
|
||||
|
||||
@@ -333,7 +333,7 @@ class TFViTMAEModelTest(TFModelTesterMixin, unittest.TestCase):
|
||||
|
||||
config, inputs_dict = self.model_tester.prepare_config_and_inputs_for_common()
|
||||
|
||||
tf_main_layer_classes = set(
|
||||
tf_main_layer_classes = {
|
||||
module_member
|
||||
for model_class in self.all_model_classes
|
||||
for module in (import_module(model_class.__module__),)
|
||||
@@ -345,7 +345,7 @@ class TFViTMAEModelTest(TFModelTesterMixin, unittest.TestCase):
|
||||
if isinstance(module_member, type)
|
||||
and tf.keras.layers.Layer in module_member.__bases__
|
||||
and getattr(module_member, "_keras_serializable", False)
|
||||
)
|
||||
}
|
||||
|
||||
num_patches = int((config.image_size // config.patch_size) ** 2)
|
||||
noise = np.random.uniform(size=(self.model_tester.batch_size, num_patches))
|
||||
|
||||
@@ -231,7 +231,7 @@ class Wav2Vec2TokenizerTest(unittest.TestCase):
|
||||
tokenizer_files = tokenizer.save_pretrained(tmpdirname2)
|
||||
self.assertSequenceEqual(
|
||||
sorted(tuple(VOCAB_FILES_NAMES.values()) + ("special_tokens_map.json", "added_tokens.json")),
|
||||
sorted(tuple(x.split(os.path.sep)[-1] for x in tokenizer_files)),
|
||||
sorted(x.split(os.path.sep)[-1] for x in tokenizer_files),
|
||||
)
|
||||
|
||||
# Checks everything loads correctly in the same way
|
||||
@@ -456,7 +456,7 @@ class Wav2Vec2CTCTokenizerTest(TokenizerTesterMixin, unittest.TestCase):
|
||||
def test_special_characters_in_vocab(self):
|
||||
sent = "ʈʰ æ æ̃ ˧ kʰ"
|
||||
|
||||
vocab_dict = {k: v for v, k in enumerate({phoneme for phoneme in sent.split()})}
|
||||
vocab_dict = {k: v for v, k in enumerate(set(sent.split()))}
|
||||
vocab_file = os.path.join(self.tmpdirname, "vocab_special.json")
|
||||
|
||||
with open(vocab_file, "w") as f:
|
||||
|
||||
@@ -215,7 +215,7 @@ class Wav2Vec2ProcessorWithLMTest(unittest.TestCase):
|
||||
with get_context(pool_context).Pool() as pool:
|
||||
decoded_processor = processor.batch_decode(logits, pool)
|
||||
|
||||
logits_list = [array for array in logits]
|
||||
logits_list = list(logits)
|
||||
|
||||
with get_context("fork").Pool() as p:
|
||||
decoded_beams = decoder.decode_beams_batch(p, logits_list)
|
||||
@@ -252,7 +252,7 @@ class Wav2Vec2ProcessorWithLMTest(unittest.TestCase):
|
||||
)
|
||||
decoded_processor = decoded_processor_out.text
|
||||
|
||||
logits_list = [array for array in logits]
|
||||
logits_list = list(logits)
|
||||
|
||||
with get_context("fork").Pool() as pool:
|
||||
decoded_decoder_out = decoder.decode_beams_batch(
|
||||
@@ -299,7 +299,7 @@ class Wav2Vec2ProcessorWithLMTest(unittest.TestCase):
|
||||
)
|
||||
decoded_processor = decoded_processor_out.text
|
||||
|
||||
logits_list = [array for array in logits]
|
||||
logits_list = list(logits)
|
||||
decoder.reset_params(
|
||||
alpha=alpha,
|
||||
beta=beta,
|
||||
|
||||
@@ -400,7 +400,7 @@ class TFXLNetModelTest(TFModelTesterMixin, unittest.TestCase):
|
||||
# The number of elements in the loss should be the same as the number of elements in the label
|
||||
prepared_for_class = self._prepare_for_class(inputs_dict.copy(), model_class, return_labels=True)
|
||||
added_label = prepared_for_class[
|
||||
sorted(list(prepared_for_class.keys() - inputs_dict.keys()), reverse=True)[0]
|
||||
sorted(prepared_for_class.keys() - inputs_dict.keys(), reverse=True)[0]
|
||||
]
|
||||
expected_loss_size = added_label.shape.as_list()[:1]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user