Skip to content

Commit d8b4a24

Browse files
committed
fix
1 parent 2166b6b commit d8b4a24

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

tests/models/mistral3/test_modeling_mistral3.py

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ def setUp(self):
297297
cleanup(torch_device, gc_collect=True)
298298
self.model_checkpoint = "mistralai/Mistral-Small-3.1-24B-Instruct-2503"
299299
self.model = Mistral3ForConditionalGeneration.from_pretrained(
300-
self.model_checkpoint, torch_dtype=torch.bfloat16
300+
self.model_checkpoint, torch_dtype=torch.float16
301301
)
302302
accelerate.cpu_offload(self.model, execution_device=torch_device)
303303

@@ -319,7 +319,7 @@ def test_mistral3_integration_generate_text_only(self):
319319

320320
inputs = processor.apply_chat_template(
321321
messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt"
322-
).to(torch_device, dtype=torch.bfloat16)
322+
).to(torch_device, dtype=torch.float16)
323323

324324
with torch.no_grad():
325325
generate_ids = self.model.generate(**inputs, max_new_tokens=200, do_sample=False)
@@ -351,7 +351,7 @@ def test_mistral3_integration_generate(self):
351351

352352
inputs = processor.apply_chat_template(
353353
messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt"
354-
).to(torch_device, dtype=torch.bfloat16)
354+
).to(torch_device, dtype=torch.float16)
355355
with torch.no_grad():
356356
generate_ids = self.model.generate(**inputs, max_new_tokens=20, do_sample=False)
357357
decoded_output = processor.decode(
@@ -361,8 +361,8 @@ def test_mistral3_integration_generate(self):
361361
expected_outputs = Expectations(
362362
{
363363
("xpu", 3): "The image features two cats resting on a pink blanket. The cat on the left is a kitten",
364-
("cuda", 7): "The image features two cats resting on a pink blanket. The cat on the left is a kitten",
365-
("cuda", 8): "The image features two cats resting on a pink blanket. The cat on the left is a small kit",
364+
("cuda", 7): 'The image features two tabby cats lying on a pink surface, which appears to be a couch or',
365+
("cuda", 8): 'The image features two cats lying on a pink surface, which appears to be a couch or a bed',
366366
}
367367
) # fmt: skip
368368
expected_output = expected_outputs.get_expectation()
@@ -378,7 +378,10 @@ def test_mistral3_integration_batched_generate(self):
378378
{
379379
"role": "user",
380380
"content": [
381-
{"type": "image", "url": "https://huggingface.co/ydshieh/kosmos-2.5/resolve/main/view.jpg"},
381+
{
382+
"type": "image",
383+
"url": "https://huggingface.co/datasets/hf-internal-testing/testing-data-mistral3/resolve/main/view.jpg",
384+
},
382385
{"type": "text", "text": "Write a haiku for this image"},
383386
],
384387
},
@@ -396,7 +399,7 @@ def test_mistral3_integration_batched_generate(self):
396399

397400
inputs = processor.apply_chat_template(
398401
messages, padding=True, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt"
399-
).to(torch_device, dtype=torch.bfloat16)
402+
).to(torch_device, dtype=torch.float16)
400403

401404
output = self.model.generate(**inputs, do_sample=False, max_new_tokens=25)
402405

@@ -408,8 +411,8 @@ def test_mistral3_integration_batched_generate(self):
408411
expected_outputs = Expectations(
409412
{
410413
("xpu", 3): "Calm lake's mirror gleams,\nWhispering pines stand in silence,\nPath to peace begins.",
411-
("cuda", 7): "Calm waters reflect\nWhispering pines stand in silence\nPath to peace begins",
412-
("cuda", 8): "Calm waters reflect\nWhispering pines stand in silence\nPath to peace begins",
414+
("cuda", 7): 'Calm waters reflect\nWooden path to distant shore\nSilence in the woods',
415+
("cuda", 8): "Wooden path to calm,\nReflections whisper secrets,\nNature's peace unfolds.",
413416
}
414417
) # fmt: skip
415418
expected_output = expected_outputs.get_expectation()
@@ -424,8 +427,8 @@ def test_mistral3_integration_batched_generate(self):
424427
expected_outputs = Expectations(
425428
{
426429
("xpu", 3): "The image depicts a vibrant urban scene in what appears to be Chinatown. The focal point is a traditional Chinese archway",
427-
("cuda", 7): 'The image depicts a vibrant street scene in Chinatown, likely in a major city. The focal point is a traditional Chinese',
428-
("cuda", 8): 'The image depicts a vibrant street scene in what appears to be Chinatown in a major city. The focal point is a',
430+
("cuda", 7): 'The image depicts a street scene in what appears to be a Chinatown district. The focal point is a traditional Chinese arch',
431+
("cuda", 8): 'The image depicts a street scene in what appears to be a Chinatown district. The focal point is a traditional Chinese arch',
429432
}
430433
) # fmt: skip
431434
expected_output = expected_outputs.get_expectation()
@@ -446,7 +449,10 @@ def test_mistral3_integration_batched_generate_multi_image(self):
446449
{
447450
"role": "user",
448451
"content": [
449-
{"type": "image", "url": "https://huggingface.co/ydshieh/kosmos-2.5/resolve/main/view.jpg"},
452+
{
453+
"type": "image",
454+
"url": "https://huggingface.co/datasets/hf-internal-testing/testing-data-mistral3/resolve/main/view.jpg",
455+
},
450456
{"type": "text", "text": "Write a haiku for this image"},
451457
],
452458
},
@@ -457,11 +463,11 @@ def test_mistral3_integration_batched_generate_multi_image(self):
457463
"content": [
458464
{
459465
"type": "image",
460-
"url": "https://huggingface.co/ydshieh/kosmos-2.5/resolve/main/Statue-of-Liberty-Island-New-York-Bay.jpg",
466+
"url": "https://huggingface.co/datasets/hf-internal-testing/testing-data-mistral3/resolve/main/Statue-of-Liberty-Island-New-York-Bay.jpg",
461467
},
462468
{
463469
"type": "image",
464-
"url": "https://huggingface.co/ydshieh/kosmos-2.5/resolve/main/golden-gate-bridge-san-francisco-purple-flowers-california-echium-candicans-36805947.jpg",
470+
"url": "https://huggingface.co/datasets/hf-internal-testing/testing-data-mistral3/resolve/main/golden-gate-bridge-san-francisco-purple-flowers-california-echium-candicans-36805947.jpg",
465471
},
466472
{
467473
"type": "text",
@@ -473,7 +479,7 @@ def test_mistral3_integration_batched_generate_multi_image(self):
473479
]
474480
inputs = processor.apply_chat_template(
475481
messages, padding=True, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt"
476-
).to(torch_device, dtype=torch.bfloat16)
482+
).to(torch_device, dtype=torch.float16)
477483

478484
output = self.model.generate(**inputs, do_sample=False, max_new_tokens=25)
479485
gen_tokens = output[:, inputs["input_ids"].shape[1] :]
@@ -483,8 +489,8 @@ def test_mistral3_integration_batched_generate_multi_image(self):
483489
expected_outputs = Expectations(
484490
{
485491
("xpu", 3): "Still lake reflects skies,\nWooden path to nature's heart,\nSilence speaks volumes.",
486-
("cuda", 7): "Calm waters reflect\nWhispering pines stand in silence\nPath to peace begins",
487-
("cuda", 8): "Calm waters reflect\nWhispering pines stand in silence\nPath to peace begins",
492+
("cuda", 7): 'Calm waters reflect\nWooden path to distant shore\nSilence in the pines',
493+
("cuda", 8): 'Calm waters reflect\nWooden path to distant shore\nSilence in the pines',
488494
}
489495
) # fmt: skip
490496
expected_output = expected_outputs.get_expectation()
@@ -499,8 +505,8 @@ def test_mistral3_integration_batched_generate_multi_image(self):
499505
expected_outputs = Expectations(
500506
{
501507
("xpu", 3): "Certainly! The images depict two iconic landmarks:\n\n1. The first image shows the Statue of Liberty in New York City.",
502-
("cuda", 7): "Certainly! The images depict the following landmarks:\n\n1. The first image shows the Statue of Liberty and the New York City",
503-
("cuda", 8): "Certainly! The images depict the following landmarks:\n\n1. The first image shows the Statue of Liberty and the New York City",
508+
("cuda", 7): 'Certainly! The images depict two famous landmarks in the United States:\n\n1. The first image shows the Statue of Liberty,',
509+
("cuda", 8): 'Certainly! The images depict two famous landmarks in the United States:\n\n1. The first image shows the Statue of Liberty,',
504510
}
505511
) # fmt: skip
506512
expected_output = expected_outputs.get_expectation()

0 commit comments

Comments
 (0)