



'''simple docstring'''





import functools
import operator

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


A					:       int									=     logging.get_logger(__name__)

A					:       str									=     {
    'asapp/sew-d-tiny-100k': 'https://huggingface.co/asapp/sew-d-tiny-100k/resolve/main/config.json',
    # See all SEW-D models at https://huggingface.co/models?filter=sew-d
}





class 				lowerCAmelCase_						(			UpperCAmelCase_		):
    __UpperCAmelCase				=			'sew-d'





    def __init__(							self							:							Tuple,							_snake_case							:							List[str]=32,							_snake_case							:							Any=768,							_snake_case							:							str=12,							_snake_case							:							List[Any]=12,							_snake_case							:							Optional[Any]=3_072,							_snake_case							:							List[Any]=2,							_snake_case							:							Optional[int]=512,							_snake_case							:							Any=256,							_snake_case							:							Tuple=True,							_snake_case							:							Union[str, Any]=True,							_snake_case							:							Union[str, Any]=("p2c", "c2p"),							_snake_case							:							int="layer_norm",							_snake_case							:							Tuple="gelu_python",							_snake_case							:							Optional[Any]=0.1,							_snake_case							:							List[Any]=0.1,							_snake_case							:							int=0.1,							_snake_case							:							List[str]=0.0,							_snake_case							:							Any=0.1,							_snake_case							:							Any=0.02,							_snake_case							:							Any=1E-7,							_snake_case							:							int=1E-5,							_snake_case							:							Any="group",							_snake_case							:							List[str]="gelu",							_snake_case							:							List[str]=(64, 128, 128, 128, 128, 256, 256, 256, 256, 512, 512, 512, 512),							_snake_case							:							int=(5, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1),							_snake_case							:							List[Any]=(10, 3, 1, 3, 1, 3, 1, 3, 1, 2, 1, 2, 1),							_snake_case							:							List[str]=False,							_snake_case							:							List[Any]=128,							_snake_case							:							Dict=16,							_snake_case							:							Any=True,							_snake_case							:							List[str]=0.05,							_snake_case							:							int=10,							_snake_case							:							int=2,							_snake_case							:							Dict=0.0,							_snake_case							:							Tuple=10,							_snake_case							:							Dict=0,							_snake_case							:							List[str]="mean",							_snake_case							:							Dict=False,							_snake_case							:							Optional[Any]=False,							_snake_case							:							Dict=256,							_snake_case							:							int=0,							_snake_case							:							List[Any]=1,							_snake_case							:							List[Any]=2,							**_snake_case							:							Optional[Any],							):



       '''simple docstring'''







       super().__init__(**__a,							pad_token_id=__a,							bos_token_id=__a,							eos_token_id=__a      )
       snake_case       :				List[Any]		    =hidden_size
       snake_case       :				str		    =feat_extract_norm
       snake_case       :				str		    =feat_extract_activation
       snake_case       :				Optional[Any]		    =list(__a      )
       snake_case       :				Union[str, Any]		    =list(__a      )
       snake_case       :				Optional[Any]		    =list(__a      )
       snake_case       :				Any		    =conv_bias
       snake_case       :				Tuple		    =num_conv_pos_embeddings
       snake_case       :				Tuple		    =num_conv_pos_embedding_groups
       snake_case       :				List[Any]		    =len(self.conv_dim      )
       snake_case       :				str		    =num_hidden_layers
       snake_case       :				List[Any]		    =intermediate_size
       snake_case       :				int		    =squeeze_factor
       snake_case       :				Dict		    =max_position_embeddings
       snake_case       :				Tuple		    =position_buckets
       snake_case       :				int		    =share_att_key
       snake_case       :				List[Any]		    =relative_attention
       snake_case       :				Any		    =norm_rel_ebd
       snake_case       :				List[str]		    =list(__a      )
       snake_case       :				Optional[int]		    =hidden_act
       snake_case       :				List[str]		    =num_attention_heads
       snake_case       :				Tuple		    =hidden_dropout
       snake_case       :				Union[str, Any]		    =attention_dropout
       snake_case       :				str		    =activation_dropout
       snake_case       :				Optional[Any]		    =feat_proj_dropout
       snake_case       :				Tuple		    =final_dropout
       snake_case       :				int		    =layer_norm_eps
       snake_case       :				Any		    =feature_layer_norm_eps
       snake_case       :				Optional[Any]		    =initializer_range
       snake_case       :				Union[str, Any]		    =vocab_size

       if (
           (len(self.conv_stride      ) != self.num_feat_extract_layers)
           or (len(self.conv_kernel      ) != self.num_feat_extract_layers)
           or (len(self.conv_dim      ) != self.num_feat_extract_layers)
       ):
          raise ValueError(
              '''Configuration for convolutional layers is incorrect.'''
              '''It is required that `len(config.conv_dim)` == `len(config.conv_stride)` == `len(config.conv_kernel)`,'''
              f'''but is `len(config.conv_dim) = {len(self.conv_dim      )}`, `len(config.conv_stride)'''
              f'''= {len(self.conv_stride      )}`, `len(config.conv_kernel) = {len(self.conv_kernel      )}`.'''      )

       # fine-tuning config parameters for SpecAugment: https://arxiv.org/abs/1904.08779
       snake_case       :				List[str]		    =apply_spec_augment
       snake_case       :				Dict		    =mask_time_prob
       snake_case       :				str		    =mask_time_length
       snake_case       :				Dict		    =mask_time_min_masks
       snake_case       :				Any		    =mask_feature_prob
       snake_case       :				str		    =mask_feature_length
       snake_case       :				Any		    =mask_feature_min_masks

       # ctc loss
       snake_case       :				Union[str, Any]		    =ctc_loss_reduction
       snake_case       :				Optional[int]		    =ctc_zero_infinity

       # sequence classification
       snake_case       :				List[str]		    =use_weighted_layer_sum
       snake_case       :				str		    =classifier_proj_size






    @property
    def 	__snake_case  (							self							:							Tuple      ):



       '''simple docstring'''







       return functools.reduce(operator.mul,							self.conv_stride,							1      )










from dataclasses import dataclass, field
from typing import Tuple

from ..utils import cached_property, is_tf_available, logging, requires_backends
from .benchmark_args_utils import BenchmarkArguments


if is_tf_available():
     import tensorflow as tf


a_    :  Any						  =		logging.get_logger(__name__)





@dataclass
class  lowerCamelCase__	(    UpperCAmelCase_):
     """simple docstring"""



     _A      =      [
         'no_inference',
         'no_cuda',
         'no_tpu',
         'no_speed',
         'no_memory',
         'no_env_print',
         'no_multi_process',
     ]







     def __init__(self					,      **__a     ):






           '''simple docstring'''



           for deprecated_arg in self.deprecated_args:
                 if deprecated_arg in kwargs:
                       lowerCamelCase             =		deprecated_arg[3:]
                       lowerCamelCase             =		not kwargs.pop(__a     )
                       logger.warning(
                           F"""{deprecated_arg} is depreciated. Please use --no-{positive_arg} or"""
                           F""" {positive_arg}={kwargs[positive_arg]}"""     )
           lowerCamelCase             =		kwargs.pop("tpu_name"					,      self.tpu_name     )
           lowerCamelCase             =		kwargs.pop("device_idx"					,      self.device_idx     )
           lowerCamelCase             =		kwargs.pop("eager_mode"					,      self.eager_mode     )
           lowerCamelCase             =		kwargs.pop("use_xla"					,      self.use_xla     )
           super().__init__(**__a     )

     _A      =      field(
         default=UpperCAmelCase_							,     metadata={'help': 'Name of TPU'}							,     )
     _A      =      field(
         default=0							,     metadata={'help': 'CPU / GPU device index. Defaults to 0.'}							,     )
     _A      =      field(default=UpperCAmelCase_							,     metadata={'help': 'Benchmark models in eager model.'})
     _A      =      field(
         default=UpperCAmelCase_							,     metadata={
             'help': 'Benchmark models using XLA JIT compilation. Note that `eager_model` has to be set to `False`.'
         }							,     )







     @cached_property
     def     _a   (self     ):






           '''simple docstring'''



           requires_backends(self					,      ["tf"]     )
           lowerCamelCase             =		None
           if self.tpu:
                 try:
                       if self.tpu_name:
                             lowerCamelCase             =		tf.distribute.cluster_resolver.TPUClusterResolver(self.tpu_name     )
                       else:
                             lowerCamelCase             =		tf.distribute.cluster_resolver.TPUClusterResolver()
                 except ValueError:
                       lowerCamelCase             =		None
           return tpu







     @cached_property
     def     _a   (self     ):






           '''simple docstring'''



           requires_backends(self					,      ["tf"]     )
           if self.is_tpu:
                 tf.config.experimental_connect_to_cluster(self._setup_tpu     )
                 tf.tpu.experimental.initialize_tpu_system(self._setup_tpu     )

                 lowerCamelCase             =		tf.distribute.TPUStrategy(self._setup_tpu     )
           else:
                 # currently no multi gpu is allowed
                 if self.is_gpu:
                       # TODO: Currently only single GPU is supported
                       tf.config.set_visible_devices(self.gpu_list[self.device_idx]					,      "GPU"     )
                       lowerCamelCase             =		tf.distribute.OneDeviceStrategy(device=F"""/gpu:{self.device_idx}"""     )
                 else:
                       tf.config.set_visible_devices([]					,      "GPU"     )  # disable GPU
                       lowerCamelCase             =		tf.distribute.OneDeviceStrategy(device=F"""/cpu:{self.device_idx}"""     )

           return strategy







     @property
     def     _a   (self     ):






           '''simple docstring'''



           requires_backends(self					,      ["tf"]     )
           return self._setup_tpu is not None







     @property
     def     _a   (self     ):






           '''simple docstring'''



           requires_backends(self					,      ["tf"]     )
           return self._setup_strategy







     @property
     def     _a   (self     ):






           '''simple docstring'''



           requires_backends(self					,      ["tf"]     )
           return tf.config.list_physical_devices("GPU"     )







     @property
     def     _a   (self     ):






           '''simple docstring'''



           requires_backends(self					,      ["tf"]     )
           if self.cuda:
                 return len(self.gpu_list     )
           return 0







     @property
     def     _a   (self     ):






           '''simple docstring'''



           return self.n_gpu > 0