





"""simple docstring"""
import inspect
import unittest

from transformers import MobileViTConfig
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
  import torch

  from transformers import MobileViTForImageClassification, MobileViTForSemanticSegmentation, MobileViTModel
  from transformers.models.mobilevit.modeling_mobilevit import MOBILEVIT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
  from PIL import Image

  from transformers import MobileViTImageProcessor






class 					_SCREAMING_SNAKE_CASE(   UpperCAmelCase_  ):




       def     _UpperCamelCase     (						self							)			->      Any:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE   :Optional[Any]						=  self.config_class(**self.inputs_dict							)
             self.parent.assertTrue(hasattr(lowerCAmelCase__		,'''hidden_sizes'''							)							)
             self.parent.assertTrue(hasattr(lowerCAmelCase__		,'''neck_hidden_sizes'''							)							)
             self.parent.assertTrue(hasattr(lowerCAmelCase__		,'''num_attention_heads'''							)							)






class 					_SCREAMING_SNAKE_CASE:




       def __init__(						self		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__=13		,SCREAMING_SNAKE_CASE__=32		,SCREAMING_SNAKE_CASE__=2		,SCREAMING_SNAKE_CASE__=3		,SCREAMING_SNAKE_CASE__=6_40		,SCREAMING_SNAKE_CASE__=4		,SCREAMING_SNAKE_CASE__="silu"		,SCREAMING_SNAKE_CASE__=3		,SCREAMING_SNAKE_CASE__=32		,SCREAMING_SNAKE_CASE__=0.1		,SCREAMING_SNAKE_CASE__=0.1		,SCREAMING_SNAKE_CASE__=0.1		,SCREAMING_SNAKE_CASE__=0.0_2		,SCREAMING_SNAKE_CASE__=True		,SCREAMING_SNAKE_CASE__=True		,SCREAMING_SNAKE_CASE__=10		,SCREAMING_SNAKE_CASE__=None		,)			->      int:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE   :Any						=  parent
             __SCREAMING_SNAKE_CASE   :List[Any]						=  batch_size
             __SCREAMING_SNAKE_CASE   :Tuple						=  image_size
             __SCREAMING_SNAKE_CASE   :Tuple						=  patch_size
             __SCREAMING_SNAKE_CASE   :List[Any]						=  num_channels
             __SCREAMING_SNAKE_CASE   :str						=  last_hidden_size
             __SCREAMING_SNAKE_CASE   :List[Any]						=  num_attention_heads
             __SCREAMING_SNAKE_CASE   :Dict						=  hidden_act
             __SCREAMING_SNAKE_CASE   :Optional[Any]						=  conv_kernel_size
             __SCREAMING_SNAKE_CASE   :str						=  output_stride
             __SCREAMING_SNAKE_CASE   :Any						=  hidden_dropout_prob
             __SCREAMING_SNAKE_CASE   :Dict						=  attention_probs_dropout_prob
             __SCREAMING_SNAKE_CASE   :int						=  classifier_dropout_prob
             __SCREAMING_SNAKE_CASE   :Union[str, Any]						=  use_labels
             __SCREAMING_SNAKE_CASE   :Union[str, Any]						=  is_training
             __SCREAMING_SNAKE_CASE   :Any						=  num_labels
             __SCREAMING_SNAKE_CASE   :Tuple						=  initializer_range
             __SCREAMING_SNAKE_CASE   :List[str]						=  scope




       def     _UpperCamelCase     (						self							)			->      int:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE   :int						=  floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]							)

             __SCREAMING_SNAKE_CASE   :List[str]						=  None
             __SCREAMING_SNAKE_CASE   :List[Any]						=  None
             if self.use_labels:
                   __SCREAMING_SNAKE_CASE   :str						=  ids_tensor([self.batch_size]		,self.num_labels							)
                   __SCREAMING_SNAKE_CASE   :Tuple						=  ids_tensor([self.batch_size, self.image_size, self.image_size]		,self.num_labels							)

             __SCREAMING_SNAKE_CASE   :List[Any]						=  self.get_config()

             return config, pixel_values, labels, pixel_labels




       def     _UpperCamelCase     (						self							)			->      List[Any]:





             """simple docstring"""






             return MobileViTConfig(
                 image_size=self.image_size		,patch_size=self.patch_size		,num_channels=self.num_channels		,num_attention_heads=self.num_attention_heads		,hidden_act=self.hidden_act		,conv_kernel_size=self.conv_kernel_size		,output_stride=self.output_stride		,hidden_dropout_prob=self.hidden_dropout_prob		,attention_probs_dropout_prob=self.attention_probs_dropout_prob		,classifier_dropout_prob=self.classifier_dropout_prob		,initializer_range=self.initializer_range		,)




       def     _UpperCamelCase     (						self		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							)			->      Dict:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE   :List[Any]						=  MobileViTModel(config=lowerCAmelCase__							)
             model.to(lowerCAmelCase__							)
             model.eval()
             __SCREAMING_SNAKE_CASE   :Tuple						=  model(lowerCAmelCase__							)
             self.parent.assertEqual(
                 result.last_hidden_state.shape		,(
                     self.batch_size,
                     self.last_hidden_size,
                     self.image_size // self.output_stride,
                     self.image_size // self.output_stride,
                 )		,)




       def     _UpperCamelCase     (						self		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							)			->      List[str]:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE   :List[Any]						=  self.num_labels
             __SCREAMING_SNAKE_CASE   :str						=  MobileViTForImageClassification(lowerCAmelCase__							)
             model.to(lowerCAmelCase__							)
             model.eval()
             __SCREAMING_SNAKE_CASE   :Dict						=  model(lowerCAmelCase__		,labels=lowerCAmelCase__							)
             self.parent.assertEqual(result.logits.shape		,(self.batch_size, self.num_labels)							)




       def     _UpperCamelCase     (						self		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							)			->      Optional[int]:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE   :Any						=  self.num_labels
             __SCREAMING_SNAKE_CASE   :List[Any]						=  MobileViTForSemanticSegmentation(lowerCAmelCase__							)
             model.to(lowerCAmelCase__							)
             model.eval()
             __SCREAMING_SNAKE_CASE   :Union[str, Any]						=  model(lowerCAmelCase__							)
             self.parent.assertEqual(
                 result.logits.shape		,(
                     self.batch_size,
                     self.num_labels,
                     self.image_size // self.output_stride,
                     self.image_size // self.output_stride,
                 )		,)
             __SCREAMING_SNAKE_CASE   :List[str]						=  model(lowerCAmelCase__		,labels=lowerCAmelCase__							)
             self.parent.assertEqual(
                 result.logits.shape		,(
                     self.batch_size,
                     self.num_labels,
                     self.image_size // self.output_stride,
                     self.image_size // self.output_stride,
                 )		,)




       def     _UpperCamelCase     (						self							)			->      Dict:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE   :List[str]						=  self.prepare_config_and_inputs()
             __SCREAMING_SNAKE_CASE   :Any						=  config_and_inputs
             __SCREAMING_SNAKE_CASE   :int						=  {"pixel_values": pixel_values}
             return config, inputs_dict






@require_torch
class 					_SCREAMING_SNAKE_CASE(   UpperCAmelCase_    ,	UpperCAmelCase_    ,	unittest.TestCase  ):
       SCREAMING_SNAKE_CASE_   :      Union[str, Any]							=  (
           (MobileViTModel, MobileViTForImageClassification, MobileViTForSemanticSegmentation)
           if is_torch_available()
           else ()
       )
       SCREAMING_SNAKE_CASE_   :      str							=  (
           {
               '''feature-extraction''': MobileViTModel,
               '''image-classification''': MobileViTForImageClassification,
               '''image-segmentation''': MobileViTForSemanticSegmentation,
           }
           if is_torch_available()
           else {}
       )

       SCREAMING_SNAKE_CASE_   :      Any							=  False
       SCREAMING_SNAKE_CASE_   :      Dict							=  False
       SCREAMING_SNAKE_CASE_   :      Union[str, Any]							=  False
       SCREAMING_SNAKE_CASE_   :      int							=  False




       def     _UpperCamelCase     (						self							)			->      int:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE   :str						=  MobileViTModelTester(self							)
             __SCREAMING_SNAKE_CASE   :Union[str, Any]						=  MobileViTConfigTester(self		,config_class=lowerCAmelCase__		,has_text_modality=lowerCAmelCase__							)




       def     _UpperCamelCase     (						self							)			->      Dict:





             """simple docstring"""






             self.config_tester.run_common_tests()




       @unittest.skip(reason='''MobileViT does not use inputs_embeds'''							)
       def     _UpperCamelCase     (						self							)			->      List[Any]:





             """simple docstring"""






             pass




       @unittest.skip(reason='''MobileViT does not support input and output embeddings'''							)
       def     _UpperCamelCase     (						self							)			->      Dict:





             """simple docstring"""






             pass




       @unittest.skip(reason='''MobileViT does not output attentions'''							)
       def     _UpperCamelCase     (						self							)			->      int:





             """simple docstring"""






             pass




       def     _UpperCamelCase     (						self							)			->      List[Any]:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE   :Dict						=  self.model_tester.prepare_config_and_inputs_for_common()

             for model_class in self.all_model_classes:
                   __SCREAMING_SNAKE_CASE   :List[str]						=  model_class(lowerCAmelCase__							)
                   __SCREAMING_SNAKE_CASE   :Optional[int]						=  inspect.signature(model.forward							)
                   # signature.parameters is an OrderedDict => so arg_names order is deterministic
                   __SCREAMING_SNAKE_CASE   :List[Any]						=  [*signature.parameters.keys()]

                   __SCREAMING_SNAKE_CASE   :List[str]						=  ["pixel_values"]
                   self.assertListEqual(arg_names[:1]		,lowerCAmelCase__							)




       @unittest.skip('''Will be fixed soon by reducing the size of the model used for common tests.'''							)
       def     _UpperCamelCase     (						self							)			->      str:





             """simple docstring"""






             pass




       def     _UpperCamelCase     (						self							)			->      int:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE   :List[str]						=  self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_model(*lowerCAmelCase__							)




       def     _UpperCamelCase     (						self							)			->      Optional[Any]:





             """simple docstring"""






             def check_hidden_states_output(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							):
                   __SCREAMING_SNAKE_CASE   :Dict						=  model_class(lowerCAmelCase__							)
                   model.to(lowerCAmelCase__							)
                   model.eval()

                   with torch.no_grad():
                         __SCREAMING_SNAKE_CASE   :Union[str, Any]						=  model(**self._prepare_for_class(lowerCAmelCase__		,lowerCAmelCase__							)							)

                   __SCREAMING_SNAKE_CASE   :Optional[int]						=  outputs.hidden_states

                   __SCREAMING_SNAKE_CASE   :Any						=  5
                   self.assertEqual(len(lowerCAmelCase__							)		,lowerCAmelCase__							)

                   # MobileViT's feature maps are of shape (batch_size, num_channels, height, width)
                   # with the width and height being successively divided by 2.
                   __SCREAMING_SNAKE_CASE   :Optional[Any]						=  2
                   for i in range(len(lowerCAmelCase__							)							):
                         self.assertListEqual(
                             list(hidden_states[i].shape[-2:]							)		,[self.model_tester.image_size // divisor, self.model_tester.image_size // divisor]		,)
                         divisor *= 2

                   self.assertEqual(self.model_tester.output_stride		,divisor // 2							)

             __SCREAMING_SNAKE_CASE   :List[Any]						=  self.model_tester.prepare_config_and_inputs_for_common()

             for model_class in self.all_model_classes:
                   __SCREAMING_SNAKE_CASE   :Dict						=  True
                   check_hidden_states_output(lowerCAmelCase__		,lowerCAmelCase__		,lowerCAmelCase__							)

                   # check that output_hidden_states also work using config
                   del inputs_dict["output_hidden_states"]
                   __SCREAMING_SNAKE_CASE   :Optional[int]						=  True

                   check_hidden_states_output(lowerCAmelCase__		,lowerCAmelCase__		,lowerCAmelCase__							)




       def     _UpperCamelCase     (						self							)			->      int:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE   :Optional[Any]						=  self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_image_classification(*lowerCAmelCase__							)




       def     _UpperCamelCase     (						self							)			->      Optional[Any]:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE   :Any						=  self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_semantic_segmentation(*lowerCAmelCase__							)




       @slow
       def     _UpperCamelCase     (						self							)			->      Dict:





             """simple docstring"""






             for model_name in MOBILEVIT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                   __SCREAMING_SNAKE_CASE   :Optional[int]						=  MobileViTModel.from_pretrained(lowerCAmelCase__							)
                   self.assertIsNotNone(lowerCAmelCase__							)




def      __lowerCamelCase   (							)			->      Union[str, Any]:
      __SCREAMING_SNAKE_CASE   :Union[str, Any]						=  Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''							)
      return image







@require_torch
@require_vision
class 					_SCREAMING_SNAKE_CASE(   unittest.TestCase  ):




       @cached_property
       def     _UpperCamelCase     (						self							)			->      List[str]:





             """simple docstring"""






             return MobileViTImageProcessor.from_pretrained('''apple/mobilevit-xx-small'''							) if is_vision_available() else None




       @slow
       def     _UpperCamelCase     (						self							)			->      int:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE   :int						=  MobileViTForImageClassification.from_pretrained('''apple/mobilevit-xx-small'''							).to(lowerCAmelCase__							)

             __SCREAMING_SNAKE_CASE   :int						=  self.default_image_processor
             __SCREAMING_SNAKE_CASE   :Union[str, Any]						=  prepare_img()
             __SCREAMING_SNAKE_CASE   :List[str]						=  image_processor(images=lowerCAmelCase__		,return_tensors='''pt'''							).to(lowerCAmelCase__							)

             # forward pass
             with torch.no_grad():
                   __SCREAMING_SNAKE_CASE   :int						=  model(**lowerCAmelCase__							)

             # verify the logits
             __SCREAMING_SNAKE_CASE   :Union[str, Any]						=  torch.Size((1, 10_00)							)
             self.assertEqual(outputs.logits.shape		,lowerCAmelCase__							)

             __SCREAMING_SNAKE_CASE   :Any						=  torch.tensor([-1.9_3_6_4, -1.2_3_2_7, -0.4_6_5_3]							).to(lowerCAmelCase__							)

             self.assertTrue(torch.allclose(outputs.logits[0, :3]		,lowerCAmelCase__		,atol=1E-4							)							)




       @slow
       def     _UpperCamelCase     (						self							)			->      str:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE   :Optional[Any]						=  MobileViTForSemanticSegmentation.from_pretrained('''apple/deeplabv3-mobilevit-xx-small'''							)
             __SCREAMING_SNAKE_CASE   :Optional[Any]						=  model.to(lowerCAmelCase__							)

             __SCREAMING_SNAKE_CASE   :List[Any]						=  MobileViTImageProcessor.from_pretrained('''apple/deeplabv3-mobilevit-xx-small'''							)

             __SCREAMING_SNAKE_CASE   :Union[str, Any]						=  prepare_img()
             __SCREAMING_SNAKE_CASE   :Any						=  image_processor(images=lowerCAmelCase__		,return_tensors='''pt'''							).to(lowerCAmelCase__							)

             # forward pass
             with torch.no_grad():
                   __SCREAMING_SNAKE_CASE   :Optional[int]						=  model(**lowerCAmelCase__							)
             __SCREAMING_SNAKE_CASE   :Union[str, Any]						=  outputs.logits

             # verify the logits
             __SCREAMING_SNAKE_CASE   :Union[str, Any]						=  torch.Size((1, 21, 32, 32)							)
             self.assertEqual(logits.shape		,lowerCAmelCase__							)

             __SCREAMING_SNAKE_CASE   :Union[str, Any]						=  torch.tensor(
                 [
                     [[6.9_7_1_3, 6.9_7_8_6, 7.2_4_2_2], [7.2_8_9_3, 7.2_8_2_5, 7.4_4_4_6], [7.6_5_8_0, 7.8_7_9_7, 7.9_4_2_0]],
                     [[-1_0.6_8_6_9, -1_0.3_2_5_0, -1_0.3_4_7_1], [-1_0.4_2_2_8, -9.9_8_6_8, -9.7_1_3_2], [-1_1.0_4_0_5, -1_1.0_2_2_1, -1_0.7_3_1_8]],
                     [[-3.3_0_8_9, -2.8_5_3_9, -2.6_7_4_0], [-3.2_7_0_6, -2.5_6_2_1, -2.5_1_0_8], [-3.2_5_3_4, -2.6_6_1_5, -2.6_6_5_1]],
                 ]		,device=lowerCAmelCase__		,)

             self.assertTrue(torch.allclose(logits[0, :3, :3, :3]		,lowerCAmelCase__		,atol=1E-4							)							)




       @slow
       def     _UpperCamelCase     (						self							)			->      Tuple:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE   :List[str]						=  MobileViTForSemanticSegmentation.from_pretrained('''apple/deeplabv3-mobilevit-xx-small'''							)
             __SCREAMING_SNAKE_CASE   :Dict						=  model.to(lowerCAmelCase__							)

             __SCREAMING_SNAKE_CASE   :Union[str, Any]						=  MobileViTImageProcessor.from_pretrained('''apple/deeplabv3-mobilevit-xx-small'''							)

             __SCREAMING_SNAKE_CASE   :Dict						=  prepare_img()
             __SCREAMING_SNAKE_CASE   :Optional[Any]						=  image_processor(images=lowerCAmelCase__		,return_tensors='''pt'''							).to(lowerCAmelCase__							)

             # forward pass
             with torch.no_grad():
                   __SCREAMING_SNAKE_CASE   :Union[str, Any]						=  model(**lowerCAmelCase__							)

             __SCREAMING_SNAKE_CASE   :int						=  outputs.logits.detach().cpu()

             __SCREAMING_SNAKE_CASE   :Any						=  image_processor.post_process_semantic_segmentation(outputs=lowerCAmelCase__		,target_sizes=[(50, 60)]							)
             __SCREAMING_SNAKE_CASE   :Tuple						=  torch.Size((50, 60)							)
             self.assertEqual(segmentation[0].shape		,lowerCAmelCase__							)

             __SCREAMING_SNAKE_CASE   :Optional[Any]						=  image_processor.post_process_semantic_segmentation(outputs=lowerCAmelCase__							)
             __SCREAMING_SNAKE_CASE   :Optional[Any]						=  torch.Size((32, 32)							)
             self.assertEqual(segmentation[0].shape		,lowerCAmelCase__							)


import unittest

from transformers import (
    MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING,
    TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING,
    TextaTextGenerationPipeline,
    pipeline,
)
from transformers.testing_utils import is_pipeline_test, require_tf, require_torch
from transformers.utils import is_torch_available

from .test_pipelines_common import ANY


if is_torch_available():
						import torch



@is_pipeline_test
class   __lowercase				( unittest.TestCase	):




			"""simple docstring"""







			_UpperCAmelCase   :							List[Any]										=     MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING
			_UpperCAmelCase   :							str										=     TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING



			def        _SCREAMING_SNAKE_CASE			( self  :     Any   ,						lowerCAmelCase__  :     List[str]   ,						lowerCAmelCase__  :     List[str]   ,						lowerCAmelCase__  :     Dict):
									SCREAMING_SNAKE_CASE_: Any  		=       TextaTextGenerationPipeline(model=lowerCAmelCase__   ,						tokenizer=lowerCAmelCase__)
									return generator, ["Something to write", "Something else"]



			def        _SCREAMING_SNAKE_CASE			( self  :     str   ,						lowerCAmelCase__  :     Dict   ,						lowerCAmelCase__  :     Any):
									SCREAMING_SNAKE_CASE_: List[Any]  		=       generator("Something there")
									self.assertEqual(lowerCAmelCase__   ,						[{"generated_text": ANY(lowerCAmelCase__)}])
									# These are encoder decoder, they don't just append to incoming string
									self.assertFalse(outputs[0]["generated_text"].startswith("Something there"))

									SCREAMING_SNAKE_CASE_: List[Any]  		=       generator(["This is great !", "Something else"]   ,						num_return_sequences=2   ,						do_sample=lowerCAmelCase__)
									self.assertEqual(
									    lowerCAmelCase__   ,						[
									        [{"generated_text": ANY(lowerCAmelCase__)}, {"generated_text": ANY(lowerCAmelCase__)}],
									        [{"generated_text": ANY(lowerCAmelCase__)}, {"generated_text": ANY(lowerCAmelCase__)}],
									    ]   ,						)

									SCREAMING_SNAKE_CASE_: Dict  		=       generator(
									    ["This is great !", "Something else"]   ,						num_return_sequences=2   ,						batch_size=2   ,						do_sample=lowerCAmelCase__)
									self.assertEqual(
									    lowerCAmelCase__   ,						[
									        [{"generated_text": ANY(lowerCAmelCase__)}, {"generated_text": ANY(lowerCAmelCase__)}],
									        [{"generated_text": ANY(lowerCAmelCase__)}, {"generated_text": ANY(lowerCAmelCase__)}],
									    ]   ,						)

									with self.assertRaises(lowerCAmelCase__):
															generator(4)



			@require_torch
			def        _SCREAMING_SNAKE_CASE			( self  :     Tuple):
									SCREAMING_SNAKE_CASE_: Optional[int]  		=       pipeline("text2text-generation"   ,						model="patrickvonplaten/t5-tiny-random"   ,						framework="pt")
									# do_sample=False necessary for reproducibility
									SCREAMING_SNAKE_CASE_: Union[str, Any]  		=       generator("Something there"   ,						do_sample=lowerCAmelCase__)
									self.assertEqual(lowerCAmelCase__   ,						[{"generated_text": ""}])

									SCREAMING_SNAKE_CASE_: Union[str, Any]  		=       3
									SCREAMING_SNAKE_CASE_: Any  		=       generator(
									    "Something there"   ,						num_return_sequences=lowerCAmelCase__   ,						num_beams=lowerCAmelCase__   ,						)
									SCREAMING_SNAKE_CASE_: Any  		=       [
									    {"generated_text": "Beide Beide Beide Beide Beide Beide Beide Beide Beide"},
									    {"generated_text": "Beide Beide Beide Beide Beide Beide Beide Beide"},
									    {"generated_text": ""},
									]
									self.assertEqual(lowerCAmelCase__   ,						lowerCAmelCase__)

									SCREAMING_SNAKE_CASE_: int  		=       generator("This is a test"   ,						do_sample=lowerCAmelCase__   ,						num_return_sequences=2   ,						return_tensors=lowerCAmelCase__)
									self.assertEqual(
									    lowerCAmelCase__   ,						[
									        {"generated_token_ids": ANY(torch.Tensor)},
									        {"generated_token_ids": ANY(torch.Tensor)},
									    ]   ,						)
									SCREAMING_SNAKE_CASE_: str  		=       generator.model.config.eos_token_id
									SCREAMING_SNAKE_CASE_: Union[str, Any]  		=       "<pad>"
									SCREAMING_SNAKE_CASE_: Tuple  		=       generator(
									    ["This is a test", "This is a second test"]   ,						do_sample=lowerCAmelCase__   ,						num_return_sequences=2   ,						batch_size=2   ,						return_tensors=lowerCAmelCase__   ,						)
									self.assertEqual(
									    lowerCAmelCase__   ,						[
									        [
									            {"generated_token_ids": ANY(torch.Tensor)},
									            {"generated_token_ids": ANY(torch.Tensor)},
									        ],
									        [
									            {"generated_token_ids": ANY(torch.Tensor)},
									            {"generated_token_ids": ANY(torch.Tensor)},
									        ],
									    ]   ,						)




			@require_tf
			def        _SCREAMING_SNAKE_CASE			( self  :     Union[str, Any]):
									SCREAMING_SNAKE_CASE_: Union[str, Any]  		=       pipeline("text2text-generation"   ,						model="patrickvonplaten/t5-tiny-random"   ,						framework="tf")
									# do_sample=False necessary for reproducibility
									SCREAMING_SNAKE_CASE_: List[Any]  		=       generator("Something there"   ,						do_sample=lowerCAmelCase__)
									self.assertEqual(lowerCAmelCase__   ,						[{"generated_text": ""}])






