
"""simple docstring"""




from typing import Mapping

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


A__      :	List[str]          =    logging.get_logger(__name__)

A__      :	Tuple          =    {
    """google/umt5-small""": """https://huggingface.co/google/umt5-small/resolve/main/config.json""",
    # See all umt5 models at https://huggingface.co/models?filter=umt5
}







class   _lowercase						(       lowerCAmelCase_				):


     '''simple docstring'''





     _A								=							'umt5'
     _A								=							['past_key_values']



     def __init__(      self ,			__UpperCamelCase=25_01_12 ,			__UpperCamelCase=5_12 ,			__UpperCamelCase=64 ,			__UpperCamelCase=10_24 ,			__UpperCamelCase=8 ,			__UpperCamelCase=None ,			__UpperCamelCase=6 ,			__UpperCamelCase=32 ,			__UpperCamelCase=1_28 ,			__UpperCamelCase=0.1 ,			__UpperCamelCase=1E-6 ,			__UpperCamelCase=1.0 ,			__UpperCamelCase="gated-gelu" ,			__UpperCamelCase=True ,			__UpperCamelCase=True ,			__UpperCamelCase="T5Tokenizer" ,			__UpperCamelCase=True ,			__UpperCamelCase=0 ,			__UpperCamelCase=1 ,			__UpperCamelCase=0 ,			**__UpperCamelCase ,			)->					str:
          super().__init__(
              is_encoder_decoder=__UpperCamelCase ,			tokenizer_class=__UpperCamelCase ,			tie_word_embeddings=__UpperCamelCase ,			pad_token_id=__UpperCamelCase ,			eos_token_id=__UpperCamelCase ,			decoder_start_token_id=__UpperCamelCase ,			**__UpperCamelCase ,			)
          UpperCAmelCase__							: Any 							=						vocab_size
          UpperCAmelCase__							: str 							=						d_model
          UpperCAmelCase__							: Dict 							=						d_kv
          UpperCAmelCase__							: List[str] 							=						d_ff
          UpperCAmelCase__							: Tuple 							=						num_layers
          UpperCAmelCase__							: Tuple 							=						(
              num_decoder_layers if num_decoder_layers is not None else self.num_layers
          )  # default = symmetry
          UpperCAmelCase__							: Optional[int] 							=						num_heads
          UpperCAmelCase__							: Dict 							=						relative_attention_num_buckets
          UpperCAmelCase__							: Any 							=						relative_attention_max_distance
          UpperCAmelCase__							: int 							=						dropout_rate
          UpperCAmelCase__							: Optional[Any] 							=						layer_norm_epsilon
          UpperCAmelCase__							: Tuple 							=						initializer_factor
          UpperCAmelCase__							: Optional[Any] 							=						feed_forward_proj
          UpperCAmelCase__							: Optional[int] 							=						use_cache

          UpperCAmelCase__							: str 							=						self.feed_forward_proj.split("-"  )
          UpperCAmelCase__							: List[str] 							=						act_info[-1]
          UpperCAmelCase__							: Optional[Any] 							=						act_info[0] == "gated"

          if len(__UpperCamelCase  ) > 1 and act_info[0] != "gated" or len(__UpperCamelCase  ) > 2:
               raise ValueError(
                   F"`feed_forward_proj`: {feed_forward_proj} is not a valid activation function of the dense layer."
                   "Please make sure `feed_forward_proj` is of the format `gated-{ACT_FN}` or `{ACT_FN}`, e.g. "
                   "'gated-gelu' or 'relu'"  )

          if feed_forward_proj == "gated-gelu":
               UpperCAmelCase__							: Union[str, Any] 							=						"gelu_new"



     @property
     def  lowerCAmelCase__       (      self  )->					Optional[Any]:
          return self.d_model



     @property
     def  lowerCAmelCase__       (      self  )->					Dict:
          return self.num_heads



     @property
     def  lowerCAmelCase__       (      self  )->					int:
          return self.num_layers







class   _lowercase						(       lowerCAmelCase_				):


     '''simple docstring'''





     @property
     # Copied from transformers.models.t5.configuration_t5.T5OnnxConfig.inputs
     def  lowerCAmelCase__       (      self  )->					Mapping[str, Mapping[int, str]]:
          UpperCAmelCase__							: Any 							=						{
              "input_ids": {0: "batch", 1: "encoder_sequence"},
              "attention_mask": {0: "batch", 1: "encoder_sequence"},
          }
          if self.use_past:
               UpperCAmelCase__							: Optional[int] 							=						"past_encoder_sequence + sequence"
               UpperCAmelCase__							: List[str] 							=						{0: "batch"}
               UpperCAmelCase__							: Dict 							=						{0: "batch", 1: "past_decoder_sequence + sequence"}
          else:
               UpperCAmelCase__							: Optional[Any] 							=						{0: "batch", 1: "decoder_sequence"}
               UpperCAmelCase__							: Dict 							=						{0: "batch", 1: "decoder_sequence"}

          if self.use_past:
               self.fill_with_past_key_values_(__UpperCamelCase ,			direction="inputs"  )

          return common_inputs



     @property
     # Copied from transformers.models.t5.configuration_t5.T5OnnxConfig.default_onnx_opset
     def  lowerCAmelCase__       (      self  )->					int:
          return 13



     @property
     def  lowerCAmelCase__       (      self  )->					float:
          return 5E-4





"""simple docstring"""




import unittest

from transformers import load_tool

from .test_tools_common import ToolTesterMixin







class   _lowercase						(       unittest.TestCase	,   lowerCAmelCase_				):


     '''simple docstring'''





     def  lowerCAmelCase__       (      self  )->					Dict:
          UpperCAmelCase__							: Optional[Any] 							=						load_tool("text-classification"  )
          self.tool.setup()
          UpperCAmelCase__							: List[str] 							=						load_tool("text-classification" ,			remote=__UpperCamelCase  )



     def  lowerCAmelCase__       (      self  )->					Union[str, Any]:
          UpperCAmelCase__							: Dict 							=						self.tool("That's quite cool" ,			["positive", "negative"]  )
          self.assertEqual(__UpperCamelCase ,			"positive"  )



     def  lowerCAmelCase__       (      self  )->					str:
          UpperCAmelCase__							: List[Any] 							=						self.remote_tool("That's quite cool" ,			["positive", "negative"]  )
          self.assertEqual(__UpperCamelCase ,			"positive"  )



     def  lowerCAmelCase__       (      self  )->					Optional[int]:
          UpperCAmelCase__							: Any 							=						self.tool(text="That's quite cool" ,			labels=["positive", "negative"]  )
          self.assertEqual(__UpperCamelCase ,			"positive"  )



     def  lowerCAmelCase__       (      self  )->					str:
          UpperCAmelCase__							: str 							=						self.remote_tool(text="That's quite cool" ,			labels=["positive", "negative"]  )
          self.assertEqual(__UpperCamelCase ,			"positive"  )



