





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     SCREAMING_SNAKE_CASE       (__lowercase				):
   _UpperCamelCase   :		Optional[int]			 =	'''mctct'''


   def __init__(   self      :    List[str]      ,					a      :    Dict=8_065      ,					a      :    Tuple=1_536      ,					a      :    Optional[Any]=36      ,					a      :    Dict=6_144      ,					a      :    List[Any]=4      ,					a      :    Optional[Any]=384      ,					a      :    Any=920      ,					a      :    Optional[int]=1E-5      ,					a      :    Tuple=0.3      ,					a      :    Dict="relu"      ,					a      :    int=0.02      ,					a      :    Tuple=0.3      ,					a      :    Optional[int]=0.3      ,					a      :    Union[str, Any]=1      ,					a      :    List[str]=0      ,					a      :    Dict=2      ,					a      :    str=1      ,					a      :    Any=0.3      ,					a      :    Optional[Any]=1      ,					a      :    Union[str, Any]=(7,)      ,					a      :    List[str]=(3,)      ,					a      :    Dict=80      ,					a      :    List[str]=1      ,					a      :    Any=None      ,					a      :    int="sum"      ,					a      :    Dict=False      ,					**a      :    Tuple      ,					)->       str:





     """simple docstring"""







     super().__init__(**a      ,					pad_token_id=a      ,					bos_token_id=a      ,					eos_token_id=a	)
     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(a	)
     lowercase__           =  list(a	)

     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 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       __UpperCamelCase  (_SCREAMING_SNAKE_CASE		)    ->       List[str]:
  if is_torch_version('<'		,						'2.0.0'		) or not hasattr(_SCREAMING_SNAKE_CASE		,						'_dynamo'		):
    return False
  return isinstance(_SCREAMING_SNAKE_CASE		,						torch._dynamo.eval_frame.OptimizedModule		)




def       __UpperCamelCase  (_SCREAMING_SNAKE_CASE		,						_SCREAMING_SNAKE_CASE = True		)    ->       Dict:
  lowercase__           =  (torch.nn.parallel.DistributedDataParallel, torch.nn.DataParallel)

  lowercase__           =  is_compiled_module(_SCREAMING_SNAKE_CASE		)
  if is_compiled:
    lowercase__           =  model
    lowercase__           =  model._orig_mod

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

  while isinstance(_SCREAMING_SNAKE_CASE		,						_SCREAMING_SNAKE_CASE		):
    lowercase__           =  model.module

  if not keep_fpaa_wrapper:
    lowercase__           =  getattr(_SCREAMING_SNAKE_CASE		,						'forward'		)
    lowercase__           =  model.__dict__.pop('_original_forward'		,						_SCREAMING_SNAKE_CASE		)
    if original_forward is not None:
      while hasattr(_SCREAMING_SNAKE_CASE		,						'__wrapped__'		):
        lowercase__           =  forward.__wrapped__
        if forward == original_forward:
          break
      lowercase__           =  forward
    if getattr(_SCREAMING_SNAKE_CASE		,						'_converted_to_transformer_engine'		,						_SCREAMING_SNAKE_CASE		):
      convert_model(_SCREAMING_SNAKE_CASE		,						to_transformer_engine=_SCREAMING_SNAKE_CASE		)

  if is_compiled:
    lowercase__           =  model
    lowercase__           =  compiled_model

  return model




def       __UpperCamelCase  ()    ->       Tuple:
  PartialState().wait_for_everyone()




def       __UpperCamelCase  (_SCREAMING_SNAKE_CASE		,						_SCREAMING_SNAKE_CASE		)    ->       List[Any]:
  if PartialState().distributed_type == DistributedType.TPU:
    xm.save(_SCREAMING_SNAKE_CASE		,						_SCREAMING_SNAKE_CASE		)
  elif PartialState().local_process_index == 0:
    torch.save(_SCREAMING_SNAKE_CASE		,						_SCREAMING_SNAKE_CASE		)




@contextmanager
def       __UpperCamelCase  (**_SCREAMING_SNAKE_CASE		)    ->       Optional[Any]:
  for key, value in kwargs.items():
    lowercase__           =  str(_SCREAMING_SNAKE_CASE		)

  yield

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




def       __UpperCamelCase  (_SCREAMING_SNAKE_CASE		)    ->       List[str]:
  if not hasattr(_SCREAMING_SNAKE_CASE		,						'__qualname__'		) and not hasattr(_SCREAMING_SNAKE_CASE		,						'__name__'		):
    lowercase__           =  getattr(_SCREAMING_SNAKE_CASE		,						'__class__'		,						_SCREAMING_SNAKE_CASE		)
  if hasattr(_SCREAMING_SNAKE_CASE		,						'__qualname__'		):
    return obj.__qualname__
  if hasattr(_SCREAMING_SNAKE_CASE		,						'__name__'		):
    return obj.__name__
  return str(_SCREAMING_SNAKE_CASE		)




def       __UpperCamelCase  (_SCREAMING_SNAKE_CASE		,						_SCREAMING_SNAKE_CASE		)    ->       Dict:
  for key, value in source.items():
    if isinstance(_SCREAMING_SNAKE_CASE		,						_SCREAMING_SNAKE_CASE		):
      lowercase__           =  destination.setdefault(_SCREAMING_SNAKE_CASE		,						{}		)
      merge_dicts(_SCREAMING_SNAKE_CASE		,						_SCREAMING_SNAKE_CASE		)
    else:
      lowercase__           =  value

  return destination




def       __UpperCamelCase  (_SCREAMING_SNAKE_CASE = None		)    ->       bool:
  if port is None:
    lowercase__           =  29500
  with socket.socket(socket.AF_INET		,						socket.SOCK_STREAM		) as s:
    return s.connect_ex(('localhost', port)		) == 0


