Skip to content

Commit d1808f2

Browse files
[ci] Fixing some failing tests for important models (#43231)
* fix gpt2 tests * use_safetensors=False for facebook/detr-resnet-50 * use @require_read_token decorator for LlamaTokenizationTest * update an expected_output * style * fix an expectation * remove @require_read_token decorator, smoother process is coming in #43233
1 parent 3d27645 commit d1808f2

4 files changed

Lines changed: 15 additions & 15 deletions

File tree

tests/models/detr/test_modeling_detr.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,9 @@ def default_image_processor(self):
748748
)
749749

750750
def test_inference_no_head(self):
751-
model = DetrModel.from_pretrained("facebook/detr-resnet-50", revision="no_timm").to(torch_device)
751+
model = DetrModel.from_pretrained("facebook/detr-resnet-50", revision="no_timm", use_safetensors=False).to(
752+
torch_device
753+
)
752754

753755
image_processor = self.default_image_processor
754756
image = prepare_img()

tests/models/gpt2/test_modeling_gpt2.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ def test_batch_generation(self):
461461
tokenizer = GPT2Tokenizer.from_pretrained("openai-community/gpt2")
462462

463463
tokenizer.padding_side = "left"
464+
max_length = 20
464465

465466
# Define PAD Token = EOS Token = 50256
466467
tokenizer.pad_token = tokenizer.eos_token
@@ -485,24 +486,22 @@ def test_batch_generation(self):
485486
outputs = model.generate(
486487
input_ids=input_ids,
487488
attention_mask=inputs["attention_mask"].to(torch_device),
488-
max_length=20,
489+
max_length=max_length,
489490
)
490491

491492
outputs_tt = model.generate(
492493
input_ids=input_ids,
493494
attention_mask=inputs["attention_mask"].to(torch_device),
494495
token_type_ids=token_type_ids,
495-
max_length=20,
496+
max_length=max_length,
496497
)
497498

498499
inputs_non_padded = tokenizer(sentences[0], return_tensors="pt").input_ids.to(torch_device)
499-
output_non_padded = model.generate(input_ids=inputs_non_padded, max_length=20)
500+
output_non_padded = model.generate(input_ids=inputs_non_padded, max_length=max_length)
500501

501502
num_paddings = inputs_non_padded.shape[-1] - inputs["attention_mask"][-1].long().sum().item()
502503
inputs_padded = tokenizer(sentences[1], return_tensors="pt").input_ids.to(torch_device)
503-
output_padded = model.generate(
504-
input_ids=inputs_padded, max_length=model.generation_config.max_length - num_paddings
505-
)
504+
output_padded = model.generate(input_ids=inputs_padded, max_length=max_length - num_paddings)
506505

507506
batch_out_sentence = tokenizer.batch_decode(outputs, skip_special_tokens=True)
508507
batch_out_sentence_tt = tokenizer.batch_decode(outputs_tt, skip_special_tokens=True)
@@ -524,6 +523,7 @@ def test_batch_generation_2heads(self):
524523
tokenizer = GPT2Tokenizer.from_pretrained("openai-community/gpt2")
525524

526525
tokenizer.padding_side = "left"
526+
max_length = 20
527527

528528
# This tokenizer has no pad token, so we have to set it in some way
529529
# Define PAD Token = EOS Token = 50256
@@ -549,24 +549,22 @@ def test_batch_generation_2heads(self):
549549
outputs = model.generate(
550550
input_ids=input_ids,
551551
attention_mask=inputs["attention_mask"].to(torch_device),
552-
max_length=20,
552+
max_length=max_length,
553553
)
554554

555555
outputs_tt = model.generate(
556556
input_ids=input_ids,
557557
attention_mask=inputs["attention_mask"].to(torch_device),
558558
token_type_ids=token_type_ids,
559-
max_length=20,
559+
max_length=max_length,
560560
)
561561

562562
inputs_non_padded = tokenizer(sentences[0], return_tensors="pt").input_ids.to(torch_device)
563-
output_non_padded = model.generate(input_ids=inputs_non_padded, max_length=20)
563+
output_non_padded = model.generate(input_ids=inputs_non_padded, max_length=max_length)
564564

565565
num_paddings = inputs_non_padded.shape[-1] - inputs["attention_mask"][-1].long().sum().item()
566566
inputs_padded = tokenizer(sentences[1], return_tensors="pt").input_ids.to(torch_device)
567-
output_padded = model.generate(
568-
input_ids=inputs_padded, max_length=model.generation_config.max_length - num_paddings
569-
)
567+
output_padded = model.generate(input_ids=inputs_padded, max_length=max_length - num_paddings)
570568

571569
batch_out_sentence = tokenizer.batch_decode(outputs, skip_special_tokens=True)
572570
batch_out_sentence_tt = tokenizer.batch_decode(outputs_tt, skip_special_tokens=True)

tests/models/llava/test_modeling_llava.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ def test_tokenizer_integration(self):
585585
fast_tokenizer.add_tokens("<image>", True)
586586

587587
prompt = "<|im_start|>system\nAnswer the questions.<|im_end|><|im_start|>user\n<image>\nWhat is shown in this image?<|im_end|><|im_start|>assistant\n"
588-
EXPECTED_OUTPUT = ['<|im_start|>', 'system', '\n', 'Answer', 'the', '▁questions', '.', '<|im_end|>', '<|im_start|>', 'user', '\n', '<image>', '\n', 'What', 'is', '▁shown', 'in', '▁this', '▁image', '?', '<|im_end|>', '<|im_start|>', 'ass', 'istant', '\n'] # fmt: skip
588+
EXPECTED_OUTPUT = ['<|im_start|>', 'sy', 'st', 'em', '\n', 'An', 'sw', 'er', ' ', 'the', ' ', 'qu', 'est', 'ions', '.', '<|im_end|>', '<|im_start|>', 'us', 'er', '\n', '<image>', '\n', 'What', ' ', 'is', ' ', 'sh', 'own', ' ', 'in', ' ', 'th', 'is', ' ', 'im', 'age', '?', '<|im_end|>', '<|im_start|>', 'ass', 'ist', 'ant', '\n'] # fmt: skip
589589
self.assertEqual(slow_tokenizer.tokenize(prompt), EXPECTED_OUTPUT)
590590
self.assertEqual(fast_tokenizer.tokenize(prompt), EXPECTED_OUTPUT)
591591

tests/models/qwen2_5_omni/test_modeling_qwen2_5_omni.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ def test_small_model_integration_test_batch(self):
723723
"system\nYou are a helpful assistant.\nuser\nWhat's that sound and what kind of dog is this?\nassistant\nThe sound is a glass shattering. The dog in the picture is a Labrador Retriever.",
724724
],
725725
("rocm", (9, 4)): [
726-
"system\nYou are a helpful assistant.\nuser\nWhat's that sound and what kind of dog is this?\nassistant\nThe sound is a glass shattering. The dog in the picture is a Labrador Retriever.",
726+
"system\nYou are a helpful assistant.\nuser\nWhat's that sound and what kind of dog is this?\nassistant\nThe sound is glass shattering, and the dog is a Labrador Retriever.",
727727
"system\nYou are a helpful assistant.\nuser\nWhat's that sound and what kind of dog is this?\nassistant\nThe sound is glass shattering, and the dog is a Labrador Retriever.",
728728
],
729729
}

0 commit comments

Comments
 (0)