

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


lowercase_									=   logging.get_logger(__name__)

lowercase_									=   {
    'speechbrain/m-ctc-t-large': 'https://huggingface.co/speechbrain/m-ctc-t-large/resolve/main/config.json',
    # See all M-CTC-T models at https://huggingface.co/models?filter=mctct
}





class  __lowerCAmelCase     (					SCREAMING_SNAKE_CASE							):
  _a									=  """mctct"""




  def __init__(				self							,   lowerCAmelCase=8_065							,   lowerCAmelCase=1_536							,   lowerCAmelCase=36							,   lowerCAmelCase=6_144							,   lowerCAmelCase=4							,   lowerCAmelCase=384							,   lowerCAmelCase=920							,   lowerCAmelCase=1e-5							,   lowerCAmelCase=0.3							,   lowerCAmelCase="relu"							,   lowerCAmelCase=0.02							,   lowerCAmelCase=0.3							,   lowerCAmelCase=0.3							,   lowerCAmelCase=1							,   lowerCAmelCase=0							,   lowerCAmelCase=2							,   lowerCAmelCase=1							,   lowerCAmelCase=0.3							,   lowerCAmelCase=1							,   lowerCAmelCase=(7,)							,   lowerCAmelCase=(3,)							,   lowerCAmelCase=80							,   lowerCAmelCase=1							,   lowerCAmelCase=None							,   lowerCAmelCase="sum"							,   lowerCAmelCase=False							,   **lowerCAmelCase							,   )  -> Dict:
        '''simple docstring'''






        super().__init__(**lowerCAmelCase							,   pad_token_id=lowerCAmelCase							,   bos_token_id=lowerCAmelCase							,   eos_token_id=lowerCAmelCase					)
        _lowercase	       =vocab_size
        _lowercase	       =hidden_size
        _lowercase	       =num_hidden_layers
        _lowercase	       =intermediate_size
        _lowercase	       =num_attention_heads
        _lowercase	       =attention_head_dim
        _lowercase	       =max_position_embeddings
        _lowercase	       =layer_norm_eps
        _lowercase	       =layerdrop
        _lowercase	       =hidden_act
        _lowercase	       =initializer_range
        _lowercase	       =hidden_dropout_prob
        _lowercase	       =attention_probs_dropout_prob
        _lowercase	       =pad_token_id
        _lowercase	       =bos_token_id
        _lowercase	       =eos_token_id
        _lowercase	       =conv_glu_dim
        _lowercase	       =conv_dropout
        _lowercase	       =num_conv_layers
        _lowercase	       =input_feat_per_channel
        _lowercase	       =input_channels
        _lowercase	       =conv_channels
        _lowercase	       =ctc_loss_reduction
        _lowercase	       =ctc_zero_infinity

        # prevents config testing fail with exporting to json
        _lowercase	       =list(lowerCAmelCase					)
        _lowercase	       =list(lowerCAmelCase					)

        if len(self.conv_kernel					) != self.num_conv_layers:
              raise ValueError(
                  'Configuration for convolutional module is incorrect. '
                  'It is required that `len(config.conv_kernel)` == `config.num_conv_layers` '
                  F'''but is `len(config.conv_kernel) = {len(self.conv_kernel					)}`, '''
                  F'''`config.num_conv_layers = {self.num_conv_layers}`.'''					)





import torch
import torch.nn as nn
from transformers.modeling_utils import ModuleUtilsMixin
from transformers.models.ta.modeling_ta import TaBlock, TaConfig, TaLayerNorm

from ...configuration_utils import ConfigMixin, register_to_config
from ...models import ModelMixin





class  __lowerCAmelCase     (					SCREAMING_SNAKE_CASE			,			SCREAMING_SNAKE_CASE			,			SCREAMING_SNAKE_CASE							):




  @register_to_config
  def __init__(				self							,   lowerCAmelCase							,   lowerCAmelCase							,   lowerCAmelCase							,   lowerCAmelCase							,   lowerCAmelCase							,   lowerCAmelCase							,   lowerCAmelCase							,   lowerCAmelCase							,   lowerCAmelCase							,   lowerCAmelCase = False							,   )  -> Tuple:
        '''simple docstring'''






        super().__init__()

        _lowercase	       =nn.Embedding(lowerCAmelCase							,   lowerCAmelCase					)

        _lowercase	       =nn.Embedding(lowerCAmelCase							,   lowerCAmelCase					)
        _lowercase	       =False

        _lowercase	       =nn.Dropout(p=lowerCAmelCase					)

        _lowercase	       =TaConfig(
            vocab_size=lowerCAmelCase							,   d_model=lowerCAmelCase							,   num_heads=lowerCAmelCase							,   d_kv=lowerCAmelCase							,   d_ff=lowerCAmelCase							,   dropout_rate=lowerCAmelCase							,   feed_forward_proj=lowerCAmelCase							,   is_decoder=lowerCAmelCase							,   is_encoder_decoder=lowerCAmelCase							,   )

        _lowercase	       =nn.ModuleList()
        for lyr_num in range(lowerCAmelCase					):
              _lowercase	       =TaBlock(lowerCAmelCase					)
              self.encoders.append(lowerCAmelCase					)

        _lowercase	       =TaLayerNorm(lowerCAmelCase					)
        _lowercase	       =nn.Dropout(p=lowerCAmelCase					)




  def   A__     (				self							,   lowerCAmelCase							,   lowerCAmelCase					)  -> Dict:
        '''simple docstring'''






        _lowercase	       =self.token_embedder(lowerCAmelCase					)

        _lowercase	       =encoder_input_tokens.shape[1]
        _lowercase	       =torch.arange(lowerCAmelCase							,   device=encoder_input_tokens.device					)
        x += self.position_encoding(lowerCAmelCase					)

        _lowercase	       =self.dropout_pre(lowerCAmelCase					)

        # inverted the attention mask
        _lowercase	       =encoder_input_tokens.size()
        _lowercase	       =self.get_extended_attention_mask(lowerCAmelCase							,   lowerCAmelCase					)

        for lyr in self.encoders:
              _lowercase	       =lyr(lowerCAmelCase							,   lowerCAmelCase					)[0]
        _lowercase	       =self.layer_norm(lowerCAmelCase					)

        return self.dropout_post(lowerCAmelCase					), encoder_inputs_mask


