





import inspect
import unittest

import numpy as np

from tests.test_modeling_common import floats_tensor
from transformers import DetrConfig, MaskFormerConfig, SwinConfig, is_torch_available, is_vision_available
from transformers.testing_utils import require_torch, require_torch_multi_gpu, require_vision, slow, torch_device
from transformers.utils import cached_property

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
       import torch

       from transformers import MaskFormerForInstanceSegmentation, MaskFormerModel

       if is_vision_available():
              from transformers import MaskFormerImageProcessor

if is_vision_available():
       from PIL import Image

class  __A:

     def __init__(      self,       A,       A=2,       A=True,       A=False,       A=10,       A=3,       A=32 * 4,       A=32 * 6,       A=4,       A=32,       ):





            """simple docstring"""

            _UpperCamelCase              =						parent
            _UpperCamelCase              =						batch_size
            _UpperCamelCase              =						is_training
            _UpperCamelCase              =						use_auxiliary_loss
            _UpperCamelCase              =						num_queries
            _UpperCamelCase              =						num_channels
            _UpperCamelCase              =						min_size
            _UpperCamelCase              =						max_size
            _UpperCamelCase              =						num_labels
            _UpperCamelCase              =						mask_feature_size

     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            _UpperCamelCase              =						floats_tensor([self.batch_size, self.num_channels, self.min_size, self.max_size]      ).to(
                lowerCamelCase__      )

            _UpperCamelCase              =						torch.ones([self.batch_size, self.min_size, self.max_size],       device=lowerCamelCase__      )

            _UpperCamelCase              =						(
                torch.rand([self.batch_size, self.num_labels, self.min_size, self.max_size],       device=lowerCamelCase__      ) > 0.5
            ).float()
            _UpperCamelCase              =						(torch.rand((self.batch_size, self.num_labels),       device=lowerCamelCase__      ) > 0.5).long()

            _UpperCamelCase              =						self.get_config()
            return config, pixel_values, pixel_mask, mask_labels, class_labels

     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            return MaskFormerConfig.from_backbone_and_decoder_configs(
                backbone_config=SwinConfig(
                    depths=[1, 1, 1, 1],       ),       decoder_config=DetrConfig(
                    decoder_ffn_dim=128,       num_queries=self.num_queries,       decoder_attention_heads=2,       d_model=self.mask_feature_size,       ),       mask_feature_size=self.mask_feature_size,       fpn_feature_size=self.mask_feature_size,       num_channels=self.num_channels,       num_labels=self.num_labels,       )

     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            _UpperCamelCase              =						self.prepare_config_and_inputs()
            _UpperCamelCase              =						{'''pixel_values''': pixel_values, '''pixel_mask''': pixel_mask}
            return config, inputs_dict

     def 	_UpperCamelCase     (      self,       A,       A      ):





            """simple docstring"""

            _UpperCamelCase              =						output.encoder_hidden_states
            _UpperCamelCase              =						output.pixel_decoder_hidden_states
            _UpperCamelCase              =						output.transformer_decoder_hidden_states

            self.parent.assertTrue(len(lowerCamelCase__      ),       len(config.backbone_config.depths      )      )
            self.parent.assertTrue(len(lowerCamelCase__      ),       len(config.backbone_config.depths      )      )
            self.parent.assertTrue(len(lowerCamelCase__      ),       config.decoder_config.decoder_layers      )

     def 	_UpperCamelCase     (      self,       A,       A,       A,       A=False      ):





            """simple docstring"""

            with torch.no_grad():
                   _UpperCamelCase              =						MaskFormerModel(config=lowerCamelCase__      )
                   model.to(lowerCamelCase__      )
                   model.eval()

                   _UpperCamelCase              =						model(pixel_values=lowerCamelCase__,       pixel_mask=lowerCamelCase__      )
                   _UpperCamelCase              =						model(lowerCamelCase__,       output_hidden_states=lowerCamelCase__      )
            # the correct shape of output.transformer_decoder_hidden_states ensure the correcteness of the
            # encoder and pixel decoder
            self.parent.assertEqual(
                output.transformer_decoder_last_hidden_state.shape,       (self.batch_size, self.num_queries, self.mask_feature_size),       )
            # let's ensure the other two hidden state exists
            self.parent.assertTrue(output.pixel_decoder_last_hidden_state is not None      )
            self.parent.assertTrue(output.encoder_last_hidden_state is not None      )

            if output_hidden_states:
                   self.check_output_hidden_state(lowerCamelCase__,       lowerCamelCase__      )



     def 	_UpperCamelCase     (      self,       A,       A,       A,       A,       A      ):





            """simple docstring"""

            _UpperCamelCase              =						MaskFormerForInstanceSegmentation(config=lowerCamelCase__      )
            model.to(lowerCamelCase__      )
            model.eval()

            def comm_check_on_output(A      ):
                   # let's still check that all the required stuff is there
                   self.parent.assertTrue(result.transformer_decoder_last_hidden_state is not None      )
                   self.parent.assertTrue(result.pixel_decoder_last_hidden_state is not None      )
                   self.parent.assertTrue(result.encoder_last_hidden_state is not None      )
                   # okay, now we need to check the logits shape
                   # due to the encoder compression, masks have a //4 spatial size
                   self.parent.assertEqual(
                       result.masks_queries_logits.shape,       (self.batch_size, self.num_queries, self.min_size // 4, self.max_size // 4),       )
                   # + 1 for null class
                   self.parent.assertEqual(
                       result.class_queries_logits.shape,       (self.batch_size, self.num_queries, self.num_labels + 1)      )

            with torch.no_grad():
                   _UpperCamelCase              =						model(pixel_values=lowerCamelCase__,       pixel_mask=lowerCamelCase__      )
                   _UpperCamelCase              =						model(lowerCamelCase__      )

                   comm_check_on_output(lowerCamelCase__      )

                   _UpperCamelCase              =						model(
                       pixel_values=lowerCamelCase__,       pixel_mask=lowerCamelCase__,       mask_labels=lowerCamelCase__,       class_labels=lowerCamelCase__      )

            comm_check_on_output(lowerCamelCase__      )

            self.parent.assertTrue(result.loss is not None      )
            self.parent.assertEqual(result.loss.shape,       torch.Size([1]      )      )






@require_torch
class  __A(						__lowerCAmelCase						,			__lowerCAmelCase						,			unittest.TestCase ):
     __A	  =       (MaskFormerModel, MaskFormerForInstanceSegmentation) if is_torch_available() else ()
     __A	  =       (
         {"feature-extraction": MaskFormerModel, "image-segmentation": MaskFormerForInstanceSegmentation}
         if is_torch_available()
         else {}
     )

     __A	  =       False
     __A	  =       False
     __A	  =       False
     __A	  =       False

     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            _UpperCamelCase              =						MaskFormerModelTester(self      )
            _UpperCamelCase              =						ConfigTester(self,       config_class=lowerCamelCase__,       has_text_modality=lowerCamelCase__      )

     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            self.config_tester.run_common_tests()

     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            _UpperCamelCase              =						self.model_tester.prepare_config_and_inputs_for_common()
            self.model_tester.create_and_check_maskformer_model(lowerCamelCase__,       **lowerCamelCase__,       output_hidden_states=lowerCamelCase__      )

     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            _UpperCamelCase              =						self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_maskformer_instance_segmentation_head_model(*lowerCamelCase__      )

     @unittest.skip(reason='''MaskFormer does not use inputs_embeds'''      )
     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            pass

     @unittest.skip(reason='''MaskFormer does not have a get_input_embeddings method'''      )
     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            pass

     @unittest.skip(reason='''MaskFormer is not a generative model'''      )
     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            pass

     @unittest.skip(reason='''MaskFormer does not use token embeddings'''      )
     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            pass

     @require_torch_multi_gpu
     @unittest.skip(
         reason='''MaskFormer has some layers using `add_module` which doesn\'t work well with `nn.DataParallel`'''      )
     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            pass

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





            """simple docstring"""

            pass

     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            _UpperCamelCase              =						self.model_tester.prepare_config_and_inputs_for_common()

            for model_class in self.all_model_classes:
                   _UpperCamelCase              =						model_class(lowerCamelCase__      )
                   _UpperCamelCase              =						inspect.signature(model.forward      )
                   # signature.parameters is an OrderedDict => so arg_names order is deterministic
                   _UpperCamelCase              =						[*signature.parameters.keys()]

                   _UpperCamelCase              =						['''pixel_values''']
                   self.assertListEqual(arg_names[:1],       lowerCamelCase__      )

     @slow
     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            for model_name in ["facebook/maskformer-swin-small-coco"]:
                   _UpperCamelCase              =						MaskFormerModel.from_pretrained(lowerCamelCase__      )
                   self.assertIsNotNone(lowerCamelCase__      )

     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            _UpperCamelCase              =						(self.model_tester.min_size,) * 2
            _UpperCamelCase              =						{
                '''pixel_values''': torch.randn((2, 3, *size),       device=lowerCamelCase__      ),
                '''mask_labels''': torch.randn((2, 10, *size),       device=lowerCamelCase__      ),
                '''class_labels''': torch.zeros(2,       10,       device=lowerCamelCase__      ).long(),
            }

            _UpperCamelCase              =						MaskFormerForInstanceSegmentation(MaskFormerConfig()      ).to(lowerCamelCase__      )
            _UpperCamelCase              =						model(**lowerCamelCase__      )
            self.assertTrue(outputs.loss is not None      )

     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            _UpperCamelCase              =						self.model_tester.prepare_config_and_inputs_for_common()
            self.model_tester.create_and_check_maskformer_model(lowerCamelCase__,       **lowerCamelCase__,       output_hidden_states=lowerCamelCase__      )

     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            _UpperCamelCase              =						self.model_tester.prepare_config_and_inputs_for_common()

            for model_class in self.all_model_classes:
                   _UpperCamelCase              =						model_class(lowerCamelCase__      ).to(lowerCamelCase__      )
                   _UpperCamelCase              =						model(**lowerCamelCase__,       output_attentions=lowerCamelCase__      )
                   self.assertTrue(outputs.attentions is not None      )

     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            if not self.model_tester.is_training:
                   return
            # only MaskFormerForInstanceSegmentation has the loss
            _UpperCamelCase              =						self.all_model_classes[1]
            _UpperCamelCase              =						self.model_tester.prepare_config_and_inputs()

            _UpperCamelCase              =						model_class(lowerCamelCase__      )
            model.to(lowerCamelCase__      )
            model.train()

            _UpperCamelCase              =						model(lowerCamelCase__,       mask_labels=lowerCamelCase__,       class_labels=lowerCamelCase__      ).loss
            loss.backward()



     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            _UpperCamelCase              =						self.all_model_classes[1]
            _UpperCamelCase              =						self.model_tester.prepare_config_and_inputs()
            _UpperCamelCase              =						True
            _UpperCamelCase              =						True

            _UpperCamelCase              =						model_class(lowerCamelCase__      )
            model.to(lowerCamelCase__      )
            model.train()

            _UpperCamelCase              =						model(lowerCamelCase__,       mask_labels=lowerCamelCase__,       class_labels=lowerCamelCase__      )

            _UpperCamelCase              =						outputs.encoder_hidden_states[0]
            encoder_hidden_states.retain_grad()

            _UpperCamelCase              =						outputs.pixel_decoder_hidden_states[0]
            pixel_decoder_hidden_states.retain_grad()
            # we requires_grad=True in inputs_embeds (line 2152), the original implementation don't
            _UpperCamelCase              =						outputs.transformer_decoder_hidden_states[0]
            transformer_decoder_hidden_states.retain_grad()

            _UpperCamelCase              =						outputs.attentions[0]
            attentions.retain_grad()

            outputs.loss.backward(retain_graph=lowerCamelCase__      )

            self.assertIsNotNone(encoder_hidden_states.grad      )
            self.assertIsNotNone(pixel_decoder_hidden_states.grad      )
            self.assertIsNotNone(transformer_decoder_hidden_states.grad      )
            self.assertIsNotNone(attentions.grad      )






lowercase    : Optional[int]    	=  1e-4


def     SCREAMING_SNAKE_CASE			(      ):
       _UpperCamelCase              =						Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''					)
       return image

@require_vision
@slow
class  __A(						unittest.TestCase ):

     @cached_property
     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            return (
                MaskFormerImageProcessor.from_pretrained('''facebook/maskformer-swin-small-coco'''      )
                if is_vision_available()
                else None
            )

     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            _UpperCamelCase              =						MaskFormerModel.from_pretrained('''facebook/maskformer-swin-small-coco'''      ).to(lowerCamelCase__      )
            _UpperCamelCase              =						self.default_image_processor
            _UpperCamelCase              =						prepare_img()
            _UpperCamelCase              =						image_processor(lowerCamelCase__,       return_tensors='''pt'''      ).to(lowerCamelCase__      )
            _UpperCamelCase              =						inputs['''pixel_values'''].shape
            # check size is divisible by 32
            self.assertTrue((inputs_shape[-1] % 32) == 0 and (inputs_shape[-2] % 32) == 0      )
            # check size
            self.assertEqual(lowerCamelCase__,       (1, 3, 800, 1088)      )

            with torch.no_grad():
                   _UpperCamelCase              =						model(**lowerCamelCase__      )

            _UpperCamelCase              =						torch.tensor(
                [[-0.0_482, 0.9_228, 0.4_951], [-0.2_547, 0.8_017, 0.8_527], [-0.0_069, 0.3_385, -0.0_089]]      ).to(lowerCamelCase__      )
            self.assertTrue(
                torch.allclose(
                    outputs.encoder_last_hidden_state[0, 0, :3, :3],       lowerCamelCase__,       atol=lowerCamelCase__      )      )

            _UpperCamelCase              =						torch.tensor(
                [[-0.8_422, -0.8_434, -0.9_718], [-1.0_144, -0.5_565, -0.4_195], [-1.0_038, -0.4_484, -0.1_961]]      ).to(lowerCamelCase__      )
            self.assertTrue(
                torch.allclose(
                    outputs.pixel_decoder_last_hidden_state[0, 0, :3, :3],       lowerCamelCase__,       atol=lowerCamelCase__      )      )

            _UpperCamelCase              =						torch.tensor(
                [[0.2_852, -0.0_159, 0.9_735], [0.6_254, 0.1_858, 0.8_529], [-0.0_680, -0.4_116, 1.8_413]]      ).to(lowerCamelCase__      )
            self.assertTrue(
                torch.allclose(
                    outputs.transformer_decoder_last_hidden_state[0, :3, :3],       lowerCamelCase__,       atol=lowerCamelCase__      )      )

     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            _UpperCamelCase              =						(
                MaskFormerForInstanceSegmentation.from_pretrained('''facebook/maskformer-swin-small-coco'''      )
                .to(lowerCamelCase__      )
                .eval()
            )
            _UpperCamelCase              =						self.default_image_processor
            _UpperCamelCase              =						prepare_img()
            _UpperCamelCase              =						image_processor(lowerCamelCase__,       return_tensors='''pt'''      ).to(lowerCamelCase__      )
            _UpperCamelCase              =						inputs['''pixel_values'''].shape
            # check size is divisible by 32
            self.assertTrue((inputs_shape[-1] % 32) == 0 and (inputs_shape[-2] % 32) == 0      )
            # check size
            self.assertEqual(lowerCamelCase__,       (1, 3, 800, 1088)      )

            with torch.no_grad():
                   _UpperCamelCase              =						model(**lowerCamelCase__      )
            # masks_queries_logits
            _UpperCamelCase              =						outputs.masks_queries_logits
            self.assertEqual(
                masks_queries_logits.shape,       (1, model.config.decoder_config.num_queries, inputs_shape[-2] // 4, inputs_shape[-1] // 4),       )
            _UpperCamelCase              =						[
                [-1.3_737_124, -1.7_724_937, -1.9_364_233],
                [-1.5_977_281, -1.9_867_939, -2.1_523_695],
                [-1.5_795_398, -1.9_269_832, -2.093_942],
            ]
            _UpperCamelCase              =						torch.tensor(lowerCamelCase__      ).to(lowerCamelCase__      )
            self.assertTrue(torch.allclose(masks_queries_logits[0, 0, :3, :3],       lowerCamelCase__,       atol=lowerCamelCase__      )      )
            # class_queries_logits
            _UpperCamelCase              =						outputs.class_queries_logits
            self.assertEqual(
                class_queries_logits.shape,       (1, model.config.decoder_config.num_queries, model.config.num_labels + 1)      )
            _UpperCamelCase              =						torch.tensor(
                [
                    [1.6_5_1_2E0_0, -5.2_5_7_2E0_0, -3.3_5_1_9E0_0],
                    [3.6_1_6_9E-0_2, -5.9_0_2_5E0_0, -2.9_3_1_3E0_0],
                    [1.0_7_6_6E-0_4, -7.7_6_3_0E0_0, -5.1_2_6_3E0_0],
                ]      ).to(lowerCamelCase__      )
            self.assertTrue(torch.allclose(outputs.class_queries_logits[0, :3, :3],       lowerCamelCase__,       atol=lowerCamelCase__      )      )

     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            _UpperCamelCase              =						(
                MaskFormerForInstanceSegmentation.from_pretrained('''facebook/maskformer-resnet101-coco-stuff'''      )
                .to(lowerCamelCase__      )
                .eval()
            )
            _UpperCamelCase              =						self.default_image_processor
            _UpperCamelCase              =						prepare_img()
            _UpperCamelCase              =						image_processor(lowerCamelCase__,       return_tensors='''pt'''      ).to(lowerCamelCase__      )
            _UpperCamelCase              =						inputs['''pixel_values'''].shape
            # check size is divisible by 32
            self.assertTrue((inputs_shape[-1] % 32) == 0 and (inputs_shape[-2] % 32) == 0      )
            # check size
            self.assertEqual(lowerCamelCase__,       (1, 3, 800, 1088)      )

            with torch.no_grad():
                   _UpperCamelCase              =						model(**lowerCamelCase__      )
            # masks_queries_logits
            _UpperCamelCase              =						outputs.masks_queries_logits
            self.assertEqual(
                masks_queries_logits.shape,       (1, model.config.decoder_config.num_queries, inputs_shape[-2] // 4, inputs_shape[-1] // 4),       )
            _UpperCamelCase              =						[[-0.9_046, -2.6_366, -4.6_062], [-3.4_179, -5.7_890, -8.8_057], [-4.9_179, -7.6_560, -10.7_711]]
            _UpperCamelCase              =						torch.tensor(lowerCamelCase__      ).to(lowerCamelCase__      )
            self.assertTrue(torch.allclose(masks_queries_logits[0, 0, :3, :3],       lowerCamelCase__,       atol=lowerCamelCase__      )      )
            # class_queries_logits
            _UpperCamelCase              =						outputs.class_queries_logits
            self.assertEqual(
                class_queries_logits.shape,       (1, model.config.decoder_config.num_queries, model.config.num_labels + 1)      )
            _UpperCamelCase              =						torch.tensor(
                [[4.7_188, -3.2_585, -2.8_857], [6.6_871, -2.9_181, -1.2_487], [7.2_449, -2.2_764, -2.1_874]]      ).to(lowerCamelCase__      )
            self.assertTrue(torch.allclose(outputs.class_queries_logits[0, :3, :3],       lowerCamelCase__,       atol=lowerCamelCase__      )      )



     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            _UpperCamelCase              =						(
                MaskFormerForInstanceSegmentation.from_pretrained('''facebook/maskformer-swin-small-coco'''      )
                .to(lowerCamelCase__      )
                .eval()
            )
            _UpperCamelCase              =						self.default_image_processor

            _UpperCamelCase              =						image_processor(
                [np.zeros((3, 800, 1333)      ), np.zeros((3, 800, 1333)      )],       segmentation_maps=[np.zeros((384, 384)      ).astype(np.floataa      ), np.zeros((384, 384)      ).astype(np.floataa      )],       return_tensors='''pt''',       )

            _UpperCamelCase              =						inputs['''pixel_values'''].to(lowerCamelCase__      )
            _UpperCamelCase              =						[el.to(lowerCamelCase__      ) for el in inputs['''mask_labels''']]
            _UpperCamelCase              =						[el.to(lowerCamelCase__      ) for el in inputs['''class_labels''']]

            with torch.no_grad():
                   _UpperCamelCase              =						model(**lowerCamelCase__      )

            self.assertTrue(outputs.loss is not None      )










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  __A(						unittest.TestCase ):
     __A	  =       MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING
     __A	  =       TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING

     def 	_UpperCamelCase     (      self,       A,       A,       A      ):





            """simple docstring"""

            _UpperCamelCase              =						TextaTextGenerationPipeline(model=A,       tokenizer=A      )
            return generator, ["Something to write", "Something else"]

     def 	_UpperCamelCase     (      self,       A,       A      ):





            """simple docstring"""

            _UpperCamelCase              =						generator('''Something there'''      )
            self.assertEqual(A,       [{'''generated_text''': ANY(A      )}]      )
            # These are encoder decoder, they don't just append to incoming string
            self.assertFalse(outputs[0]['''generated_text'''].startswith('''Something there'''      )      )

            _UpperCamelCase              =						generator(['''This is great !''', '''Something else'''],       num_return_sequences=2,       do_sample=A      )
            self.assertEqual(
                A,       [
                    [{'''generated_text''': ANY(A      )}, {'''generated_text''': ANY(A      )}],
                    [{'''generated_text''': ANY(A      )}, {'''generated_text''': ANY(A      )}],
                ],       )

            _UpperCamelCase              =						generator(
                ['''This is great !''', '''Something else'''],       num_return_sequences=2,       batch_size=2,       do_sample=A      )
            self.assertEqual(
                A,       [
                    [{'''generated_text''': ANY(A      )}, {'''generated_text''': ANY(A      )}],
                    [{'''generated_text''': ANY(A      )}, {'''generated_text''': ANY(A      )}],
                ],       )

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

     @require_torch
     def 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            _UpperCamelCase              =						pipeline('''text2text-generation''',       model='''patrickvonplaten/t5-tiny-random''',       framework='''pt'''      )
            # do_sample=False necessary for reproducibility
            _UpperCamelCase              =						generator('''Something there''',       do_sample=A      )
            self.assertEqual(A,       [{'''generated_text''': ''''''}]      )

            _UpperCamelCase              =						3
            _UpperCamelCase              =						generator(
                '''Something there''',       num_return_sequences=A,       num_beams=A,       )
            _UpperCamelCase              =						[
                {'''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(A,       A      )

            _UpperCamelCase              =						generator('''This is a test''',       do_sample=A,       num_return_sequences=2,       return_tensors=A      )
            self.assertEqual(
                A,       [
                    {'''generated_token_ids''': ANY(torch.Tensor      )},
                    {'''generated_token_ids''': ANY(torch.Tensor      )},
                ],       )
            _UpperCamelCase              =						generator.model.config.eos_token_id
            _UpperCamelCase              =						'''<pad>'''
            _UpperCamelCase              =						generator(
                ['''This is a test''', '''This is a second test'''],       do_sample=A,       num_return_sequences=2,       batch_size=2,       return_tensors=A,       )
            self.assertEqual(
                A,       [
                    [
                        {'''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 	_UpperCamelCase     (      self      ):





            """simple docstring"""

            _UpperCamelCase              =						pipeline('''text2text-generation''',       model='''patrickvonplaten/t5-tiny-random''',       framework='''tf'''      )
            # do_sample=False necessary for reproducibility
            _UpperCamelCase              =						generator('''Something there''',       do_sample=A      )
            self.assertEqual(A,       [{'''generated_text''': ''''''}]      )






