


import functools
import operator

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


lowerCamelCase__							:						str							     =   logging.get_logger(__name__)

lowerCamelCase__							:						Optional[int]							     =   {
    """microsoft/unispeech-large-1500h-cv""": (
        """https://huggingface.co/microsoft/unispeech-large-1500h-cv/resolve/main/config.json"""
    ),
    # See all UniSpeech models at https://huggingface.co/models?filter=unispeech
}
class 		__magic_name__						(snake_case_				):





     '''simple docstring'''



     __lowercase				:							Tuple	   =       'unispeech'

     def __init__(					self:str     ,		_a:int=32     ,		_a:List[Any]=7_68     ,		_a:List[Any]=12     ,		_a:Optional[int]=12     ,		_a:str=30_72     ,		_a:Any="gelu"     ,		_a:List[str]=0.1     ,		_a:Optional[Any]=0.1     ,		_a:List[str]=0.1     ,		_a:Optional[Any]=0.0     ,		_a:Union[str, Any]=0.0     ,		_a:List[Any]=0.1     ,		_a:List[str]=0.1     ,		_a:Any=0.02     ,		_a:Optional[Any]=1e-5     ,		_a:List[str]="group"     ,		_a:Optional[int]="gelu"     ,		_a:List[str]=(5_12, 5_12, 5_12, 5_12, 5_12, 5_12, 5_12)     ,		_a:str=(5, 2, 2, 2, 2, 2, 2)     ,		_a:Any=(10, 3, 3, 3, 3, 2, 2)     ,		_a:Any=False     ,		_a:List[Any]=1_28     ,		_a:List[Any]=16     ,		_a:Any=False     ,		_a:Optional[int]=True     ,		_a:Optional[int]=0.05     ,		_a:List[Any]=10     ,		_a:Any=2     ,		_a:Dict=0.0     ,		_a:List[str]=10     ,		_a:Dict=0     ,		_a:int=3_20     ,		_a:Union[str, Any]=2     ,		_a:str=0.1     ,		_a:Tuple=1_00     ,		_a:Optional[Any]=2_56     ,		_a:Optional[int]=2_56     ,		_a:Optional[int]=0.1     ,		_a:Union[str, Any]="mean"     ,		_a:Optional[Any]=False     ,		_a:List[Any]=False     ,		_a:Optional[Any]=2_56     ,		_a:Any=80     ,		_a:Optional[Any]=0     ,		_a:Optional[Any]=1     ,		_a:Any=2     ,		_a:Optional[int]=0.5     ,		**_a:List[str]     ,		):
       super().__init__(**_a     ,		pad_token_id=_a     ,		bos_token_id=_a     ,		eos_token_id=_a   )
       snake_case__						= hidden_size
       snake_case__						= feat_extract_norm
       snake_case__						= feat_extract_activation
       snake_case__						= list(_a   )
       snake_case__						= list(_a   )
       snake_case__						= list(_a   )
       snake_case__						= conv_bias
       snake_case__						= num_conv_pos_embeddings
       snake_case__						= num_conv_pos_embedding_groups
       snake_case__						= len(self.conv_dim   )
       snake_case__						= num_hidden_layers
       snake_case__						= intermediate_size
       snake_case__						= hidden_act
       snake_case__						= num_attention_heads
       snake_case__						= hidden_dropout
       snake_case__						= attention_dropout
       snake_case__						= activation_dropout
       snake_case__						= feat_proj_dropout
       snake_case__						= final_dropout
       snake_case__						= layerdrop
       snake_case__						= layer_norm_eps
       snake_case__						= initializer_range
       snake_case__						= num_ctc_classes
       snake_case__						= vocab_size
       snake_case__						= do_stable_layer_norm
       snake_case__						= use_weighted_layer_sum
       snake_case__						= classifier_proj_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)`, but is `len(config.conv_dim) ='''
             F""" {len(self.conv_dim   )}`, `len(config.conv_stride) = {len(self.conv_stride   )}`,"""
             F""" `len(config.conv_kernel) = {len(self.conv_kernel   )}`."""   )

       # fine-tuning config parameters for SpecAugment: https://arxiv.org/abs/1904.08779
       snake_case__						= apply_spec_augment
       snake_case__						= mask_time_prob
       snake_case__						= mask_time_length
       snake_case__						= mask_time_min_masks
       snake_case__						= mask_feature_prob
       snake_case__						= mask_feature_length
       snake_case__						= mask_feature_min_masks

       # parameters for pretraining with codevector quantized representations
       snake_case__						= num_codevectors_per_group
       snake_case__						= num_codevector_groups
       snake_case__						= contrastive_logits_temperature
       snake_case__						= feat_quantizer_dropout
       snake_case__						= num_negatives
       snake_case__						= codevector_dim
       snake_case__						= proj_codevector_dim
       snake_case__						= diversity_loss_weight

       # ctc loss
       snake_case__						= ctc_loss_reduction
       snake_case__						= ctc_zero_infinity

       # pretraining loss
       snake_case__						= replace_prob







     @property
     def 	SCREAMING_SNAKE_CASE__						(					self:str   ):
       return functools.reduce(operator.mul     ,		self.conv_stride     ,		1   )





import pytest

from datasets.utils.sharding import _distribute_shards, _number_of_shards_in_gen_kwargs, _split_gen_kwargs







@pytest.mark.parametrize(
    '''kwargs, expected'''							,   [
        ({'''num_shards''': 0, '''max_num_jobs''': 1}, []),
        ({'''num_shards''': 10, '''max_num_jobs''': 1}, [range(10				)]),
        ({'''num_shards''': 10, '''max_num_jobs''': 10}, [range(__lowerCAmelCase							,   i + 1				) for i in range(10				)]),
        ({'''num_shards''': 1, '''max_num_jobs''': 10}, [range(1				)]),
        ({'''num_shards''': 10, '''max_num_jobs''': 3}, [range(0							,   4				), range(4							,   7				), range(7							,   10				)]),
        ({'''num_shards''': 3, '''max_num_jobs''': 10}, [range(0							,   1				), range(1							,   2				), range(2							,   3				)]),
    ]							,   )
def SCREAMING_SNAKE_CASE	(			__lowerCAmelCase							,   __lowerCAmelCase				)    ->				Optional[int]:
  snake_case__						= _distribute_shards(**__lowerCAmelCase				)
  assert out == expected







@pytest.mark.parametrize(
    '''gen_kwargs, max_num_jobs, expected'''							,   [
        ({'''foo''': 0}, 10, [{'''foo''': 0}]),
        ({'''shards''': [0, 1, 2, 3]}, 1, [{'''shards''': [0, 1, 2, 3]}]),
        ({'''shards''': [0, 1, 2, 3]}, 4, [{'''shards''': [0]}, {'''shards''': [1]}, {'''shards''': [2]}, {'''shards''': [3]}]),
        ({'''shards''': [0, 1]}, 4, [{'''shards''': [0]}, {'''shards''': [1]}]),
        ({'''shards''': [0, 1, 2, 3]}, 2, [{'''shards''': [0, 1]}, {'''shards''': [2, 3]}]),
    ]							,   )
def SCREAMING_SNAKE_CASE	(			__lowerCAmelCase							,   __lowerCAmelCase							,   __lowerCAmelCase				)    ->				Dict:
  snake_case__						= _split_gen_kwargs(__lowerCAmelCase							,   __lowerCAmelCase				)
  assert out == expected







@pytest.mark.parametrize(
    '''gen_kwargs, expected'''							,   [
        ({'''foo''': 0}, 1),
        ({'''shards''': [0]}, 1),
        ({'''shards''': [0, 1, 2, 3]}, 4),
        ({'''shards''': [0, 1, 2, 3], '''foo''': 0}, 4),
        ({'''shards''': [0, 1, 2, 3], '''other''': (0, 1)}, 4),
        ({'''shards''': [0, 1, 2, 3], '''shards2''': [0, 1]}, RuntimeError),
    ]							,   )
def SCREAMING_SNAKE_CASE	(			__lowerCAmelCase							,   __lowerCAmelCase				)    ->				List[Any]:
  if expected is RuntimeError:
    with pytest.raises(__lowerCAmelCase				):
      _number_of_shards_in_gen_kwargs(__lowerCAmelCase				)
  else:
    snake_case__						= _number_of_shards_in_gen_kwargs(__lowerCAmelCase				)
    assert out == expected

