


from typing import Optional, Tuple, Union

import tensorflow as tf

from ...activations_tf import ACTaFN
from ...file_utils import add_code_sample_docstrings, add_start_docstrings, add_start_docstrings_to_model_forward
from ...modeling_tf_outputs import (
    TFBaseModelOutputWithNoAttention,
    TFBaseModelOutputWithPoolingAndNoAttention,
    TFSequenceClassifierOutput,
)
from ...modeling_tf_utils import TFPreTrainedModel, TFSequenceClassificationLoss, keras_serializable, unpack_inputs
from ...tf_utils import shape_list
from ...utils import logging
from .configuration_regnet import RegNetConfig


__UpperCamelCase				:  Union[str, Any]      					=							logging.get_logger(__name__)

# General docstring
__UpperCamelCase				:  Any      					=							'RegNetConfig'

# Base docstring
__UpperCamelCase				:  int      					=							'facebook/regnet-y-040'
__UpperCamelCase				:  int      					=							[1, 1088, 7, 7]

# Image classification docstring
__UpperCamelCase				:  str      					=							'facebook/regnet-y-040'
__UpperCamelCase				:  int      					=							'tabby, tabby cat'

__UpperCamelCase				:  Optional[Any]      					=							[
    'facebook/regnet-y-040',
    # See all regnet models at https://huggingface.co/models?filter=regnet
]





class  lowerCAmelCase__(    tf.keras.layers.Layer						):






    '''simple docstring'''





    def __init__(	self				:   Union[str, Any]       ,   __snake_case				:   int       ,   __snake_case				:   int = 3       ,   __snake_case				:   int = 1       ,   __snake_case				:   int = 1       ,   __snake_case				:   Optional[str] = "relu"       ,   **__snake_case				:   List[str]       ,   ):





       '''simple docstring'''
       super().__init__(**__snake_case	)
       # The padding and conv has been verified in
       # https://colab.research.google.com/gist/sayakpaul/854bc10eeaf21c9ee2119e0b9f3841a7/scratchpad.ipynb
       UpperCAmelCase_							:      str						=   tf.keras.layers.ZeroPaddingaD(padding=kernel_size // 2	)
       UpperCAmelCase_							:      Optional[int]						=   tf.keras.layers.ConvaD(
           filters=__snake_case       ,   kernel_size=__snake_case       ,   strides=__snake_case       ,   padding='''VALID'''       ,   groups=__snake_case       ,   use_bias=__snake_case       ,   name='''convolution'''       ,   )
       UpperCAmelCase_							:      Optional[int]						=   tf.keras.layers.BatchNormalization(epsilon=1E-5       ,   momentum=0.9       ,   name='''normalization'''	)
       UpperCAmelCase_							:      Union[str, Any]						=   ACTaFN[activation] if activation is not None else tf.identity





    def 					_lowerCamelCase (	self				:   Optional[Any]       ,   __snake_case				:   List[Any]	):





       '''simple docstring'''
       UpperCAmelCase_							:      Dict						=   self.convolution(self.padding(__snake_case	)	)
       UpperCAmelCase_							:      List[Any]						=   self.normalization(__snake_case	)
       UpperCAmelCase_							:      List[Any]						=   self.activation(__snake_case	)
       return hidden_state





class  lowerCAmelCase__(    tf.keras.layers.Layer						):






    '''simple docstring'''





    def __init__(	self				:   Dict       ,   __snake_case				:   RegNetConfig       ,   **__snake_case				:   Optional[int]	):





       '''simple docstring'''
       super().__init__(**__snake_case	)
       UpperCAmelCase_							:      Any						=   config.num_channels
       UpperCAmelCase_							:      Tuple						=   TFRegNetConvLayer(
           out_channels=config.embedding_size       ,   kernel_size=3       ,   stride=2       ,   activation=config.hidden_act       ,   name='''embedder'''       ,   )





    def 					_lowerCamelCase (	self				:   Optional[Any]       ,   __snake_case				:   Any	):





       '''simple docstring'''
       UpperCAmelCase_							:      Any						=   shape_list(__snake_case	)[1]
       if tf.executing_eagerly() and num_channels != self.num_channels:
          raise ValueError(
              '''Make sure that the channel dimension of the pixel values match with the one set in the configuration.'''	)

       # When running on CPU, `tf.keras.layers.Conv2D` doesn't support `NCHW` format.
       # So change the input format from `NCHW` to `NHWC`.
       # shape = (batch_size, in_height, in_width, in_channels=num_channels)
       UpperCAmelCase_							:      Dict						=   tf.transpose(__snake_case       ,   perm=(0, 2, 3, 1)	)
       UpperCAmelCase_							:      Tuple						=   self.embedder(__snake_case	)
       return hidden_state





class  lowerCAmelCase__(    tf.keras.layers.Layer						):






    '''simple docstring'''





    def __init__(	self				:   List[str]       ,   __snake_case				:   int       ,   __snake_case				:   int = 2       ,   **__snake_case				:   int	):





       '''simple docstring'''
       super().__init__(**__snake_case	)
       UpperCAmelCase_							:      str						=   tf.keras.layers.ConvaD(
           filters=__snake_case       ,   kernel_size=1       ,   strides=__snake_case       ,   use_bias=__snake_case       ,   name='''convolution'''	)
       UpperCAmelCase_							:      Optional[int]						=   tf.keras.layers.BatchNormalization(epsilon=1E-5       ,   momentum=0.9       ,   name='''normalization'''	)





    def 					_lowerCamelCase (	self				:   Any       ,   __snake_case				:   tf.Tensor       ,   __snake_case				:   bool = False	):





       '''simple docstring'''
       return self.normalization(self.convolution(__snake_case	)       ,   training=__snake_case	)





class  lowerCAmelCase__(    tf.keras.layers.Layer						):






    '''simple docstring'''





    def __init__(	self				:   Any       ,   __snake_case				:   int       ,   __snake_case				:   int       ,   **__snake_case				:   Optional[Any]	):





       '''simple docstring'''
       super().__init__(**__snake_case	)
       UpperCAmelCase_							:      Tuple						=   tf.keras.layers.GlobalAveragePoolingaD(keepdims=__snake_case       ,   name='''pooler'''	)
       UpperCAmelCase_							:      Optional[Any]						=   [
           tf.keras.layers.ConvaD(filters=__snake_case       ,   kernel_size=1       ,   activation='''relu'''       ,   name='''attention.0'''	),
           tf.keras.layers.ConvaD(filters=__snake_case       ,   kernel_size=1       ,   activation='''sigmoid'''       ,   name='''attention.2'''	),
       ]





    def 					_lowerCamelCase (	self				:   List[str]       ,   __snake_case				:   Optional[Any]	):





       '''simple docstring'''
       UpperCAmelCase_							:      Any						=   self.pooler(__snake_case	)
       for layer_module in self.attention:
          UpperCAmelCase_							:      List[str]						=   layer_module(__snake_case	)
       UpperCAmelCase_							:      Any						=   hidden_state * pooled
       return hidden_state





class  lowerCAmelCase__(    tf.keras.layers.Layer						):






    '''simple docstring'''





    def __init__(	self				:   int       ,   __snake_case				:   RegNetConfig       ,   __snake_case				:   int       ,   __snake_case				:   int       ,   __snake_case				:   int = 1       ,   **__snake_case				:   Union[str, Any]	):





       '''simple docstring'''
       super().__init__(**__snake_case	)
       UpperCAmelCase_							:      Tuple						=   in_channels != out_channels or stride != 1
       UpperCAmelCase_							:      int						=   max(1       ,   out_channels // config.groups_width	)
       UpperCAmelCase_							:      List[Any]						=   (
           TFRegNetShortCut(__snake_case       ,   stride=__snake_case       ,   name='''shortcut'''	)
           if should_apply_shortcut
           else tf.keras.layers.Activation('''linear'''       ,   name='''shortcut'''	)
       )
       # `self.layers` instead of `self.layer` because that is a reserved argument.
       UpperCAmelCase_							:      List[Any]						=   [
           TFRegNetConvLayer(__snake_case       ,   kernel_size=1       ,   activation=config.hidden_act       ,   name='''layer.0'''	),
           TFRegNetConvLayer(
               __snake_case       ,   stride=__snake_case       ,   groups=__snake_case       ,   activation=config.hidden_act       ,   name='''layer.1'''	),
           TFRegNetConvLayer(__snake_case       ,   kernel_size=1       ,   activation=__snake_case       ,   name='''layer.2'''	),
       ]
       UpperCAmelCase_							:      List[Any]						=   ACTaFN[config.hidden_act]





    def 					_lowerCamelCase (	self				:   Union[str, Any]       ,   __snake_case				:   int	):





       '''simple docstring'''
       UpperCAmelCase_							:      Any						=   hidden_state
       for layer_module in self.layers:
          UpperCAmelCase_							:      List[str]						=   layer_module(__snake_case	)
       UpperCAmelCase_							:      Union[str, Any]						=   self.shortcut(__snake_case	)
       hidden_state += residual
       UpperCAmelCase_							:      Union[str, Any]						=   self.activation(__snake_case	)
       return hidden_state





class  lowerCAmelCase__(    tf.keras.layers.Layer						):






    '''simple docstring'''





    def __init__(	self				:   str       ,   __snake_case				:   RegNetConfig       ,   __snake_case				:   int       ,   __snake_case				:   int       ,   __snake_case				:   int = 1       ,   **__snake_case				:   int	):





       '''simple docstring'''
       super().__init__(**__snake_case	)
       UpperCAmelCase_							:      List[str]						=   in_channels != out_channels or stride != 1
       UpperCAmelCase_							:      List[Any]						=   max(1       ,   out_channels // config.groups_width	)
       UpperCAmelCase_							:      Union[str, Any]						=   (
           TFRegNetShortCut(__snake_case       ,   stride=__snake_case       ,   name='''shortcut'''	)
           if should_apply_shortcut
           else tf.keras.layers.Activation('''linear'''       ,   name='''shortcut'''	)
       )
       UpperCAmelCase_							:      Optional[int]						=   [
           TFRegNetConvLayer(__snake_case       ,   kernel_size=1       ,   activation=config.hidden_act       ,   name='''layer.0'''	),
           TFRegNetConvLayer(
               __snake_case       ,   stride=__snake_case       ,   groups=__snake_case       ,   activation=config.hidden_act       ,   name='''layer.1'''	),
           TFRegNetSELayer(__snake_case       ,   reduced_channels=int(round(in_channels / 4	)	)       ,   name='''layer.2'''	),
           TFRegNetConvLayer(__snake_case       ,   kernel_size=1       ,   activation=__snake_case       ,   name='''layer.3'''	),
       ]
       UpperCAmelCase_							:      List[str]						=   ACTaFN[config.hidden_act]





    def 					_lowerCamelCase (	self				:   str       ,   __snake_case				:   List[str]	):





       '''simple docstring'''
       UpperCAmelCase_							:      Optional[Any]						=   hidden_state
       for layer_module in self.layers:
          UpperCAmelCase_							:      List[str]						=   layer_module(__snake_case	)
       UpperCAmelCase_							:      Any						=   self.shortcut(__snake_case	)
       hidden_state += residual
       UpperCAmelCase_							:      List[str]						=   self.activation(__snake_case	)
       return hidden_state





class  lowerCAmelCase__(    tf.keras.layers.Layer						):






    '''simple docstring'''





    def __init__(	self				:   Optional[Any]       ,   __snake_case				:   RegNetConfig       ,   __snake_case				:   int       ,   __snake_case				:   int       ,   __snake_case				:   int = 2       ,   __snake_case				:   int = 2       ,   **__snake_case				:   int	):





       '''simple docstring'''
       super().__init__(**__snake_case	)

       UpperCAmelCase_							:      Optional[Any]						=   TFRegNetXLayer if config.layer_type == '''x''' else TFRegNetYLayer
       UpperCAmelCase_							:      List[str]						=   [
           # downsampling is done in the first layer with stride of 2
           layer(__snake_case       ,   __snake_case       ,   __snake_case       ,   stride=__snake_case       ,   name='''layers.0'''	),
           *[layer(__snake_case       ,   __snake_case       ,   __snake_case       ,   name=f'''layers.{i+1}'''	) for i in range(depth - 1	)],
       ]





    def 					_lowerCamelCase (	self				:   int       ,   __snake_case				:   List[Any]	):





       '''simple docstring'''
       for layer_module in self.layers:
          UpperCAmelCase_							:      Tuple						=   layer_module(__snake_case	)
       return hidden_state





class  lowerCAmelCase__(    tf.keras.layers.Layer						):






    '''simple docstring'''





    def __init__(	self				:   Tuple       ,   __snake_case				:   RegNetConfig       ,   **__snake_case				:   Any	):





       '''simple docstring'''
       super().__init__(**__snake_case	)
       UpperCAmelCase_							:      Optional[int]						=   []
       # based on `downsample_in_first_stage`, the first layer of the first stage may or may not downsample the input
       self.stages.append(
           TFRegNetStage(
               __snake_case       ,   config.embedding_size       ,   config.hidden_sizes[0]       ,   stride=2 if config.downsample_in_first_stage else 1       ,   depth=config.depths[0]       ,   name='''stages.0'''       ,   )	)
       UpperCAmelCase_							:      List[str]						=   zip(config.hidden_sizes       ,   config.hidden_sizes[1:]	)
       for i, ((in_channels, out_channels), depth) in enumerate(zip(__snake_case       ,   config.depths[1:]	)	):
          self.stages.append(TFRegNetStage(__snake_case       ,   __snake_case       ,   __snake_case       ,   depth=__snake_case       ,   name=f'''stages.{i+1}'''	)	)





    def 					_lowerCamelCase (	self				:   Dict       ,   __snake_case				:   tf.Tensor       ,   __snake_case				:   bool = False       ,   __snake_case				:   bool = True	):





       '''simple docstring'''
       UpperCAmelCase_							:      List[Any]						=   () if output_hidden_states else None

       for stage_module in self.stages:
          if output_hidden_states:
             UpperCAmelCase_							:      Optional[Any]						=   hidden_states + (hidden_state,)

          UpperCAmelCase_							:      Union[str, Any]						=   stage_module(__snake_case	)

       if output_hidden_states:
          UpperCAmelCase_							:      List[Any]						=   hidden_states + (hidden_state,)

       if not return_dict:
          return tuple(v for v in [hidden_state, hidden_states] if v is not None	)

       return TFBaseModelOutputWithNoAttention(last_hidden_state=__snake_case       ,   hidden_states=__snake_case	)





@keras_serializable
class  lowerCAmelCase__(    tf.keras.layers.Layer						):






    '''simple docstring'''





    A_  :     Dict			= RegNetConfig





    def __init__(	self				:   int       ,   __snake_case				:   List[str]       ,   **__snake_case				:   List[Any]	):





       '''simple docstring'''
       super().__init__(**__snake_case	)
       UpperCAmelCase_							:      List[Any]						=   config
       UpperCAmelCase_							:      int						=   TFRegNetEmbeddings(__snake_case       ,   name='''embedder'''	)
       UpperCAmelCase_							:      Union[str, Any]						=   TFRegNetEncoder(__snake_case       ,   name='''encoder'''	)
       UpperCAmelCase_							:      Union[str, Any]						=   tf.keras.layers.GlobalAveragePoolingaD(keepdims=__snake_case       ,   name='''pooler'''	)





    @unpack_inputs
    def 					_lowerCamelCase (	self				:   str       ,   __snake_case				:   tf.Tensor       ,   __snake_case				:   Optional[bool] = None       ,   __snake_case				:   Optional[bool] = None       ,   __snake_case				:   bool = False       ,   ):





       '''simple docstring'''
       UpperCAmelCase_							:      Optional[int]						=   (
           output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
       )
       UpperCAmelCase_							:      Any						=   return_dict if return_dict is not None else self.config.use_return_dict

       UpperCAmelCase_							:      Union[str, Any]						=   self.embedder(__snake_case       ,   training=__snake_case	)

       UpperCAmelCase_							:      Tuple						=   self.encoder(
           __snake_case       ,   output_hidden_states=__snake_case       ,   return_dict=__snake_case       ,   training=__snake_case	)

       UpperCAmelCase_							:      Any						=   encoder_outputs[0]
       UpperCAmelCase_							:      Union[str, Any]						=   self.pooler(__snake_case	)

       # Change to NCHW output format have uniformity in the modules
       UpperCAmelCase_							:      str						=   tf.transpose(__snake_case       ,   perm=(0, 3, 1, 2)	)
       UpperCAmelCase_							:      Dict						=   tf.transpose(__snake_case       ,   perm=(0, 3, 1, 2)	)

       # Change the other hidden state outputs to NCHW as well
       if output_hidden_states:
          UpperCAmelCase_							:      Tuple						=   tuple([tf.transpose(__snake_case       ,   perm=(0, 3, 1, 2)	) for h in encoder_outputs[1]]	)

       if not return_dict:
          return (last_hidden_state, pooled_output) + encoder_outputs[1:]

       return TFBaseModelOutputWithPoolingAndNoAttention(
           last_hidden_state=__snake_case       ,   pooler_output=__snake_case       ,   hidden_states=hidden_states if output_hidden_states else encoder_outputs.hidden_states       ,   )





class  lowerCAmelCase__(    snake_case__						):






    '''simple docstring'''





    A_  :     Optional[Any]			= RegNetConfig
    A_  :     Dict			= 'regnet'
    A_  :     str			= 'pixel_values'





    @property
    def 					_lowerCamelCase (	self				:   int	):





       '''simple docstring'''
       return {"pixel_values": tf.TensorSpec(shape=(None, self.config.num_channels, 224, 224)       ,   dtype=tf.floataa	)}





__UpperCamelCase				:  List[Any]      					=							R'\n    Parameters:\n    This model is a Tensorflow\n    [tf.keras.layers.Layer](https://www.tensorflow.org/api_docs/python/tf/keras/layers/Layer) sub-class. Use it as a\n    regular Tensorflow Module and refer to the Tensorflow documentation for all matter related to general usage and\n    behavior.\n        config ([`RegNetConfig`]): Model configuration class with all the parameters of the model.\n            Initializing with a config file does not load the weights associated with the model, only the\n            configuration. Check out the [`~TFPreTrainedModel.from_pretrained`] method to load the model weights.\n'

__UpperCamelCase				:  str      					=							R'\n    Args:\n        pixel_values (`tf.Tensor` of shape `(batch_size, num_channels, height, width)`):\n            Pixel values. Pixel values can be obtained using [`AutoImageProcessor`]. See\n            [`ConveNextImageProcessor.__call__`] for details.\n        output_hidden_states (`bool`, *optional*):\n            Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for\n            more detail.\n        return_dict (`bool`, *optional*):\n            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.\n'





@add_start_docstrings(
    'The bare RegNet model outputting raw features without any specific head on top.'    ,    snake_case__    ,    )
class  lowerCAmelCase__(    snake_case__						):






    '''simple docstring'''





    def __init__(	self				:   Optional[Any]       ,   __snake_case				:   RegNetConfig       ,   *__snake_case				:   Union[str, Any]       ,   **__snake_case				:   List[str]	):





       '''simple docstring'''
       super().__init__(__snake_case       ,   *__snake_case       ,   **__snake_case	)
       UpperCAmelCase_							:      str						=   TFRegNetMainLayer(__snake_case       ,   name='''regnet'''	)





    @unpack_inputs
    @add_start_docstrings_to_model_forward(__snake_case	)
    @add_code_sample_docstrings(
        checkpoint=_CHECKPOINT_FOR_DOC       ,   output_type=__snake_case       ,   config_class=_CONFIG_FOR_DOC       ,   modality='''vision'''       ,   expected_output=_EXPECTED_OUTPUT_SHAPE       ,   )
    def 					_lowerCamelCase (	self				:   List[str]       ,   __snake_case				:   tf.Tensor       ,   __snake_case				:   Optional[bool] = None       ,   __snake_case				:   Optional[bool] = None       ,   __snake_case				:   Tuple=False       ,   ):





       '''simple docstring'''
       UpperCAmelCase_							:      Dict						=   (
           output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
       )
       UpperCAmelCase_							:      Union[str, Any]						=   return_dict if return_dict is not None else self.config.use_return_dict

       UpperCAmelCase_							:      Dict						=   self.regnet(
           pixel_values=__snake_case       ,   output_hidden_states=__snake_case       ,   return_dict=__snake_case       ,   training=__snake_case       ,   )
       if not return_dict:
          return (outputs[0],) + outputs[1:]

       return TFBaseModelOutputWithPoolingAndNoAttention(
           last_hidden_state=outputs.last_hidden_state       ,   pooler_output=outputs.pooler_output       ,   hidden_states=outputs.hidden_states       ,   )





@add_start_docstrings(
    '\n    RegNet Model with an image classification head on top (a linear layer on top of the pooled features), e.g. for\n    ImageNet.\n    '    ,    snake_case__    ,    )
class  lowerCAmelCase__(    snake_case__    ,    snake_case__						):






    '''simple docstring'''





    def __init__(	self				:   Union[str, Any]       ,   __snake_case				:   RegNetConfig       ,   *__snake_case				:   List[str]       ,   **__snake_case				:   Optional[int]	):





       '''simple docstring'''
       super().__init__(__snake_case       ,   *__snake_case       ,   **__snake_case	)
       UpperCAmelCase_							:      Any						=   config.num_labels
       UpperCAmelCase_							:      List[Any]						=   TFRegNetMainLayer(__snake_case       ,   name='''regnet'''	)
       # classification head
       UpperCAmelCase_							:      Union[str, Any]						=   [
           tf.keras.layers.Flatten(),
           tf.keras.layers.Dense(config.num_labels       ,   name='''classifier.1'''	) if config.num_labels > 0 else tf.identity,
       ]





    @unpack_inputs
    @add_start_docstrings_to_model_forward(__snake_case	)
    @add_code_sample_docstrings(
        checkpoint=_IMAGE_CLASS_CHECKPOINT       ,   output_type=__snake_case       ,   config_class=_CONFIG_FOR_DOC       ,   expected_output=_IMAGE_CLASS_EXPECTED_OUTPUT       ,   )
    def 					_lowerCamelCase (	self				:   Tuple       ,   __snake_case				:   tf.Tensor = None       ,   __snake_case				:   tf.Tensor = None       ,   __snake_case				:   bool = None       ,   __snake_case				:   bool = None       ,   __snake_case				:   Tuple=False       ,   ):





       '''simple docstring'''
       UpperCAmelCase_							:      Optional[Any]						=   (
           output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
       )
       UpperCAmelCase_							:      Union[str, Any]						=   return_dict if return_dict is not None else self.config.use_return_dict

       UpperCAmelCase_							:      str						=   self.regnet(
           __snake_case       ,   output_hidden_states=__snake_case       ,   return_dict=__snake_case       ,   training=__snake_case	)

       UpperCAmelCase_							:      List[str]						=   outputs.pooler_output if return_dict else outputs[1]

       UpperCAmelCase_							:      List[Any]						=   self.classifier[0](__snake_case	)
       UpperCAmelCase_							:      Optional[int]						=   self.classifier[1](__snake_case	)

       UpperCAmelCase_							:      Optional[Any]						=   None if labels is None else self.hf_compute_loss(labels=__snake_case       ,   logits=__snake_case	)

       if not return_dict:
          UpperCAmelCase_							:      List[str]						=   (logits,) + outputs[2:]
          return ((loss,) + output) if loss is not None else output

       return TFSequenceClassifierOutput(loss=__snake_case       ,   logits=__snake_case       ,   hidden_states=outputs.hidden_states	)



import os
import re
import warnings
from shutil import copyfile
from typing import List, Optional, Tuple

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import is_sentencepiece_available, logging


if is_sentencepiece_available():
       from .tokenization_ta import TaTokenizer
else:
       __UpperCamelCase				:  Optional[int]      					=							None


__UpperCamelCase				:  Union[str, Any]      					=							logging.get_logger(__name__)

__UpperCamelCase				:  List[Any]      					=							{'vocab_file': 'spiece.model', 'tokenizer_file': 'tokenizer.json'}

__UpperCamelCase				:  Optional[int]      					=							{
    'vocab_file': {
        't5-small': 'https://huggingface.co/t5-small/resolve/main/spiece.model',
        't5-base': 'https://huggingface.co/t5-base/resolve/main/spiece.model',
        't5-large': 'https://huggingface.co/t5-large/resolve/main/spiece.model',
        't5-3b': 'https://huggingface.co/t5-3b/resolve/main/spiece.model',
        't5-11b': 'https://huggingface.co/t5-11b/resolve/main/spiece.model',
    },
    'tokenizer_file': {
        't5-small': 'https://huggingface.co/t5-small/resolve/main/tokenizer.json',
        't5-base': 'https://huggingface.co/t5-base/resolve/main/tokenizer.json',
        't5-large': 'https://huggingface.co/t5-large/resolve/main/tokenizer.json',
        't5-3b': 'https://huggingface.co/t5-3b/resolve/main/tokenizer.json',
        't5-11b': 'https://huggingface.co/t5-11b/resolve/main/tokenizer.json',
    },
}


# TODO(PVP) - this should be removed in Transformers v5
__UpperCamelCase				:  Optional[Any]      					=							{
    't5-small': 512,
    't5-base': 512,
    't5-large': 512,
    't5-3b': 512,
    't5-11b': 512,
}





class  lowerCAmelCase__(    snake_case__						):






    '''simple docstring'''





    A_  :     Optional[int]			= VOCAB_FILES_NAMES
    A_  :     List[Any]			= PRETRAINED_VOCAB_FILES_MAP
    A_  :     int			= PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
    A_  :     str			= ['input_ids', 'attention_mask']
    A_  :     int			= TaTokenizer

    A_  :     List[int]			= []





    def __init__(	self				:   Union[str, Any]       ,   __snake_case				:   Tuple=None       ,   __snake_case				:   List[Any]=None       ,   __snake_case				:   int="</s>"       ,   __snake_case				:   List[Any]="<unk>"       ,   __snake_case				:   Dict="<pad>"       ,   __snake_case				:   Tuple=100       ,   __snake_case				:   int=None       ,   **__snake_case				:   Any       ,   ):





       '''simple docstring'''
       # Add extra_ids to the special token list
       if extra_ids > 0 and additional_special_tokens is None:
          UpperCAmelCase_							:      Optional[int]						=   [f'''<extra_id_{i}>''' for i in range(__snake_case	)]
       elif extra_ids > 0 and additional_special_tokens is not None:
          # Check that we have the right number of extra special tokens
          UpperCAmelCase_							:      Any						=   len(set(filter(lambda __snake_case	: bool('''extra_id_''' in str(__snake_case	)	)       ,   __snake_case	)	)	)
          if extra_tokens != extra_ids:
             raise ValueError(
                 f'''Both extra_ids ({extra_ids}) and additional_special_tokens ({additional_special_tokens}) are'''
                 ''' provided to T5Tokenizer. In this case the additional_special_tokens must include the extra_ids'''
                 ''' tokens'''	)

       super().__init__(
           __snake_case       ,   tokenizer_file=__snake_case       ,   eos_token=__snake_case       ,   unk_token=__snake_case       ,   pad_token=__snake_case       ,   extra_ids=__snake_case       ,   additional_special_tokens=__snake_case       ,   **__snake_case       ,   )

       UpperCAmelCase_							:      str						=   vocab_file
       UpperCAmelCase_							:      List[str]						=   False if not self.vocab_file else True
       UpperCAmelCase_							:      Union[str, Any]						=   extra_ids





    @staticmethod
    def 					_lowerCamelCase (	__snake_case				:   Dict       ,   __snake_case				:   List[str]       ,   __snake_case				:   Tuple	):





       '''simple docstring'''
       if pretrained_model_name_or_path in TaTokenizerFast.max_model_input_sizes:
          UpperCAmelCase_							:      str						=   TaTokenizerFast.max_model_input_sizes[pretrained_model_name_or_path]
          if init_max_model_length is not None and init_max_model_length != max_model_length:
             return init_max_model_length
          elif init_max_model_length is None:
             warnings.warn(
                 '''This tokenizer was incorrectly instantiated with a model max length of'''
                 f''' {deprecated_max_model_length} which will be corrected in Transformers v5.\nFor now, this'''
                 ''' behavior is kept to avoid breaking backwards compatibility when padding/encoding with'''
                 ''' `truncation is True`.\n- Be aware that you SHOULD NOT rely on'''
                 f''' {pretrained_model_name_or_path} automatically truncating your input to'''
                 f''' {deprecated_max_model_length} when padding/encoding.\n- If you want to encode/pad to sequences'''
                 f''' longer than {deprecated_max_model_length} you can either instantiate this tokenizer with'''
                 ''' `model_max_length` or pass `max_length` when encoding/padding.\n- To avoid this warning, please'''
                 ''' instantiate this tokenizer with `model_max_length` set to your preferred value.'''       ,   __snake_case       ,   )

       return max_model_length





    def 					_lowerCamelCase (	self				:   Dict       ,   __snake_case				:   str       ,   __snake_case				:   Optional[str] = None	):





       '''simple docstring'''
       if not self.can_save_slow_tokenizer:
          raise ValueError(
              '''Your fast tokenizer does not have the necessary information to save the vocabulary for a slow '''
              '''tokenizer.'''	)

       if not os.path.isdir(__snake_case	):
          logger.error(f'''Vocabulary path ({save_directory}) should be a directory'''	)
          return
       UpperCAmelCase_							:      str						=   os.path.join(
           __snake_case       ,   (filename_prefix + '''-''' if filename_prefix else '''''') + VOCAB_FILES_NAMES['''vocab_file''']	)

       if os.path.abspath(self.vocab_file	) != os.path.abspath(__snake_case	):
          copyfile(self.vocab_file       ,   __snake_case	)
          logger.info(f'''Copy vocab file to {out_vocab_file}'''	)

       return (out_vocab_file,)





    def 					_lowerCamelCase (	self				:   List[str]       ,   __snake_case				:   List[int]       ,   __snake_case				:   Optional[List[int]] = None	):





       '''simple docstring'''
       UpperCAmelCase_							:      Optional[Any]						=   token_ids_a + [self.eos_token_id]
       if token_ids_a is None:
          return self.prefix_tokens + token_ids_a
       else:
          UpperCAmelCase_							:      int						=   token_ids_a + [self.eos_token_id]
          return self.prefix_tokens + token_ids_a + token_ids_a





    def 					_lowerCamelCase (	self				:   Dict       ,   __snake_case				:   List[int]       ,   __snake_case				:   Optional[List[int]] = None	):





       '''simple docstring'''
       UpperCAmelCase_							:      int						=   [self.eos_token_id]

       if token_ids_a is None:
          return len(token_ids_a + eos	) * [0]
       return len(token_ids_a + eos + token_ids_a + eos	) * [0]





    def 					_lowerCamelCase (	self				:   Tuple	):





       '''simple docstring'''
       return list(
           set(filter(lambda __snake_case	: bool(re.search(R'''<extra_id_\d+>'''       ,   __snake_case	)	) is not None       ,   self.additional_special_tokens	)	)	)





    def 					_lowerCamelCase (	self				:   Tuple	):





       '''simple docstring'''
       return [self.convert_tokens_to_ids(__snake_case	) for token in self.get_sentinel_tokens()]