





from typing import Mapping

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


UpperCAmelCase_					:   Optional[Any] 							=						logging.get_logger(__name__)

UpperCAmelCase_					:   List[Any] 							=						{
    '''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__							(							__a  ):
  __UpperCamelCase	     =  '''umt5'''
  __UpperCamelCase	     =  ['''past_key_values''']







  def __init__(	self    ,						_lowercase=250_112    ,						_lowercase=512    ,						_lowercase=64    ,						_lowercase=1_024    ,						_lowercase=8    ,						_lowercase=None    ,						_lowercase=6    ,						_lowercase=32    ,						_lowercase=128    ,						_lowercase=0.1    ,						_lowercase=1e-6    ,						_lowercase=1.0    ,						_lowercase="gated-gelu"    ,						_lowercase=True    ,						_lowercase=True    ,						_lowercase="T5Tokenizer"    ,						_lowercase=True    ,						_lowercase=0    ,						_lowercase=1    ,						_lowercase=0    ,						**_lowercase    ,						):
       super().__init__(
           is_encoder_decoder=snake_case__    ,						tokenizer_class=snake_case__    ,						tie_word_embeddings=snake_case__    ,						pad_token_id=snake_case__    ,						eos_token_id=snake_case__    ,						decoder_start_token_id=snake_case__    ,						**snake_case__    ,						)
       lowerCAmelCase_					:       Union[str, Any]    =		vocab_size
       lowerCAmelCase_					:       Tuple    =		d_model
       lowerCAmelCase_					:       Any    =		d_kv
       lowerCAmelCase_					:       Dict    =		d_ff
       lowerCAmelCase_					:       int    =		num_layers
       lowerCAmelCase_					:       Dict    =		(
           num_decoder_layers if num_decoder_layers is not None else self.num_layers
       )  # default = symmetry
       lowerCAmelCase_					:       Union[str, Any]    =		num_heads
       lowerCAmelCase_					:       Tuple    =		relative_attention_num_buckets
       lowerCAmelCase_					:       Union[str, Any]    =		relative_attention_max_distance
       lowerCAmelCase_					:       Optional[Any]    =		dropout_rate
       lowerCAmelCase_					:       int    =		layer_norm_epsilon
       lowerCAmelCase_					:       str    =		initializer_factor
       lowerCAmelCase_					:       Tuple    =		feed_forward_proj
       lowerCAmelCase_					:       List[Any]    =		use_cache

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

       if len(snake_case__						) > 1 and act_info[0] != "gated" or len(snake_case__						) > 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":
            lowerCAmelCase_					:       Optional[Any]    =		"""gelu_new"""







  @property
  def 	UpperCAmelCase__		(	self						):
       return self.d_model







  @property
  def 	UpperCAmelCase__		(	self						):
       return self.num_heads







  @property
  def 	UpperCAmelCase__		(	self						):
       return self.num_layers





class      lowercase__							(							__a  ):







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

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

       return common_inputs







  @property
  # Copied from transformers.models.t5.configuration_t5.T5OnnxConfig.default_onnx_opset
  def 	UpperCAmelCase__		(	self						):
       return 13







  @property
  def 	UpperCAmelCase__		(	self						):
       return 5e-4







from collections import OrderedDict
from typing import Any, Mapping, Optional, Union

from ...configuration_utils import PretrainedConfig
from ...feature_extraction_utils import FeatureExtractionMixin
from ...onnx import OnnxConfig
from ...onnx.utils import compute_effective_axis_dimension
from ...tokenization_utils_base import PreTrainedTokenizerBase
from ...utils import TensorType, logging


UpperCAmelCase_					:   Optional[Any] 							=						logging.get_logger(__name__)

UpperCAmelCase_					:   Any 							=						{
    """deepmind/language-perceiver""": """https://huggingface.co/deepmind/language-perceiver/resolve/main/config.json""",
    # See all Perceiver models at https://huggingface.co/models?filter=perceiver
}





class      lowercase__    (							__A  ):
  __UpperCamelCase	     =  """perceiver"""







  def __init__(	self    ,						_lowercase=256    ,						_lowercase=1_280    ,						_lowercase=768    ,						_lowercase=1    ,						_lowercase=26    ,						_lowercase=8    ,						_lowercase=8    ,						_lowercase=None    ,						_lowercase=None    ,						_lowercase="kv"    ,						_lowercase=1    ,						_lowercase=1    ,						_lowercase="gelu"    ,						_lowercase=0.1    ,						_lowercase=0.02    ,						_lowercase=1e-12    ,						_lowercase=True    ,						_lowercase=262    ,						_lowercase=2_048    ,						_lowercase=56    ,						_lowercase=[368, 496]    ,						_lowercase=16    ,						_lowercase=1_920    ,						_lowercase=16    ,						_lowercase=[1, 16, 224, 224]    ,						**_lowercase    ,						):
       super().__init__(**_lowercase						)

       lowerCAmelCase_					:       Optional[int]    =		num_latents
       lowerCAmelCase_					:       List[str]    =		d_latents
       lowerCAmelCase_					:       int    =		d_model
       lowerCAmelCase_					:       Dict    =		num_blocks
       lowerCAmelCase_					:       Union[str, Any]    =		num_self_attends_per_block
       lowerCAmelCase_					:       List[str]    =		num_self_attention_heads
       lowerCAmelCase_					:       List[str]    =		num_cross_attention_heads
       lowerCAmelCase_					:       List[Any]    =		qk_channels
       lowerCAmelCase_					:       Optional[Any]    =		v_channels
       lowerCAmelCase_					:       Optional[Any]    =		cross_attention_shape_for_attention
       lowerCAmelCase_					:       Optional[int]    =		self_attention_widening_factor
       lowerCAmelCase_					:       int    =		cross_attention_widening_factor
       lowerCAmelCase_					:       Union[str, Any]    =		hidden_act
       lowerCAmelCase_					:       int    =		attention_probs_dropout_prob
       lowerCAmelCase_					:       int    =		initializer_range
       lowerCAmelCase_					:       Optional[Any]    =		layer_norm_eps
       lowerCAmelCase_					:       Optional[Any]    =		use_query_residual
       # masked language modeling attributes
       lowerCAmelCase_					:       Tuple    =		vocab_size
       lowerCAmelCase_					:       List[Any]    =		max_position_embeddings
       # image classification attributes
       lowerCAmelCase_					:       List[Any]    =		image_size
       # flow attributes
       lowerCAmelCase_					:       Dict    =		train_size
       # multimodal autoencoding attributes
       lowerCAmelCase_					:       Optional[Any]    =		num_frames
       lowerCAmelCase_					:       int    =		audio_samples_per_frame
       lowerCAmelCase_					:       Any    =		samples_per_patch
       lowerCAmelCase_					:       Any    =		output_shape





class      lowercase__    (							__A  ):







  @property
  def 	UpperCAmelCase__		(	self						):
       if self.task == "multiple-choice":
            lowerCAmelCase_					:       Optional[Any]    =		{0: """batch""", 1: """choice""", 2: """sequence"""}
       else:
            lowerCAmelCase_					:       Optional[int]    =		{0: """batch""", 1: """sequence"""}
       return OrderedDict(
           [
               ("""inputs""", dynamic_axis),
               ("""attention_mask""", dynamic_axis),
           ]						)







  @property
  def 	UpperCAmelCase__		(	self						):
       return 1e-4







  def 	UpperCAmelCase__		(	self    ,						_lowercase    ,						_lowercase = -1    ,						_lowercase = -1    ,						_lowercase = -1    ,						_lowercase = False    ,						_lowercase = None    ,						_lowercase = 3    ,						_lowercase = 40    ,						_lowercase = 40    ,						):
       # copied from `transformers.onnx.config.OnnxConfig` and slightly altered/simplified

       if isinstance(_lowercase    ,						_lowercase						):
            # If dynamic axis (-1) we forward with a fixed dimension of 2 samples to avoid optimizations made by ONNX
            lowerCAmelCase_					:       Union[str, Any]    =		compute_effective_axis_dimension(
                _lowercase    ,						fixed_dimension=OnnxConfig.default_fixed_batch    ,						num_token_to_add=0						)
            # If dynamic axis (-1) we forward with a fixed dimension of 8 tokens to avoid optimizations made by ONNX
            lowerCAmelCase_					:       int    =		preprocessor.num_special_tokens_to_add(_lowercase						)
            lowerCAmelCase_					:       int    =		compute_effective_axis_dimension(
                _lowercase    ,						fixed_dimension=OnnxConfig.default_fixed_sequence    ,						num_token_to_add=_lowercase						)
            # Generate dummy inputs according to compute batch and sequence
            lowerCAmelCase_					:       Optional[int]    =		[""" """.join(["""a"""]						) * seq_length] * batch_size
            lowerCAmelCase_					:       Optional[Any]    =		dict(preprocessor(_lowercase    ,						return_tensors=_lowercase						)						)
            lowerCAmelCase_					:       Optional[Any]    =		inputs.pop("""input_ids"""						)
            return inputs
       elif isinstance(_lowercase    ,						_lowercase						) and preprocessor.model_input_names[0] == "pixel_values":
            # If dynamic axis (-1) we forward with a fixed dimension of 2 samples to avoid optimizations made by ONNX
            lowerCAmelCase_					:       Any    =		compute_effective_axis_dimension(_lowercase    ,						fixed_dimension=OnnxConfig.default_fixed_batch						)
            lowerCAmelCase_					:       str    =		self._generate_dummy_images(_lowercase    ,						_lowercase    ,						_lowercase    ,						_lowercase						)
            lowerCAmelCase_					:       List[str]    =		dict(preprocessor(images=_lowercase    ,						return_tensors=_lowercase						)						)
            lowerCAmelCase_					:       Tuple    =		inputs.pop("""pixel_values"""						)
            return inputs
       else:
            raise ValueError(
                """Unable to generate dummy inputs for the model. Please provide a tokenizer or a preprocessor."""						)
