

from typing import Optional, Tuple, Union

import tensorflow as tf

from ...activations_tf import ACTaFN
from ...modeling_tf_outputs import (
    TFBaseModelOutputWithNoAttention,
    TFBaseModelOutputWithPoolingAndNoAttention,
    TFImageClassifierOutputWithNoAttention,
)
from ...modeling_tf_utils import TFPreTrainedModel, TFSequenceClassificationLoss, keras_serializable, unpack_inputs
from ...tf_utils import shape_list
from ...utils import add_code_sample_docstrings, add_start_docstrings, add_start_docstrings_to_model_forward, logging
from .configuration_resnet import ResNetConfig


lowerCAmelCase						:   Optional[int]										=    logging.get_logger(__name__)

# General docstring
lowerCAmelCase						:   Union[str, Any]										=    '''ResNetConfig'''

# Base docstring
lowerCAmelCase						:   List[Any]										=    '''microsoft/resnet-50'''
lowerCAmelCase						:   Optional[int]										=    [1, 2048, 7, 7]

# Image classification docstring
lowerCAmelCase						:   Optional[Any]										=    '''microsoft/resnet-50'''
lowerCAmelCase						:   List[Any]										=    '''tiger cat'''

lowerCAmelCase						:   List[str]										=    [
    '''microsoft/resnet-50''',
    # See all resnet models at https://huggingface.co/models?filter=resnet
]
class     SCREAMING_SNAKE_CASE__     (						tf.keras.layers.Layer		):





       '''simple docstring'''




       def __init__(						self       :						Optional[int]    ,		lowerCAmelCase__       :						int    ,		lowerCAmelCase__       :						int = 3    ,		lowerCAmelCase__       :						int = 1    ,		lowerCAmelCase__       :						str = "relu"    ,		**lowerCAmelCase__       :						Dict							)			->    None:
             super().__init__(**lowerCAmelCase__							)
             snake_case__					=   kernel_size // 2
             snake_case__					=   tf.keras.layers.ConvaD(
                 lowerCAmelCase__    ,		kernel_size=lowerCAmelCase__    ,		strides=lowerCAmelCase__    ,		padding="""valid"""    ,		use_bias=lowerCAmelCase__    ,		name="""convolution"""							)
             # Use same default momentum and epsilon as PyTorch equivalent
             snake_case__					=   tf.keras.layers.BatchNormalization(epsilon=1E-5    ,		momentum=0.9    ,		name="""normalization"""							)
             snake_case__					=   ACTaFN[activation] if activation is not None else tf.keras.layers.Activation("""linear"""							)

       def UpperCAmelCase_						(						self       :						List[str]    ,		lowerCAmelCase__       :						tf.Tensor							)			->    tf.Tensor:
             # Pad to match that done in the PyTorch Conv2D model
             snake_case__					=   snake_case__					=   (self.pad_value, self.pad_value)
             snake_case__					=   tf.pad(lowerCAmelCase__    ,		[(0, 0), height_pad, width_pad, (0, 0)]							)
             snake_case__					=   self.conv(lowerCAmelCase__							)
             return hidden_state

       def UpperCAmelCase_						(						self       :						str    ,		lowerCAmelCase__       :						tf.Tensor    ,		lowerCAmelCase__       :						bool = False							)			->    tf.Tensor:
             snake_case__					=   self.convolution(lowerCAmelCase__							)
             snake_case__					=   self.normalization(lowerCAmelCase__    ,		training=lowerCAmelCase__							)
             snake_case__					=   self.activation(lowerCAmelCase__							)
             return hidden_state



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





       '''simple docstring'''




       def __init__(						self       :						Optional[int]    ,		lowerCAmelCase__       :						ResNetConfig    ,		**lowerCAmelCase__       :						Optional[int]							)			->    None:
             super().__init__(**lowerCAmelCase__							)
             snake_case__					=   TFResNetConvLayer(
                 config.embedding_size    ,		kernel_size=7    ,		stride=2    ,		activation=config.hidden_act    ,		name="""embedder"""    ,		)
             snake_case__					=   tf.keras.layers.MaxPoolaD(pool_size=3    ,		strides=2    ,		padding="""valid"""    ,		name="""pooler"""							)
             snake_case__					=   config.num_channels

       def UpperCAmelCase_						(						self       :						Union[str, Any]    ,		lowerCAmelCase__       :						tf.Tensor    ,		lowerCAmelCase__       :						bool = False							)			->    tf.Tensor:
             snake_case__	,			snake_case__	,			snake_case__	,			snake_case__					=   shape_list(lowerCAmelCase__							)
             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."""							)
             snake_case__					=   pixel_values
             snake_case__					=   self.embedder(lowerCAmelCase__							)
             snake_case__					=   tf.pad(lowerCAmelCase__    ,		[[0, 0], [1, 1], [1, 1], [0, 0]]							)
             snake_case__					=   self.pooler(lowerCAmelCase__							)
             return hidden_state



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





       '''simple docstring'''




       def __init__(						self       :						Optional[Any]    ,		lowerCAmelCase__       :						int    ,		lowerCAmelCase__       :						int = 2    ,		**lowerCAmelCase__       :						Union[str, Any]							)			->    None:
             super().__init__(**lowerCAmelCase__							)
             snake_case__					=   tf.keras.layers.ConvaD(
                 lowerCAmelCase__    ,		kernel_size=1    ,		strides=lowerCAmelCase__    ,		use_bias=lowerCAmelCase__    ,		name="""convolution"""							)
             # Use same default momentum and epsilon as PyTorch equivalent
             snake_case__					=   tf.keras.layers.BatchNormalization(epsilon=1E-5    ,		momentum=0.9    ,		name="""normalization"""							)

       def UpperCAmelCase_						(						self       :						List[Any]    ,		lowerCAmelCase__       :						tf.Tensor    ,		lowerCAmelCase__       :						bool = False							)			->    tf.Tensor:
             snake_case__					=   x
             snake_case__					=   self.convolution(lowerCAmelCase__							)
             snake_case__					=   self.normalization(lowerCAmelCase__    ,		training=lowerCAmelCase__							)
             return hidden_state



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





       '''simple docstring'''




       def __init__(						self       :						Optional[int]    ,		lowerCAmelCase__       :						int    ,		lowerCAmelCase__       :						int    ,		lowerCAmelCase__       :						int = 1    ,		lowerCAmelCase__       :						str = "relu"    ,		**lowerCAmelCase__       :						str							)			->    None:
             super().__init__(**lowerCAmelCase__							)
             snake_case__					=   in_channels != out_channels or stride != 1
             snake_case__					=   TFResNetConvLayer(lowerCAmelCase__    ,		stride=lowerCAmelCase__    ,		name="""layer.0"""							)
             snake_case__					=   TFResNetConvLayer(lowerCAmelCase__    ,		activation=lowerCAmelCase__    ,		name="""layer.1"""							)
             snake_case__					=   (
                 TFResNetShortCut(lowerCAmelCase__    ,		stride=lowerCAmelCase__    ,		name="""shortcut"""							)
                 if should_apply_shortcut
                 else tf.keras.layers.Activation("""linear"""    ,		name="""shortcut"""							)
             )
             snake_case__					=   ACTaFN[activation]

       def UpperCAmelCase_						(						self       :						List[Any]    ,		lowerCAmelCase__       :						tf.Tensor    ,		lowerCAmelCase__       :						bool = False							)			->    tf.Tensor:
             snake_case__					=   hidden_state
             snake_case__					=   self.conva(lowerCAmelCase__    ,		training=lowerCAmelCase__							)
             snake_case__					=   self.conva(lowerCAmelCase__    ,		training=lowerCAmelCase__							)
             snake_case__					=   self.shortcut(lowerCAmelCase__    ,		training=lowerCAmelCase__							)
             hidden_state += residual
             snake_case__					=   self.activation(lowerCAmelCase__							)
             return hidden_state



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





       '''simple docstring'''




       def __init__(						self       :						Union[str, Any]    ,		lowerCAmelCase__       :						int    ,		lowerCAmelCase__       :						int    ,		lowerCAmelCase__       :						int = 1    ,		lowerCAmelCase__       :						str = "relu"    ,		lowerCAmelCase__       :						int = 4    ,		**lowerCAmelCase__       :						Tuple    ,		)			->    None:
             super().__init__(**lowerCAmelCase__							)
             snake_case__					=   in_channels != out_channels or stride != 1
             snake_case__					=   out_channels // reduction
             snake_case__					=   TFResNetConvLayer(lowerCAmelCase__    ,		kernel_size=1    ,		name="""layer.0"""							)
             snake_case__					=   TFResNetConvLayer(lowerCAmelCase__    ,		stride=lowerCAmelCase__    ,		name="""layer.1"""							)
             snake_case__					=   TFResNetConvLayer(lowerCAmelCase__    ,		kernel_size=1    ,		activation=lowerCAmelCase__    ,		name="""layer.2"""							)
             snake_case__					=   (
                 TFResNetShortCut(lowerCAmelCase__    ,		stride=lowerCAmelCase__    ,		name="""shortcut"""							)
                 if should_apply_shortcut
                 else tf.keras.layers.Activation("""linear"""    ,		name="""shortcut"""							)
             )
             snake_case__					=   ACTaFN[activation]

       def UpperCAmelCase_						(						self       :						Tuple    ,		lowerCAmelCase__       :						tf.Tensor    ,		lowerCAmelCase__       :						bool = False							)			->    tf.Tensor:
             snake_case__					=   hidden_state
             snake_case__					=   self.conva(lowerCAmelCase__    ,		training=lowerCAmelCase__							)
             snake_case__					=   self.conva(lowerCAmelCase__    ,		training=lowerCAmelCase__							)
             snake_case__					=   self.conva(lowerCAmelCase__    ,		training=lowerCAmelCase__							)
             snake_case__					=   self.shortcut(lowerCAmelCase__    ,		training=lowerCAmelCase__							)
             hidden_state += residual
             snake_case__					=   self.activation(lowerCAmelCase__							)
             return hidden_state



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





       '''simple docstring'''




       def __init__(						self       :						List[str]    ,		lowerCAmelCase__       :						ResNetConfig    ,		lowerCAmelCase__       :						int    ,		lowerCAmelCase__       :						int    ,		lowerCAmelCase__       :						int = 2    ,		lowerCAmelCase__       :						int = 2    ,		**lowerCAmelCase__       :						Dict							)			->    None:
             super().__init__(**lowerCAmelCase__							)

             snake_case__					=   TFResNetBottleNeckLayer if config.layer_type == """bottleneck""" else TFResNetBasicLayer

             snake_case__					=   [layer(lowerCAmelCase__    ,		lowerCAmelCase__    ,		stride=lowerCAmelCase__    ,		activation=config.hidden_act    ,		name="""layers.0"""							)]
             layers += [
                 layer(lowerCAmelCase__    ,		lowerCAmelCase__    ,		activation=config.hidden_act    ,		name=f'''layers.{i + 1}'''							)
                 for i in range(depth - 1							)
             ]
             snake_case__					=   layers

       def UpperCAmelCase_						(						self       :						Union[str, Any]    ,		lowerCAmelCase__       :						tf.Tensor    ,		lowerCAmelCase__       :						bool = False							)			->    tf.Tensor:
             for layer in self.stage_layers:
                   snake_case__					=   layer(lowerCAmelCase__    ,		training=lowerCAmelCase__							)
             return hidden_state



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





       '''simple docstring'''




       def __init__(						self       :						Union[str, Any]    ,		lowerCAmelCase__       :						ResNetConfig    ,		**lowerCAmelCase__       :						Optional[Any]							)			->    None:
             super().__init__(**lowerCAmelCase__							)
             # based on `downsample_in_first_stage` the first layer of the first stage may or may not downsample the input
             snake_case__					=   [
                 TFResNetStage(
                     lowerCAmelCase__    ,		config.embedding_size    ,		config.hidden_sizes[0]    ,		stride=2 if config.downsample_in_first_stage else 1    ,		depth=config.depths[0]    ,		name="""stages.0"""    ,		)
             ]
             for i, (in_channels, out_channels, depth) in enumerate(
                 zip(config.hidden_sizes    ,		config.hidden_sizes[1:]    ,		config.depths[1:]							)							):
                   self.stages.append(TFResNetStage(lowerCAmelCase__    ,		lowerCAmelCase__    ,		lowerCAmelCase__    ,		depth=lowerCAmelCase__    ,		name=f'''stages.{i + 1}'''							)							)

       def UpperCAmelCase_						(						self       :						Optional[int]    ,		lowerCAmelCase__       :						tf.Tensor    ,		lowerCAmelCase__       :						bool = False    ,		lowerCAmelCase__       :						bool = True    ,		lowerCAmelCase__       :						bool = False    ,		)			->    TFBaseModelOutputWithNoAttention:
             snake_case__					=   () if output_hidden_states else None

             for stage_module in self.stages:
                   if output_hidden_states:
                         snake_case__					=   hidden_states + (hidden_state,)

                   snake_case__					=   stage_module(lowerCAmelCase__    ,		training=lowerCAmelCase__							)

             if output_hidden_states:
                   snake_case__					=   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=lowerCAmelCase__    ,		hidden_states=lowerCAmelCase__							)



class     SCREAMING_SNAKE_CASE__     (						__a		):





       '''simple docstring'''




       UpperCamelCase__ :     int				    =       ResNetConfig
       UpperCamelCase__ :     Any				    =       '''resnet'''
       UpperCamelCase__ :     str				    =       '''pixel_values'''

       @property
       def UpperCAmelCase_						(						self       :						Dict							)			->    Tuple:
             return {"pixel_values": tf.TensorSpec(shape=(None, self.config.num_channels, 224, 224)    ,		dtype=tf.floataa							)}



lowerCAmelCase						:   int										=    r'''
    This model is a TensorFlow
    [tf.keras.layers.Layer](https://www.tensorflow.org/api_docs/python/tf/keras/layers/Layer) sub-class. Use it as a
    regular TensorFlow Module and refer to the TensorFlow documentation for all matter related to general usage and
    behavior.

    Parameters:
        config ([`ResNetConfig`]): Model configuration class with all the parameters of the model.
            Initializing with a config file does not load the weights associated with the model, only the
            configuration. Check out the [`~TFPreTrainedModel.from_pretrained`] method to load the model weights.
'''


lowerCAmelCase						:   List[str]										=    r'''
    Args:
        pixel_values (`tf.Tensor` of shape `(batch_size, num_channels, height, width)`):
            Pixel values. Pixel values can be obtained using [`AutoImageProcessor`]. See
            [`ConvNextImageProcessor.__call__`] for details.

        output_hidden_states (`bool`, *optional*):
            Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
            more detail.
        return_dict (`bool`, *optional*):
            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
'''
@keras_serializable
class     SCREAMING_SNAKE_CASE__     (						tf.keras.layers.Layer		):





       '''simple docstring'''




       UpperCamelCase__ :     List[Any]				    =       ResNetConfig

       def __init__(						self       :						Optional[Any]    ,		lowerCAmelCase__       :						ResNetConfig    ,		**lowerCAmelCase__       :						List[str]							)			->    None:
             super().__init__(**lowerCAmelCase__							)
             snake_case__					=   config
             snake_case__					=   TFResNetEmbeddings(lowerCAmelCase__    ,		name="""embedder"""							)
             snake_case__					=   TFResNetEncoder(lowerCAmelCase__    ,		name="""encoder"""							)
             snake_case__					=   tf.keras.layers.GlobalAveragePoolingaD(keepdims=lowerCAmelCase__							)

       @unpack_inputs
       def UpperCAmelCase_						(						self       :						Dict    ,		lowerCAmelCase__       :						tf.Tensor    ,		lowerCAmelCase__       :						Optional[bool] = None    ,		lowerCAmelCase__       :						Optional[bool] = None    ,		lowerCAmelCase__       :						bool = False    ,		)			->    Union[Tuple[tf.Tensor], TFBaseModelOutputWithPoolingAndNoAttention]:
             snake_case__					=   (
                 output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
             )
             snake_case__					=   return_dict if return_dict is not None else self.config.use_return_dict

             # TF 2.0 image layers can't use NCHW format when running on CPU.
             # We transpose to NHWC format and then transpose back after the full forward pass.
             # (batch_size, num_channels, height, width) -> (batch_size, height, width, num_channels)
             snake_case__					=   tf.transpose(lowerCAmelCase__    ,		perm=[0, 2, 3, 1]							)
             snake_case__					=   self.embedder(lowerCAmelCase__    ,		training=lowerCAmelCase__							)

             snake_case__					=   self.encoder(
                 lowerCAmelCase__    ,		output_hidden_states=lowerCAmelCase__    ,		return_dict=lowerCAmelCase__    ,		training=lowerCAmelCase__							)

             snake_case__					=   encoder_outputs[0]

             snake_case__					=   self.pooler(lowerCAmelCase__							)

             # Transpose all the outputs to the NCHW format
             # (batch_size, height, width, num_channels) -> (batch_size, num_channels, height, width)
             snake_case__					=   tf.transpose(lowerCAmelCase__    ,		(0, 3, 1, 2)							)
             snake_case__					=   tf.transpose(lowerCAmelCase__    ,		(0, 3, 1, 2)							)
             snake_case__					=   ()
             for hidden_state in encoder_outputs[1:]:
                   snake_case__					=   hidden_states + tuple(tf.transpose(lowerCAmelCase__    ,		(0, 3, 1, 2)							) for h in hidden_state							)

             if not return_dict:
                   return (last_hidden_state, pooled_output) + hidden_states

             snake_case__					=   hidden_states if output_hidden_states else None

             return TFBaseModelOutputWithPoolingAndNoAttention(
                 last_hidden_state=lowerCAmelCase__    ,		pooler_output=lowerCAmelCase__    ,		hidden_states=lowerCAmelCase__    ,		)



@add_start_docstrings(
    '''The bare ResNet model outputting raw features without any specific head on top.''' ,	__a ,	)
class     SCREAMING_SNAKE_CASE__     (						__a		):





       '''simple docstring'''




       def __init__(						self       :						Optional[int]    ,		lowerCAmelCase__       :						ResNetConfig    ,		**lowerCAmelCase__       :						int							)			->    None:
             super().__init__(lowerCAmelCase__    ,		**lowerCAmelCase__							)
             snake_case__					=   TFResNetMainLayer(config=lowerCAmelCase__    ,		name="""resnet"""							)

       @add_start_docstrings_to_model_forward(lowerCAmelCase__							)
       @add_code_sample_docstrings(
           checkpoint=_CHECKPOINT_FOR_DOC    ,		output_type=lowerCAmelCase__    ,		config_class=_CONFIG_FOR_DOC    ,		modality="""vision"""    ,		expected_output=_EXPECTED_OUTPUT_SHAPE    ,		)
       @unpack_inputs
       def UpperCAmelCase_						(						self       :						Dict    ,		lowerCAmelCase__       :						tf.Tensor    ,		lowerCAmelCase__       :						Optional[bool] = None    ,		lowerCAmelCase__       :						Optional[bool] = None    ,		lowerCAmelCase__       :						bool = False    ,		)			->    Union[Tuple[tf.Tensor], TFBaseModelOutputWithPoolingAndNoAttention]:
             snake_case__					=   (
                 output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
             )
             snake_case__					=   return_dict if return_dict is not None else self.config.use_return_dict

             snake_case__					=   self.resnet(
                 pixel_values=lowerCAmelCase__    ,		output_hidden_states=lowerCAmelCase__    ,		return_dict=lowerCAmelCase__    ,		training=lowerCAmelCase__    ,		)
             return resnet_outputs



@add_start_docstrings(
    '''
    ResNet Model with an image classification head on top (a linear layer on top of the pooled features), e.g. for
    ImageNet.
    ''' ,	__a ,	)
class     SCREAMING_SNAKE_CASE__     (						__a ,	__a		):





       '''simple docstring'''




       def __init__(						self       :						Optional[Any]    ,		lowerCAmelCase__       :						ResNetConfig    ,		**lowerCAmelCase__       :						str							)			->    None:
             super().__init__(lowerCAmelCase__    ,		**lowerCAmelCase__							)
             snake_case__					=   config.num_labels
             snake_case__					=   TFResNetMainLayer(lowerCAmelCase__    ,		name="""resnet"""							)
             # classification head
             snake_case__					=   (
                 tf.keras.layers.Dense(config.num_labels    ,		name="""classifier.1"""							)
                 if config.num_labels > 0
                 else tf.keras.layers.Activation("""linear"""    ,		name="""classifier.1"""							)
             )

       def UpperCAmelCase_						(						self       :						List[str]    ,		lowerCAmelCase__       :						tf.Tensor							)			->    tf.Tensor:
             snake_case__					=   tf.keras.layers.Flatten()(lowerCAmelCase__							)
             snake_case__					=   self.classifier_layer(lowerCAmelCase__							)
             return logits

       @add_start_docstrings_to_model_forward(lowerCAmelCase__							)
       @add_code_sample_docstrings(
           checkpoint=_IMAGE_CLASS_CHECKPOINT    ,		output_type=lowerCAmelCase__    ,		config_class=_CONFIG_FOR_DOC    ,		expected_output=_IMAGE_CLASS_EXPECTED_OUTPUT    ,		)
       @unpack_inputs
       def UpperCAmelCase_						(						self       :						List[Any]    ,		lowerCAmelCase__       :						tf.Tensor = None    ,		lowerCAmelCase__       :						tf.Tensor = None    ,		lowerCAmelCase__       :						bool = None    ,		lowerCAmelCase__       :						bool = None    ,		lowerCAmelCase__       :						bool = False    ,		)			->    Union[Tuple[tf.Tensor], TFImageClassifierOutputWithNoAttention]:
             snake_case__					=   return_dict if return_dict is not None else self.config.use_return_dict

             snake_case__					=   self.resnet(
                 lowerCAmelCase__    ,		output_hidden_states=lowerCAmelCase__    ,		return_dict=lowerCAmelCase__    ,		training=lowerCAmelCase__							)

             snake_case__					=   outputs.pooler_output if return_dict else outputs[1]

             snake_case__					=   self.classifier(lowerCAmelCase__							)

             snake_case__					=   None if labels is None else self.hf_compute_loss(lowerCAmelCase__    ,		lowerCAmelCase__							)

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

             return TFImageClassifierOutputWithNoAttention(loss=lowerCAmelCase__    ,		logits=lowerCAmelCase__    ,		hidden_states=outputs.hidden_states							)









import functools
import operator

from ...configuration_utils import PretrainedConfig
from ...utils import logging


lowerCAmelCase						:   Dict										=    logging.get_logger(__name__)

lowerCAmelCase						:   str										=    {
    '''facebook/hubert-base-ls960''': '''https://huggingface.co/facebook/hubert-base-ls960/resolve/main/config.json''',
    # See all Hubert models at https://huggingface.co/models?filter=hubert
}
class     SCREAMING_SNAKE_CASE__     (						__a		):





       '''simple docstring'''




       UpperCamelCase__ :     Tuple				    =       '''hubert'''

       def __init__(						self       :						Union[str, Any]    ,		lowerCAmelCase__       :						List[Any]=32    ,		lowerCAmelCase__       :						Any=768    ,		lowerCAmelCase__       :						List[Any]=12    ,		lowerCAmelCase__       :						Tuple=12    ,		lowerCAmelCase__       :						Optional[int]=3072    ,		lowerCAmelCase__       :						Dict="gelu"    ,		lowerCAmelCase__       :						List[str]=0.1    ,		lowerCAmelCase__       :						str=0.1    ,		lowerCAmelCase__       :						List[str]=0.1    ,		lowerCAmelCase__       :						int=True    ,		lowerCAmelCase__       :						Tuple=0.0    ,		lowerCAmelCase__       :						Union[str, Any]=0.1    ,		lowerCAmelCase__       :						Dict=0.1    ,		lowerCAmelCase__       :						int=0.02    ,		lowerCAmelCase__       :						Optional[int]=1E-5    ,		lowerCAmelCase__       :						List[str]="group"    ,		lowerCAmelCase__       :						List[str]="gelu"    ,		lowerCAmelCase__       :						Any=(512, 512, 512, 512, 512, 512, 512)    ,		lowerCAmelCase__       :						str=(5, 2, 2, 2, 2, 2, 2)    ,		lowerCAmelCase__       :						Union[str, Any]=(10, 3, 3, 3, 3, 2, 2)    ,		lowerCAmelCase__       :						Optional[Any]=False    ,		lowerCAmelCase__       :						Dict=128    ,		lowerCAmelCase__       :						List[Any]=16    ,		lowerCAmelCase__       :						Optional[Any]=False    ,		lowerCAmelCase__       :						Optional[int]=True    ,		lowerCAmelCase__       :						List[Any]=0.05    ,		lowerCAmelCase__       :						Any=10    ,		lowerCAmelCase__       :						Dict=2    ,		lowerCAmelCase__       :						Dict=0.0    ,		lowerCAmelCase__       :						Tuple=10    ,		lowerCAmelCase__       :						List[str]=0    ,		lowerCAmelCase__       :						int="sum"    ,		lowerCAmelCase__       :						Optional[Any]=False    ,		lowerCAmelCase__       :						List[Any]=False    ,		lowerCAmelCase__       :						int=256    ,		lowerCAmelCase__       :						List[Any]=0    ,		lowerCAmelCase__       :						Union[str, Any]=1    ,		lowerCAmelCase__       :						Tuple=2    ,		**lowerCAmelCase__       :						str    ,		)			->    Union[str, Any]:
             super().__init__(**lowerCAmelCase__    ,		pad_token_id=lowerCAmelCase__    ,		bos_token_id=lowerCAmelCase__    ,		eos_token_id=lowerCAmelCase__							)
             snake_case__					=   hidden_size
             snake_case__					=   feat_extract_norm
             snake_case__					=   feat_extract_activation
             snake_case__					=   list(lowerCAmelCase__							)
             snake_case__					=   list(lowerCAmelCase__							)
             snake_case__					=   list(lowerCAmelCase__							)
             snake_case__					=   conv_bias
             snake_case__					=   num_conv_pos_embeddings
             snake_case__					=   num_conv_pos_embedding_groups
             snake_case__					=   len(self.conv_dim							)
             snake_case__					=   num_hidden_layers
             snake_case__					=   intermediate_size
             snake_case__					=   hidden_act
             snake_case__					=   num_attention_heads
             snake_case__					=   hidden_dropout
             snake_case__					=   attention_dropout
             snake_case__					=   activation_dropout
             snake_case__					=   feat_proj_layer_norm
             snake_case__					=   feat_proj_dropout
             snake_case__					=   final_dropout
             snake_case__					=   layerdrop
             snake_case__					=   layer_norm_eps
             snake_case__					=   initializer_range
             snake_case__					=   vocab_size
             snake_case__					=   do_stable_layer_norm
             snake_case__					=   use_weighted_layer_sum
             snake_case__					=   classifier_proj_size

             if (
                 (len(self.conv_stride							) != self.num_feat_extract_layers)
                 or (len(self.conv_kernel							) != self.num_feat_extract_layers)
                 or (len(self.conv_dim							) != self.num_feat_extract_layers)
             ):
                   raise ValueError(
                       """Configuration for convolutional layers is incorrect. It is required that `len(config.conv_dim)` =="""
                       """ `len(config.conv_stride)` == `len(config.conv_kernel)`, but is `len(config.conv_dim) ="""
                       f''' {len(self.conv_dim							)}`, `len(config.conv_stride) = {len(self.conv_stride							)}`,'''
                       f''' `len(config.conv_kernel) = {len(self.conv_kernel							)}`.'''							)

             # fine-tuning config parameters for SpecAugment: https://arxiv.org/abs/1904.08779
             snake_case__					=   apply_spec_augment
             snake_case__					=   mask_time_prob
             snake_case__					=   mask_time_length
             snake_case__					=   mask_time_min_masks
             snake_case__					=   mask_feature_prob
             snake_case__					=   mask_feature_length
             snake_case__					=   mask_feature_min_masks

             # ctc loss
             snake_case__					=   ctc_loss_reduction
             snake_case__					=   ctc_zero_infinity

       @property
       def UpperCAmelCase_						(						self       :						Union[str, Any]							)			->    Tuple:
             return functools.reduce(operator.mul    ,		self.conv_stride    ,		1							)






