
"""simple docstring"""





from dataclasses import dataclass
from typing import Optional

import torch
from torch import nn

from ..configuration_utils import ConfigMixin, register_to_config
from ..utils import BaseOutput
from .attention import BasicTransformerBlock
from .modeling_utils import ModelMixin
@dataclass
class 						SCREAMING_SNAKE_CASE_ (						__a ):




		"""simple docstring"""





		__lowercase							:  torch.FloatTensor



class 						SCREAMING_SNAKE_CASE_ (						__a     ,				__a ):




		"""simple docstring"""





		@register_to_config
		def __init__(     self							,  lowerCAmelCase__ = 1_6							,  lowerCAmelCase__ = 8_8							,  lowerCAmelCase__ = None							,  lowerCAmelCase__ = None							,  lowerCAmelCase__ = 1							,  lowerCAmelCase__ = 0.0							,  lowerCAmelCase__ = 3_2							,  lowerCAmelCase__ = None							,  lowerCAmelCase__ = False							,  lowerCAmelCase__ = None							,  lowerCAmelCase__ = "geglu"							,  lowerCAmelCase__ = True							,  lowerCAmelCase__ = True							,  ):
				super().__init__()
				__SCREAMING_SNAKE_CASE            = num_attention_heads
				__SCREAMING_SNAKE_CASE            = attention_head_dim
				__SCREAMING_SNAKE_CASE            = num_attention_heads * attention_head_dim

				__SCREAMING_SNAKE_CASE            = in_channels

				__SCREAMING_SNAKE_CASE            = torch.nn.GroupNorm(num_groups=lowerCAmelCase__							,  num_channels=lowerCAmelCase__							,  eps=1E-6							,  affine=lowerCAmelCase__)
				__SCREAMING_SNAKE_CASE            = nn.Linear(lowerCAmelCase__							,  lowerCAmelCase__)

				# 3. Define transformers blocks
				__SCREAMING_SNAKE_CASE            = nn.ModuleList(
				    [
				        BasicTransformerBlock(
				            lowerCAmelCase__							,  lowerCAmelCase__							,  lowerCAmelCase__							,  dropout=lowerCAmelCase__							,  cross_attention_dim=lowerCAmelCase__							,  activation_fn=lowerCAmelCase__							,  attention_bias=lowerCAmelCase__							,  double_self_attention=lowerCAmelCase__							,  norm_elementwise_affine=lowerCAmelCase__							,  )
				        for d in range(lowerCAmelCase__)
				    ])

				__SCREAMING_SNAKE_CASE            = nn.Linear(lowerCAmelCase__							,  lowerCAmelCase__)




		def 	snake_case_     (     self							,  lowerCAmelCase__							,  lowerCAmelCase__=None							,  lowerCAmelCase__=None							,  lowerCAmelCase__=None							,  lowerCAmelCase__=1							,  lowerCAmelCase__=None							,  lowerCAmelCase__ = True							,  ):
				__SCREAMING_SNAKE_CASE       ,__SCREAMING_SNAKE_CASE       ,__SCREAMING_SNAKE_CASE       ,__SCREAMING_SNAKE_CASE            = hidden_states.shape
				__SCREAMING_SNAKE_CASE            = batch_frames // num_frames

				__SCREAMING_SNAKE_CASE            = hidden_states

				__SCREAMING_SNAKE_CASE            = hidden_states[None, :].reshape(lowerCAmelCase__							,  lowerCAmelCase__							,  lowerCAmelCase__							,  lowerCAmelCase__							,  lowerCAmelCase__)
				__SCREAMING_SNAKE_CASE            = hidden_states.permute(0							,  2							,  1							,  3							,  4)

				__SCREAMING_SNAKE_CASE            = self.norm(lowerCAmelCase__)
				__SCREAMING_SNAKE_CASE            = hidden_states.permute(0							,  3							,  4							,  2							,  1).reshape(batch_size * height * width							,  lowerCAmelCase__							,  lowerCAmelCase__)

				__SCREAMING_SNAKE_CASE            = self.proj_in(lowerCAmelCase__)

				# 2. Blocks
				for block in self.transformer_blocks:
						__SCREAMING_SNAKE_CASE            = block(
						    lowerCAmelCase__							,  encoder_hidden_states=lowerCAmelCase__							,  timestep=lowerCAmelCase__							,  cross_attention_kwargs=lowerCAmelCase__							,  class_labels=lowerCAmelCase__							,  )

				# 3. Output
				__SCREAMING_SNAKE_CASE            = self.proj_out(lowerCAmelCase__)
				__SCREAMING_SNAKE_CASE            = (
				    hidden_states[None, None, :]
				    .reshape(lowerCAmelCase__							,  lowerCAmelCase__							,  lowerCAmelCase__							,  lowerCAmelCase__							,  lowerCAmelCase__)
				    .permute(0							,  3							,  4							,  1							,  2)
				    .contiguous()
				)
				__SCREAMING_SNAKE_CASE            = hidden_states.reshape(lowerCAmelCase__							,  lowerCAmelCase__							,  lowerCAmelCase__							,  lowerCAmelCase__)

				__SCREAMING_SNAKE_CASE            = hidden_states + residual

				if not return_dict:
						return (output,)

				return TransformerTemporalModelOutput(sample=lowerCAmelCase__)










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


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

lowerCamelCase__ :   List[str]					=							{
    'facebook/s2t-small-librispeech-asr': (
        'https://huggingface.co/facebook/s2t-small-librispeech-asr/resolve/main/config.json'
    ),
    # See all Speech2Text models at https://huggingface.co/models?filter=speech_to_text
}





class        lowerCamelCase_							(      _SCREAMING_SNAKE_CASE					):


 '''simple docstring'''







 lowercase_				    =    "speech_to_text"
 lowercase_				    =    ["past_key_values"]
 lowercase_				    =    {"num_attention_heads": "encoder_attention_heads", "hidden_size": "d_model"}



 def __init__(							self  :		Tuple				,				_lowerCAmelCase  :		List[Any]=10_000				,				_lowerCAmelCase  :		List[Any]=12				,				_lowerCAmelCase  :		Union[str, Any]=2_048				,				_lowerCAmelCase  :		Optional[int]=4				,				_lowerCAmelCase  :		Union[str, Any]=6				,				_lowerCAmelCase  :		Optional[int]=2_048				,				_lowerCAmelCase  :		Optional[Any]=4				,				_lowerCAmelCase  :		Any=0.0				,				_lowerCAmelCase  :		Optional[Any]=0.0				,				_lowerCAmelCase  :		List[str]=True				,				_lowerCAmelCase  :		List[Any]=True				,				_lowerCAmelCase  :		int="relu"				,				_lowerCAmelCase  :		Union[str, Any]=256				,				_lowerCAmelCase  :		List[str]=0.1				,				_lowerCAmelCase  :		str=0.0				,				_lowerCAmelCase  :		Tuple=0.0				,				_lowerCAmelCase  :		List[str]=0.02				,				_lowerCAmelCase  :		List[str]=2				,				_lowerCAmelCase  :		Tuple=True				,				_lowerCAmelCase  :		List[str]=1				,				_lowerCAmelCase  :		str=0				,				_lowerCAmelCase  :		str=2				,				_lowerCAmelCase  :		Union[str, Any]=6_000				,				_lowerCAmelCase  :		List[str]=1_024				,				_lowerCAmelCase  :		str=2				,				_lowerCAmelCase  :		Optional[Any]=(5, 5)				,				_lowerCAmelCase  :		str=1_024				,				_lowerCAmelCase  :		str=80				,				_lowerCAmelCase  :		Tuple=1				,				**_lowerCAmelCase  :		Any				,				):
       SCREAMING_SNAKE_CASE_							=			vocab_size
       SCREAMING_SNAKE_CASE_							=			d_model
       SCREAMING_SNAKE_CASE_							=			encoder_ffn_dim
       SCREAMING_SNAKE_CASE_							=			encoder_layers
       SCREAMING_SNAKE_CASE_							=			encoder_attention_heads
       SCREAMING_SNAKE_CASE_							=			decoder_ffn_dim
       SCREAMING_SNAKE_CASE_							=			decoder_layers
       SCREAMING_SNAKE_CASE_							=			decoder_attention_heads
       SCREAMING_SNAKE_CASE_							=			dropout
       SCREAMING_SNAKE_CASE_							=			attention_dropout
       SCREAMING_SNAKE_CASE_							=			activation_dropout
       SCREAMING_SNAKE_CASE_							=			activation_function
       SCREAMING_SNAKE_CASE_							=			init_std
       SCREAMING_SNAKE_CASE_							=			encoder_layerdrop
       SCREAMING_SNAKE_CASE_							=			decoder_layerdrop
       SCREAMING_SNAKE_CASE_							=			use_cache
       SCREAMING_SNAKE_CASE_							=			encoder_layers
       SCREAMING_SNAKE_CASE_							=			scale_embedding  # scale factor will be sqrt(d_model) if True
       SCREAMING_SNAKE_CASE_							=			max_source_positions
       SCREAMING_SNAKE_CASE_							=			max_target_positions
       SCREAMING_SNAKE_CASE_							=			num_conv_layers
       SCREAMING_SNAKE_CASE_							=			list(_lowerCAmelCase						)
       SCREAMING_SNAKE_CASE_							=			conv_channels
       SCREAMING_SNAKE_CASE_							=			input_feat_per_channel
       SCREAMING_SNAKE_CASE_							=			input_channels

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

       super().__init__(
           pad_token_id=_lowerCAmelCase				,				bos_token_id=_lowerCAmelCase				,				eos_token_id=_lowerCAmelCase				,				is_encoder_decoder=_lowerCAmelCase				,				decoder_start_token_id=_lowerCAmelCase				,				**_lowerCAmelCase				,				)