


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


__snake_case            =   logging.get_logger(__name__)

__snake_case            =   {
    "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    UpperCAmelCase					(       __snake_case    ):
			lowercase						= """mctct"""




			def __init__(						self							:		str       ,       __magic_name__							:		Tuple=8_0_6_5       ,       __magic_name__							:		Tuple=1_5_3_6       ,       __magic_name__							:		str=3_6       ,       __magic_name__							:		List[Any]=6_1_4_4       ,       __magic_name__							:		str=4       ,       __magic_name__							:		List[Any]=3_8_4       ,       __magic_name__							:		Any=9_2_0       ,       __magic_name__							:		Tuple=1e-5       ,       __magic_name__							:		Optional[Any]=0.3       ,       __magic_name__							:		Union[str, Any]="relu"       ,       __magic_name__							:		List[Any]=0.02       ,       __magic_name__							:		Tuple=0.3       ,       __magic_name__							:		Union[str, Any]=0.3       ,       __magic_name__							:		str=1       ,       __magic_name__							:		Tuple=0       ,       __magic_name__							:		Dict=2       ,       __magic_name__							:		Any=1       ,       __magic_name__							:		Tuple=0.3       ,       __magic_name__							:		Dict=1       ,       __magic_name__							:		Union[str, Any]=(7,)       ,       __magic_name__							:		List[str]=(3,)       ,       __magic_name__							:		List[Any]=8_0       ,       __magic_name__							:		Tuple=1       ,       __magic_name__							:		int=None       ,       __magic_name__							:		int="sum"       ,       __magic_name__							:		Tuple=False       ,       **__magic_name__							:		Any       ,       ):







						"""simple docstring"""







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

						# prevents config testing fail with exporting to json
						UpperCamelCase         =					list(__magic_name__						)
						UpperCamelCase         =					list(__magic_name__						)

						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 functools
import gc
import inspect

import torch

from .imports import is_npu_available, is_xpu_available






def 							_lowercase    (		*SCREAMING_SNAKE_CASE_   :		List[Any]	):





			"""simple docstring"""




			if not isinstance(SCREAMING_SNAKE_CASE_       ,  SCREAMING_SNAKE_CASE_	):
						UpperCamelCase         =					list(SCREAMING_SNAKE_CASE_	)
			for i in range(len(SCREAMING_SNAKE_CASE_	)	):
						UpperCamelCase         =					None
			gc.collect()
			if is_xpu_available():
						torch.xpu.empty_cache()
			elif is_npu_available():
						torch.npu.empty_cache()
			else:
						torch.cuda.empty_cache()
			return objects






def 							_lowercase    (		SCREAMING_SNAKE_CASE_   :		Exception	):





			"""simple docstring"""




			UpperCamelCase         =					[
			    """CUDA out of memory.""",  # CUDA OOM
			    """cuDNN error: CUDNN_STATUS_NOT_SUPPORTED.""",  # CUDNN SNAFU
			    """DefaultCPUAllocator: can't allocate memory""",  # CPU OOM
			]
			if isinstance(SCREAMING_SNAKE_CASE_       ,  SCREAMING_SNAKE_CASE_	) and len(exception.args	) == 1:
						return any(err in exception.args[0] for err in _statements	)
			return False






def 							_lowercase    (		SCREAMING_SNAKE_CASE_   :		callable = None       ,  SCREAMING_SNAKE_CASE_   :		int = 128	):





			"""simple docstring"""




			if function is None:
						return functools.partial(SCREAMING_SNAKE_CASE_       ,  starting_batch_size=SCREAMING_SNAKE_CASE_	)

			UpperCamelCase         =					starting_batch_size

			def decorator(*SCREAMING_SNAKE_CASE_   :		Union[str, Any]       ,  **SCREAMING_SNAKE_CASE_   :		Tuple	):
						nonlocal batch_size
						gc.collect()
						if is_xpu_available():
									torch.xpu.empty_cache()
						elif is_npu_available():
									torch.npu.empty_cache()
						else:
									torch.cuda.empty_cache()
						UpperCamelCase         =					list(inspect.signature(SCREAMING_SNAKE_CASE_	).parameters.keys()	)
						# Guard against user error
						if len(SCREAMING_SNAKE_CASE_	) < (len(SCREAMING_SNAKE_CASE_	) + 1):
									UpperCamelCase         =					""", """.join([f'{arg}={value}' for arg, value in zip(params[1:]       ,  args[1:]	)]	)
									raise TypeError(
									    f'Batch size was passed into `{function.__name__}` as the first argument when called.'
									    f'Remove this as the decorator already does so: `{function.__name__}({arg_str})`'	)
						while True:
									if batch_size == 0:
												raise RuntimeError("""No executable batch size found, reached zero."""	)
									try:
												return function(SCREAMING_SNAKE_CASE_       ,  *SCREAMING_SNAKE_CASE_       ,  **SCREAMING_SNAKE_CASE_	)
									except Exception as e:
												if should_reduce_batch_size(SCREAMING_SNAKE_CASE_	):
															gc.collect()
															if is_xpu_available():
																		torch.xpu.empty_cache()
															elif is_npu_available():
																		torch.npu.empty_cache()
															else:
																		torch.cuda.empty_cache()
															batch_size //= 2
												else:
															raise

			return decorator




