20
20
from transformers .testing_utils import (
21
21
Expectations ,
22
22
require_bitsandbytes ,
23
+ require_deterministic_for_xpu ,
23
24
require_torch ,
24
25
require_torch_accelerator ,
25
26
slow ,
@@ -483,6 +484,7 @@ def test_generation(self):
483
484
decoded_output = tokenizer .decode (outputs [0 ], skip_special_tokens = True )
484
485
self .assertEqual (decoded_output , expected_output )
485
486
487
+ @require_deterministic_for_xpu
486
488
def test_generation_batched (self ):
487
489
model_id = "mosaicml/mpt-7b"
488
490
tokenizer = AutoTokenizer .from_pretrained (model_id )
@@ -498,10 +500,19 @@ def test_generation_batched(self):
498
500
499
501
inputs = tokenizer (input_texts , return_tensors = "pt" , padding = True ).to (torch_device )
500
502
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 ()
505
516
outputs = model .generate (** inputs , max_new_tokens = 20 )
506
517
507
518
decoded_outputs = tokenizer .batch_decode (outputs , skip_special_tokens = True )
0 commit comments