Skip to content

Commit 555693f

Browse files
authored
fix mpt test of different outputs from cuda (#37691)
* fix mpt test Signed-off-by: jiqing-feng <[email protected]> * fix mpt tests with Expectations Signed-off-by: jiqing-feng <[email protected]> * fix typo Signed-off-by: jiqing-feng <[email protected]> * fix output Signed-off-by: jiqing-feng <[email protected]> * fix format Signed-off-by: jiqing-feng <[email protected]> --------- Signed-off-by: jiqing-feng <[email protected]>
1 parent 0cfbf9c commit 555693f

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

tests/models/mpt/test_modeling_mpt.py

+15-4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from transformers.testing_utils import (
2121
Expectations,
2222
require_bitsandbytes,
23+
require_deterministic_for_xpu,
2324
require_torch,
2425
require_torch_accelerator,
2526
slow,
@@ -483,6 +484,7 @@ def test_generation(self):
483484
decoded_output = tokenizer.decode(outputs[0], skip_special_tokens=True)
484485
self.assertEqual(decoded_output, expected_output)
485486

487+
@require_deterministic_for_xpu
486488
def test_generation_batched(self):
487489
model_id = "mosaicml/mpt-7b"
488490
tokenizer = AutoTokenizer.from_pretrained(model_id)
@@ -498,10 +500,19 @@ def test_generation_batched(self):
498500

499501
inputs = tokenizer(input_texts, return_tensors="pt", padding=True).to(torch_device)
500502

501-
expected_output = [
502-
"Hello my name is Tiffany and I am a mother of two beautiful children. I have been a nanny for the",
503-
"Today I am going at the gym and then I am going to go to the grocery store. I am going to buy some food and some",
504-
]
503+
expected_outputs = Expectations(
504+
{
505+
("xpu", 3): [
506+
"Hello my name is Tiffany. I am a mother of two beautiful children. I have been a nanny for over",
507+
"Today I am going at the gym and then I am going to go to the mall with my mom. I am going to go to the",
508+
],
509+
("cuda", 7): [
510+
"Hello my name is Tiffany and I am a mother of two beautiful children. I have been a nanny for the",
511+
"Today I am going at the gym and then I am going to go to the grocery store. I am going to buy some food and some",
512+
],
513+
}
514+
)
515+
expected_output = expected_outputs.get_expectation()
505516
outputs = model.generate(**inputs, max_new_tokens=20)
506517

507518
decoded_outputs = tokenizer.batch_decode(outputs, skip_special_tokens=True)

0 commit comments

Comments
 (0)