




"""simple docstring"""




import contextlib
from multiprocessing import Pool, RLock

from tqdm.auto import tqdm

from ..utils import experimental, logging


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






class        __magic_name__				:






				'''simple docstring'''
				__UpperCamelCase         =		None




@experimental
def        a__					(							snake_case__			,					snake_case__			,					snake_case__			,					snake_case__			,					snake_case__			,					snake_case__			,					snake_case__							)		->   Any:
			if ParallelBackendConfig.backend_name is None:
						return _map_with_multiprocessing_pool(
						    snake_case__			,					snake_case__			,					snake_case__			,					snake_case__			,					snake_case__			,					snake_case__			,					snake_case__							)

			return _map_with_joblib(snake_case__			,					snake_case__			,					snake_case__			,					snake_case__			,					snake_case__			,					snake_case__			,					snake_case__							)



def        a__					(							snake_case__			,					snake_case__			,					snake_case__			,					snake_case__			,					snake_case__			,					snake_case__			,					snake_case__							)		->   str:
			lowerCamelCase      =   num_proc if num_proc <= len(snake_case__							) else len(snake_case__							)
			lowerCamelCase      =   []  # We organize the splits ourselve (contiguous splits)
			for index in range(snake_case__							):
						lowerCamelCase      =   len(snake_case__							) // num_proc
						lowerCamelCase      =   len(snake_case__							) % num_proc
						lowerCamelCase      =   div * index + min(snake_case__			,					snake_case__							)
						lowerCamelCase      =   start + div + (1 if index < mod else 0)
						split_kwds.append((function, iterable[start:end], types, index, disable_tqdm, desc)							)

			if len(snake_case__							) != sum(len(i[1]							) for i in split_kwds							):
						raise ValueError(
						    F'Error dividing inputs iterable among processes. '
						    F'Total number of objects {len(snake_case__							)}, '
						    F'length: {sum(len(i[1]							) for i in split_kwds							)}'							)

			logger.info(
			    F'Spawning {num_proc} processes for {len(snake_case__							)} objects in slices of {[len(i[1]							) for i in split_kwds]}'							)
			lowerCamelCase ,  lowerCamelCase      =   None, None
			if not disable_tqdm:
						lowerCamelCase ,  lowerCamelCase      =   (RLock(),), tqdm.set_lock
			with Pool(snake_case__			,					initargs=snake_case__			,					initializer=snake_case__							) as pool:
						lowerCamelCase      =   pool.map(snake_case__			,					snake_case__							)
			logger.info(F'Finished {num_proc} processes'							)
			lowerCamelCase      =   [obj for proc_res in mapped for obj in proc_res]
			logger.info(F'Unpacked {len(snake_case__							)} objects'							)

			return mapped



def        a__					(							snake_case__			,					snake_case__			,					snake_case__			,					snake_case__			,					snake_case__			,					snake_case__			,					snake_case__							)		->   Any:
			# progress bar is not yet supported for _map_with_joblib, because tqdm couldn't accurately be applied to joblib,
			# and it requires monkey-patching joblib internal classes which is subject to change
			import joblib

			with joblib.parallel_backend(ParallelBackendConfig.backend_name			,					n_jobs=snake_case__							):
						return joblib.Parallel()(
						    joblib.delayed(snake_case__							)((function, obj, types, None, True, None)							) for obj in iterable							)



@experimental
@contextlib.contextmanager
def        a__					(							snake_case__							)		->   List[Any]:
			lowerCamelCase      =   backend_name

			if backend_name == "spark":
						from joblibspark import register_spark

						register_spark()

						# TODO: call create_cache_and_write_probe if "download" in steps
						# TODO: raise NotImplementedError when Dataset.map etc is called

			try:
						yield
			finally:
						lowerCamelCase      =   None









"""simple docstring"""




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


lowerCAmelCase				:     Union[str, Any]					=				logging.get_logger(__name__)

lowerCAmelCase				:     Union[str, Any]					=				{
    """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        __magic_name__				(			UpperCAmelCase__							):






				'''simple docstring'''
				__UpperCamelCase         =		"mctct"





				def __init__(			self						,					_a=8_065						,					_a=1_536						,					_a=36						,					_a=6_144						,					_a=4						,					_a=384						,					_a=920						,					_a=1e-5						,					_a=0.3						,					_a="relu"						,					_a=0.02						,					_a=0.3						,					_a=0.3						,					_a=1						,					_a=0						,					_a=2						,					_a=1						,					_a=0.3						,					_a=1						,					_a=(7,)						,					_a=(3,)						,					_a=80						,					_a=1						,					_a=None						,					_a="sum"						,					_a=False						,					**_a						,					):





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

							# prevents config testing fail with exporting to json
							lowerCamelCase      =   list(_a					)
							lowerCamelCase      =   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}`.'					)



