'''simple docstring'''




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


__UpperCAmelCase					=logging.get_logger(__name__)

__UpperCAmelCase					={
    "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        a__ (  UpperCAmelCase__					):
     lowerCamelCase    :	int				="speech_to_text"
     lowerCamelCase    :	Any				=["past_key_values"]
     lowerCamelCase    :	str				={"num_attention_heads": "encoder_attention_heads", "hidden_size": "d_model"}






     def __init__(					self						:						Dict    ,							a						:						List[Any]=1_00_00    ,							a						:						List[Any]=12    ,							a						:						List[str]=20_48    ,							a						:						Optional[Any]=4    ,							a						:						str=6    ,							a						:						str=20_48    ,							a						:						int=4    ,							a						:						Union[str, Any]=0.0    ,							a						:						int=0.0    ,							a						:						Tuple=True    ,							a						:						List[str]=True    ,							a						:						Tuple="relu"    ,							a						:						Union[str, Any]=2_56    ,							a						:						Any=0.1    ,							a						:						Optional[Any]=0.0    ,							a						:						Tuple=0.0    ,							a						:						Optional[int]=0.02    ,							a						:						List[str]=2    ,							a						:						Union[str, Any]=True    ,							a						:						int=1    ,							a						:						List[str]=0    ,							a						:						List[str]=2    ,							a						:						List[str]=60_00    ,							a						:						Optional[Any]=10_24    ,							a						:						Dict=2    ,							a						:						Any=(5, 5)    ,							a						:						Tuple=10_24    ,							a						:						Optional[int]=80    ,							a						:						Optional[int]=1    ,							**a						:						List[Any]    ,							):





         """simple docstring"""



         __lowerCamelCase            =    vocab_size
         __lowerCamelCase            =    d_model
         __lowerCamelCase            =    encoder_ffn_dim
         __lowerCamelCase            =    encoder_layers
         __lowerCamelCase            =    encoder_attention_heads
         __lowerCamelCase            =    decoder_ffn_dim
         __lowerCamelCase            =    decoder_layers
         __lowerCamelCase            =    decoder_attention_heads
         __lowerCamelCase            =    dropout
         __lowerCamelCase            =    attention_dropout
         __lowerCamelCase            =    activation_dropout
         __lowerCamelCase            =    activation_function
         __lowerCamelCase            =    init_std
         __lowerCamelCase            =    encoder_layerdrop
         __lowerCamelCase            =    decoder_layerdrop
         __lowerCamelCase            =    use_cache
         __lowerCamelCase            =    encoder_layers
         __lowerCamelCase            =    scale_embedding  # scale factor will be sqrt(d_model) if True
         __lowerCamelCase            =    max_source_positions
         __lowerCamelCase            =    max_target_positions
         __lowerCamelCase            =    num_conv_layers
         __lowerCamelCase            =    list(a       )
         __lowerCamelCase            =    conv_channels
         __lowerCamelCase            =    input_feat_per_channel
         __lowerCamelCase            =    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=a    ,							bos_token_id=a    ,							eos_token_id=a    ,							is_encoder_decoder=a    ,							decoder_start_token_id=a    ,							**a    ,							)

'''simple docstring'''




import unittest
from typing import Tuple

import torch

from diffusers.utils import floats_tensor, randn_tensor, torch_all_close, torch_device
from diffusers.utils.testing_utils import require_torch




@require_torch
class        a__ :






     @property
     def   SCREAMING_SNAKE_CASE__  (					self						:						str       ):





         """simple docstring"""



         return self.get_dummy_input()






     @property
     def   SCREAMING_SNAKE_CASE__  (					self						:						str       ):





         """simple docstring"""



         if self.block_type == "down":
             return (4, 32, 16, 16)
         elif self.block_type == "mid":
             return (4, 32, 32, 32)
         elif self.block_type == "up":
             return (4, 32, 64, 64)

         raise ValueError(f"""'{self.block_type}' is not a supported block_type. Set it to 'up', 'mid', or 'down'."""       )






     def   SCREAMING_SNAKE_CASE__  (					self						:						Optional[Any]    ,							a						:						List[Any]=True    ,							a						:						Dict=False    ,							a						:						Optional[Any]=False    ,							a						:						List[Any]=False    ,							):





         """simple docstring"""



         __lowerCamelCase            =    4
         __lowerCamelCase            =    32
         __lowerCamelCase            =    (32, 32)

         __lowerCamelCase            =    torch.manual_seed(0       )
         __lowerCamelCase            =    torch.device(a       )
         __lowerCamelCase            =    (batch_size, num_channels) + sizes
         __lowerCamelCase            =    randn_tensor(a    ,							generator=a    ,							device=a       )
         __lowerCamelCase            =    {'''hidden_states''': hidden_states}

         if include_temb:
             __lowerCamelCase            =    1_28
             __lowerCamelCase            =    randn_tensor((batch_size, temb_channels)    ,							generator=a    ,							device=a       )

         if include_res_hidden_states_tuple:
             __lowerCamelCase            =    torch.manual_seed(1       )
             __lowerCamelCase            =    (randn_tensor(a    ,							generator=a    ,							device=a       ),)

         if include_encoder_hidden_states:
             __lowerCamelCase            =    floats_tensor((batch_size, 32, 32)       ).to(a       )

         if include_skip_sample:
             __lowerCamelCase            =    randn_tensor(((batch_size, 3) + sizes)    ,							generator=a    ,							device=a       )

         return dummy_input






     def   SCREAMING_SNAKE_CASE__  (					self						:						Optional[int]       ):





         """simple docstring"""



         __lowerCamelCase            =    {
             '''in_channels''': 32,
             '''out_channels''': 32,
             '''temb_channels''': 1_28,
         }
         if self.block_type == "up":
             __lowerCamelCase            =    32

         if self.block_type == "mid":
             init_dict.pop('''out_channels'''       )

         __lowerCamelCase            =    self.dummy_input
         return init_dict, inputs_dict






     def   SCREAMING_SNAKE_CASE__  (					self						:						Optional[Any]    ,							a						:						List[str]       ):





         """simple docstring"""



         __lowerCamelCase      ,    __lowerCamelCase            =    self.prepare_init_args_and_inputs_for_common()
         __lowerCamelCase            =    self.block_class(**a       )
         unet_block.to(a       )
         unet_block.eval()

         with torch.no_grad():
             __lowerCamelCase            =    unet_block(**a       )

         if isinstance(a    ,							a       ):
             __lowerCamelCase            =    output[0]

         self.assertEqual(output.shape    ,							self.output_shape       )

         __lowerCamelCase            =    output[0, -1, -3:, -3:]
         __lowerCamelCase            =    torch.tensor(a       ).to(a       )
         assert torch_all_close(output_slice.flatten()    ,							a    ,							atol=5e-3       )






     @unittest.skipIf(torch_device == '''mps'''    ,							'''Training is not supported in mps'''       )
     def   SCREAMING_SNAKE_CASE__  (					self						:						Any       ):





         """simple docstring"""



         __lowerCamelCase      ,    __lowerCamelCase            =    self.prepare_init_args_and_inputs_for_common()
         __lowerCamelCase            =    self.block_class(**a       )
         model.to(a       )
         model.train()
         __lowerCamelCase            =    model(**a       )

         if isinstance(a    ,							a       ):
             __lowerCamelCase            =    output[0]

         __lowerCamelCase            =    torch.device(a       )
         __lowerCamelCase            =    randn_tensor(output.shape    ,							device=a       )
         __lowerCamelCase            =    torch.nn.functional.mse_loss(a    ,							a       )
         loss.backward()
