





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


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

lowercase				:	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 			A__   (							__UpperCAmelCase     ):




   """simple docstring"""



   __A       :    Optional[Any]	  =  '''speech_to_text'''
   __A       :    Tuple	  =  ['''past_key_values''']
   __A       :    Union[str, Any]	  =  {'''num_attention_heads''': '''encoder_attention_heads''', '''hidden_size''': '''d_model'''}

   def __init__( self ,  lowercase=1_0000 ,  lowercase=12 ,  lowercase=2048 ,  lowercase=4 ,  lowercase=6 ,  lowercase=2048 ,  lowercase=4 ,  lowercase=0.0 ,  lowercase=0.0 ,  lowercase=True ,  lowercase=True ,  lowercase="relu" ,  lowercase=256 ,  lowercase=0.1 ,  lowercase=0.0 ,  lowercase=0.0 ,  lowercase=0.02 ,  lowercase=2 ,  lowercase=True ,  lowercase=1 ,  lowercase=0 ,  lowercase=2 ,  lowercase=6000 ,  lowercase=1024 ,  lowercase=2 ,  lowercase=(5, 5) ,  lowercase=1024 ,  lowercase=80 ,  lowercase=1 ,  **lowercase ,  )      ->						int:







          '''simple docstring'''

          a__						:     Any			=    vocab_size
          a__						:     List[str]			=    d_model
          a__						:     Optional[int]			=    encoder_ffn_dim
          a__						:     Any			=    encoder_layers
          a__						:     List[str]			=    encoder_attention_heads
          a__						:     Union[str, Any]			=    decoder_ffn_dim
          a__						:     Any			=    decoder_layers
          a__						:     str			=    decoder_attention_heads
          a__						:     Union[str, Any]			=    dropout
          a__						:     Optional[int]			=    attention_dropout
          a__						:     Optional[int]			=    activation_dropout
          a__						:     int			=    activation_function
          a__						:     Union[str, Any]			=    init_std
          a__						:     List[Any]			=    encoder_layerdrop
          a__						:     Dict			=    decoder_layerdrop
          a__						:     Any			=    use_cache
          a__						:     List[Any]			=    encoder_layers
          a__						:     Dict			=    scale_embedding  # scale factor will be sqrt(d_model) if True
          a__						:     Tuple			=    max_source_positions
          a__						:     List[str]			=    max_target_positions
          a__						:     int			=    num_conv_layers
          a__						:     Optional[int]			=    list(lowercase)
          a__						:     List[str]			=    conv_channels
          a__						:     List[str]			=    input_feat_per_channel
          a__						:     Any			=    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=lowercase ,  bos_token_id=lowercase ,  eos_token_id=lowercase ,  is_encoder_decoder=lowercase ,  decoder_start_token_id=lowercase ,  **lowercase ,  )









import os
import socket
from contextlib import contextmanager

import torch

from ..commands.config.default import write_basic_config  # noqa: F401
from ..state import PartialState
from .dataclasses import DistributedType
from .imports import is_deepspeed_available, is_tpu_available
from .transformer_engine import convert_model
from .versions import is_torch_version


if is_deepspeed_available():
    from deepspeed import DeepSpeedEngine

if is_tpu_available(check_device=False):
    import torch_xla.core.xla_model as xm



def A_     (		A__    )  ->		Optional[int]:
       if is_torch_version('<'		,				'2.0.0'    ) or not hasattr(A__		,				'_dynamo'    ):
              return False
       return isinstance(A__		,				torch._dynamo.eval_frame.OptimizedModule    )



def A_     (		A__		,				A__ = True    )  ->		int:
       a__						:     Optional[Any]			=    (torch.nn.parallel.DistributedDataParallel, torch.nn.DataParallel)

       a__						:     Union[str, Any]			=    is_compiled_module(A__    )
       if is_compiled:
              a__						:     List[str]			=    model
              a__						:     Dict			=    model._orig_mod

       if is_deepspeed_available():
              options += (DeepSpeedEngine,)

       while isinstance(A__		,				A__    ):
              a__						:     str			=    model.module

       if not keep_fpaa_wrapper:
              a__						:     Union[str, Any]			=    getattr(A__		,				'forward'    )
              a__						:     List[Any]			=    model.__dict__.pop('_original_forward'		,				A__    )
              if original_forward is not None:
                     while hasattr(A__		,				'__wrapped__'    ):
                            a__						:     int			=    forward.__wrapped__
                            if forward == original_forward:
                                   break
                     a__						:     List[Any]			=    forward
              if getattr(A__		,				'_converted_to_transformer_engine'		,				A__    ):
                     convert_model(A__		,				to_transformer_engine=A__    )

       if is_compiled:
              a__						:     List[str]			=    model
              a__						:     Any			=    compiled_model

       return model



def A_     (		)  ->		int:
       PartialState().wait_for_everyone()



def A_     (		A__		,				A__    )  ->		Dict:
       if PartialState().distributed_type == DistributedType.TPU:
              xm.save(A__		,				A__    )
       elif PartialState().local_process_index == 0:
              torch.save(A__		,				A__    )



@contextmanager
def A_     (		**A__    )  ->		Any:
       for key, value in kwargs.items():
              a__						:     Optional[int]			=    str(A__    )

       yield

       for key in kwargs:
              if key.upper() in os.environ:
                     del os.environ[key.upper()]



def A_     (		A__    )  ->		List[str]:
       if not hasattr(A__		,				'__qualname__'    ) and not hasattr(A__		,				'__name__'    ):
              a__						:     Dict			=    getattr(A__		,				'__class__'		,				A__    )
       if hasattr(A__		,				'__qualname__'    ):
              return obj.__qualname__
       if hasattr(A__		,				'__name__'    ):
              return obj.__name__
       return str(A__    )



def A_     (		A__		,				A__    )  ->		Dict:
       for key, value in source.items():
              if isinstance(A__		,				A__    ):
                     a__						:     Optional[Any]			=    destination.setdefault(A__		,				{}    )
                     merge_dicts(A__		,				A__    )
              else:
                     a__						:     Optional[int]			=    value

       return destination



def A_     (		A__ = None    )  ->		bool:
       if port is None:
              a__						:     List[Any]			=    2_9500
       with socket.socket(socket.AF_INET		,				socket.SOCK_STREAM    ) as s:
              return s.connect_ex(('localhost', port)    ) == 0


