

"""simple docstring"""



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				):



    """simple docstring"""



    UpperCAmelCase						 =					MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING
    UpperCAmelCase						 =					TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING

    def 				UpperCamelCase	(     self: Dict    ,						UpperCamelCase: str    ,						UpperCamelCase: Optional[Any]    ,						UpperCamelCase: Any       ):






         """simple docstring"""


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

    def 				UpperCamelCase	(     self: List[Any]    ,						UpperCamelCase: Any    ,						UpperCamelCase: Dict       ):






         """simple docstring"""


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

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

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

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

    @require_torch
    def 				UpperCamelCase	(     self: Optional[Any]       ):






         """simple docstring"""


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

         A__										=  3
         A__										=  generator(
             """Something there"""    ,						num_return_sequences=UpperCamelCase    ,						num_beams=UpperCamelCase    ,						)
         A__										=  [
             {"""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(UpperCamelCase    ,						UpperCamelCase       )

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






         """simple docstring"""


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









"""simple docstring"""



import warnings
from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


SCREAMING_SNAKE_CASE_					:	Any							  =						logging.get_logger(__name__)

SCREAMING_SNAKE_CASE_					:	Optional[Any]							  =						{
    'nvidia/segformer-b0-finetuned-ade-512-512': (
        'https://huggingface.co/nvidia/segformer-b0-finetuned-ade-512-512/resolve/main/config.json'
    ),
    # See all SegFormer models at https://huggingface.co/models?filter=segformer
}



class 					a						(       _lowerCamelCase				):



    """simple docstring"""



    UpperCAmelCase						 =					"segformer"

    def __init__(     self: Optional[Any]    ,						UpperCamelCase: Union[str, Any]=3    ,						UpperCamelCase: int=4    ,						UpperCamelCase: int=[2, 2, 2, 2]    ,						UpperCamelCase: List[str]=[8, 4, 2, 1]    ,						UpperCamelCase: List[Any]=[32, 64, 1_60, 2_56]    ,						UpperCamelCase: Any=[7, 3, 3, 3]    ,						UpperCamelCase: Union[str, Any]=[4, 2, 2, 2]    ,						UpperCamelCase: Tuple=[1, 2, 5, 8]    ,						UpperCamelCase: Optional[int]=[4, 4, 4, 4]    ,						UpperCamelCase: Dict="gelu"    ,						UpperCamelCase: Optional[Any]=0.0    ,						UpperCamelCase: List[str]=0.0    ,						UpperCamelCase: Union[str, Any]=0.1    ,						UpperCamelCase: List[Any]=0.02    ,						UpperCamelCase: int=0.1    ,						UpperCamelCase: Optional[int]=1e-6    ,						UpperCamelCase: int=2_56    ,						UpperCamelCase: Union[str, Any]=2_55    ,						**UpperCamelCase: Optional[Any]    ,						):






         """simple docstring"""


         super().__init__(**UpperCamelCase       )

         if "reshape_last_stage" in kwargs and kwargs["reshape_last_stage"] is False:
              warnings.warn(
                  """Reshape_last_stage is set to False in this config. This argument is deprecated and will soon be"""
                  """ removed, as the behaviour will default to that of reshape_last_stage = True."""    ,						UpperCamelCase    ,						)

         A__										=  num_channels
         A__										=  num_encoder_blocks
         A__										=  depths
         A__										=  sr_ratios
         A__										=  hidden_sizes
         A__										=  patch_sizes
         A__										=  strides
         A__										=  mlp_ratios
         A__										=  num_attention_heads
         A__										=  hidden_act
         A__										=  hidden_dropout_prob
         A__										=  attention_probs_dropout_prob
         A__										=  classifier_dropout_prob
         A__										=  initializer_range
         A__										=  drop_path_rate
         A__										=  layer_norm_eps
         A__										=  decoder_hidden_size
         A__										=  kwargs.get("""reshape_last_stage"""    ,						UpperCamelCase       )
         A__										=  semantic_loss_ignore_index



class 					a						(       _lowerCamelCase				):



    """simple docstring"""



    UpperCAmelCase						 =					version.parse("1.11"				)

    @property
    def 				UpperCamelCase	(     self: List[str]       ):






         """simple docstring"""


         return OrderedDict(
             [
                 ("""pixel_values""", {0: """batch""", 1: """num_channels""", 2: """height""", 3: """width"""}),
             ]       )

    @property
    def 				UpperCamelCase	(     self: int       ):






         """simple docstring"""


         return 1e-4





    @property
    def 				UpperCamelCase	(     self: Optional[int]       ):






         """simple docstring"""


         return 12






