





"""simple docstring"""





import functools
import operator

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


_lowerCamelCase       =	logging.get_logger(__name__)

_lowerCamelCase       =	{
    '''facebook/hubert-base-ls960''': '''https://huggingface.co/facebook/hubert-base-ls960/resolve/main/config.json''',
    # See all Hubert models at https://huggingface.co/models?filter=hubert
}





class 			snake_case		(   __UpperCAmelCase   ):
      lowerCamelCase__						= '''hubert'''

      def __init__(			self   :int						,							_lowerCamelCase   :Any=3_2						,							_lowerCamelCase   :List[Any]=7_6_8						,							_lowerCamelCase   :Tuple=1_2						,							_lowerCamelCase   :Optional[int]=1_2						,							_lowerCamelCase   :List[str]=3_0_7_2						,							_lowerCamelCase   :Optional[int]="gelu"						,							_lowerCamelCase   :Union[str, Any]=0.1						,							_lowerCamelCase   :Union[str, Any]=0.1						,							_lowerCamelCase   :List[str]=0.1						,							_lowerCamelCase   :str=True						,							_lowerCamelCase   :str=0.0						,							_lowerCamelCase   :Union[str, Any]=0.1						,							_lowerCamelCase   :Dict=0.1						,							_lowerCamelCase   :Optional[int]=0.0_2						,							_lowerCamelCase   :Any=1e-5						,							_lowerCamelCase   :Optional[int]="group"						,							_lowerCamelCase   :Dict="gelu"						,							_lowerCamelCase   :Any=(5_1_2, 5_1_2, 5_1_2, 5_1_2, 5_1_2, 5_1_2, 5_1_2)						,							_lowerCamelCase   :Optional[int]=(5, 2, 2, 2, 2, 2, 2)						,							_lowerCamelCase   :int=(1_0, 3, 3, 3, 3, 2, 2)						,							_lowerCamelCase   :str=False						,							_lowerCamelCase   :Dict=1_2_8						,							_lowerCamelCase   :Union[str, Any]=1_6						,							_lowerCamelCase   :str=False						,							_lowerCamelCase   :Union[str, Any]=True						,							_lowerCamelCase   :Optional[Any]=0.0_5						,							_lowerCamelCase   :Any=1_0						,							_lowerCamelCase   :int=2						,							_lowerCamelCase   :Optional[Any]=0.0						,							_lowerCamelCase   :str=1_0						,							_lowerCamelCase   :List[str]=0						,							_lowerCamelCase   :Any="sum"						,							_lowerCamelCase   :Optional[int]=False						,							_lowerCamelCase   :Dict=False						,							_lowerCamelCase   :Any=2_5_6						,							_lowerCamelCase   :Union[str, Any]=0						,							_lowerCamelCase   :Union[str, Any]=1						,							_lowerCamelCase   :str=2						,							**_lowerCamelCase   :Union[str, Any]						,							):
       super().__init__(**_lowerCamelCase						,							pad_token_id=_lowerCamelCase						,							bos_token_id=_lowerCamelCase						,							eos_token_id=_lowerCamelCase						)
       __SCREAMING_SNAKE_CASE :			List[Any]												=       hidden_size
       __SCREAMING_SNAKE_CASE :			Optional[int]												=       feat_extract_norm
       __SCREAMING_SNAKE_CASE :			int												=       feat_extract_activation
       __SCREAMING_SNAKE_CASE :			List[str]												=       list(_lowerCamelCase						)
       __SCREAMING_SNAKE_CASE :			List[Any]												=       list(_lowerCamelCase						)
       __SCREAMING_SNAKE_CASE :			Tuple												=       list(_lowerCamelCase						)
       __SCREAMING_SNAKE_CASE :			Optional[Any]												=       conv_bias
       __SCREAMING_SNAKE_CASE :			List[str]												=       num_conv_pos_embeddings
       __SCREAMING_SNAKE_CASE :			Dict												=       num_conv_pos_embedding_groups
       __SCREAMING_SNAKE_CASE :			Union[str, Any]												=       len(self.conv_dim						)
       __SCREAMING_SNAKE_CASE :			int												=       num_hidden_layers
       __SCREAMING_SNAKE_CASE :			Tuple												=       intermediate_size
       __SCREAMING_SNAKE_CASE :			List[str]												=       hidden_act
       __SCREAMING_SNAKE_CASE :			Union[str, Any]												=       num_attention_heads
       __SCREAMING_SNAKE_CASE :			int												=       hidden_dropout
       __SCREAMING_SNAKE_CASE :			Any												=       attention_dropout
       __SCREAMING_SNAKE_CASE :			Optional[int]												=       activation_dropout
       __SCREAMING_SNAKE_CASE :			Any												=       feat_proj_layer_norm
       __SCREAMING_SNAKE_CASE :			List[str]												=       feat_proj_dropout
       __SCREAMING_SNAKE_CASE :			Tuple												=       final_dropout
       __SCREAMING_SNAKE_CASE :			Any												=       layerdrop
       __SCREAMING_SNAKE_CASE :			Union[str, Any]												=       layer_norm_eps
       __SCREAMING_SNAKE_CASE :			int												=       initializer_range
       __SCREAMING_SNAKE_CASE :			Any												=       vocab_size
       __SCREAMING_SNAKE_CASE :			Tuple												=       do_stable_layer_norm
       __SCREAMING_SNAKE_CASE :			List[Any]												=       use_weighted_layer_sum
       __SCREAMING_SNAKE_CASE :			int												=       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
       __SCREAMING_SNAKE_CASE :			Optional[Any]												=       apply_spec_augment
       __SCREAMING_SNAKE_CASE :			str												=       mask_time_prob
       __SCREAMING_SNAKE_CASE :			List[Any]												=       mask_time_length
       __SCREAMING_SNAKE_CASE :			List[Any]												=       mask_time_min_masks
       __SCREAMING_SNAKE_CASE :			str												=       mask_feature_prob
       __SCREAMING_SNAKE_CASE :			Optional[int]												=       mask_feature_length
       __SCREAMING_SNAKE_CASE :			str												=       mask_feature_min_masks

       # ctc loss
       __SCREAMING_SNAKE_CASE :			Optional[int]												=       ctc_loss_reduction
       __SCREAMING_SNAKE_CASE :			Tuple												=       ctc_zero_infinity



      @property
      def 						SCREAMING_SNAKE_CASE_			(			self   :List[str]						):
       return functools.reduce(operator.mul						,							self.conv_stride						,							1						)








"""simple docstring"""





from collections import OrderedDict
from typing import Any, Mapping, Optional

from ... import PreTrainedTokenizer
from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig, OnnxSeqaSeqConfigWithPast
from ...onnx.utils import compute_effective_axis_dimension
from ...utils import TensorType, is_torch_available, logging


_lowerCamelCase       =	logging.get_logger(__name__)

_lowerCamelCase       =	{
    '''facebook/m2m100_418M''': '''https://huggingface.co/facebook/m2m100_418M/resolve/main/config.json''',
    # See all M2M100 models at https://huggingface.co/models?filter=m2m_100
}





class 			snake_case		(   __UpperCAmelCase   ):
      lowerCamelCase__						= '''m2m_100'''
      lowerCamelCase__						= ['''past_key_values''']
      lowerCamelCase__						= {'''num_attention_heads''': '''encoder_attention_heads''', '''hidden_size''': '''d_model'''}

      def __init__(			self   :int						,							_lowerCamelCase   :Union[str, Any]=1_2_8_1_1_2						,							_lowerCamelCase   :str=1_0_2_4						,							_lowerCamelCase   :Any=1_2						,							_lowerCamelCase   :Dict=4_0_9_6						,							_lowerCamelCase   :List[str]=1_6						,							_lowerCamelCase   :Union[str, Any]=1_2						,							_lowerCamelCase   :Any=4_0_9_6						,							_lowerCamelCase   :str=1_6						,							_lowerCamelCase   :Union[str, Any]=0.0_5						,							_lowerCamelCase   :Any=0.0_5						,							_lowerCamelCase   :int=True						,							_lowerCamelCase   :Dict=True						,							_lowerCamelCase   :List[str]="relu"						,							_lowerCamelCase   :List[Any]=1_0_2_4						,							_lowerCamelCase   :Dict=0.1						,							_lowerCamelCase   :List[Any]=0.1						,							_lowerCamelCase   :Any=0.0						,							_lowerCamelCase   :Tuple=0.0_2						,							_lowerCamelCase   :Dict=2						,							_lowerCamelCase   :List[str]=True						,							_lowerCamelCase   :Any=1						,							_lowerCamelCase   :Dict=0						,							_lowerCamelCase   :List[Any]=2						,							**_lowerCamelCase   :Optional[Any]						,							):
       __SCREAMING_SNAKE_CASE :			Any												=       vocab_size
       __SCREAMING_SNAKE_CASE :			Any												=       max_position_embeddings
       __SCREAMING_SNAKE_CASE :			int												=       d_model
       __SCREAMING_SNAKE_CASE :			List[Any]												=       encoder_ffn_dim
       __SCREAMING_SNAKE_CASE :			Dict												=       encoder_layers
       __SCREAMING_SNAKE_CASE :			int												=       encoder_attention_heads
       __SCREAMING_SNAKE_CASE :			Dict												=       decoder_ffn_dim
       __SCREAMING_SNAKE_CASE :			Union[str, Any]												=       decoder_layers
       __SCREAMING_SNAKE_CASE :			Optional[Any]												=       decoder_attention_heads
       __SCREAMING_SNAKE_CASE :			Optional[Any]												=       dropout
       __SCREAMING_SNAKE_CASE :			Union[str, Any]												=       attention_dropout
       __SCREAMING_SNAKE_CASE :			List[str]												=       activation_dropout
       __SCREAMING_SNAKE_CASE :			List[Any]												=       activation_function
       __SCREAMING_SNAKE_CASE :			Any												=       init_std
       __SCREAMING_SNAKE_CASE :			List[Any]												=       encoder_layerdrop
       __SCREAMING_SNAKE_CASE :			Union[str, Any]												=       decoder_layerdrop
       __SCREAMING_SNAKE_CASE :			Union[str, Any]												=       use_cache
       __SCREAMING_SNAKE_CASE :			List[str]												=       encoder_layers
       __SCREAMING_SNAKE_CASE :			str												=       scale_embedding  # scale factor will be sqrt(d_model) if True

       super().__init__(
           pad_token_id=_lowerCamelCase						,							bos_token_id=_lowerCamelCase						,							eos_token_id=_lowerCamelCase						,							is_encoder_decoder=_lowerCamelCase						,							decoder_start_token_id=_lowerCamelCase						,							**_lowerCamelCase						,							)







class 			snake_case		(   __UpperCAmelCase   ):

      @property
      def 						SCREAMING_SNAKE_CASE_			(			self   :int						):
       __SCREAMING_SNAKE_CASE :			str												=       OrderedDict(
           [
               ('''input_ids''', {0: '''batch''', 1: '''encoder_sequence'''}),
               ('''attention_mask''', {0: '''batch''', 1: '''encoder_sequence'''}),
           ]						)

       if self.use_past:
        __SCREAMING_SNAKE_CASE :			Dict												=       {0: '''batch'''}
        __SCREAMING_SNAKE_CASE :			Any												=       {0: '''batch''', 1: '''past_decoder_sequence + sequence'''}
       else:
        __SCREAMING_SNAKE_CASE :			int												=       {0: '''batch''', 1: '''decoder_sequence'''}
        __SCREAMING_SNAKE_CASE :			List[Any]												=       {0: '''batch''', 1: '''decoder_sequence'''}

       if self.use_past:
        self.fill_with_past_key_values_(_lowerCamelCase						,							direction='''inputs'''						)
       return common_inputs

      def 						SCREAMING_SNAKE_CASE_			(			self   :Tuple						,							_lowerCamelCase   :PreTrainedTokenizer						,							_lowerCamelCase   :int = -1						,							_lowerCamelCase   :int = -1						,							_lowerCamelCase   :bool = False						,							_lowerCamelCase   :Optional[TensorType] = None						,							):
       # Copied from OnnxConfig.generate_dummy_inputs
       # Did not use super(OnnxConfigWithPast, self).generate_dummy_inputs for code clarity.
       # If dynamic axis (-1) we forward with a fixed dimension of 2 samples to avoid optimizations made by ONNX
       __SCREAMING_SNAKE_CASE :			List[Any]												=       compute_effective_axis_dimension(
           _lowerCamelCase						,							fixed_dimension=OnnxConfig.default_fixed_batch						,							num_token_to_add=0						)

       # If dynamic axis (-1) we forward with a fixed dimension of 8 tokens to avoid optimizations made by ONNX
       __SCREAMING_SNAKE_CASE :			List[str]												=       tokenizer.num_special_tokens_to_add(_lowerCamelCase						)
       __SCREAMING_SNAKE_CASE :			int												=       compute_effective_axis_dimension(
           _lowerCamelCase						,							fixed_dimension=OnnxConfig.default_fixed_sequence						,							num_token_to_add=_lowerCamelCase						)

       # Generate dummy inputs according to compute batch and sequence
       __SCREAMING_SNAKE_CASE :			int												=       [''' '''.join([tokenizer.unk_token]						) * seq_length] * batch_size
       __SCREAMING_SNAKE_CASE :			Union[str, Any]												=       dict(tokenizer(_lowerCamelCase						,							return_tensors=_lowerCamelCase						)						)
       return common_inputs

      def 						SCREAMING_SNAKE_CASE_			(			self   :str						,							_lowerCamelCase   :PreTrainedTokenizer						,							_lowerCamelCase   :int = -1						,							_lowerCamelCase   :int = -1						,							_lowerCamelCase   :bool = False						,							_lowerCamelCase   :Optional[TensorType] = None						,							):
       __SCREAMING_SNAKE_CASE :			Dict												=       self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
           _lowerCamelCase						,							_lowerCamelCase						,							_lowerCamelCase						,							_lowerCamelCase						,							_lowerCamelCase						)

       # Generate decoder inputs
       __SCREAMING_SNAKE_CASE :			Dict												=       seq_length if not self.use_past else 1
       __SCREAMING_SNAKE_CASE :			Any												=       self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
           _lowerCamelCase						,							_lowerCamelCase						,							_lowerCamelCase						,							_lowerCamelCase						,							_lowerCamelCase						)
       __SCREAMING_SNAKE_CASE :			Optional[int]												=       {f'''decoder_{name}''': tensor for name, tensor in decoder_inputs.items()}
       __SCREAMING_SNAKE_CASE :			Optional[Any]												=       dict(**_lowerCamelCase						,							**_lowerCamelCase						)

       if self.use_past:
        if not is_torch_available():
         raise ValueError('''Cannot generate dummy past_keys inputs without PyTorch installed.'''						)
        else:
         import torch
        __SCREAMING_SNAKE_CASE							,      __SCREAMING_SNAKE_CASE :			int												=       common_inputs['''input_ids'''].shape
        __SCREAMING_SNAKE_CASE :			Tuple												=       common_inputs['''decoder_input_ids'''].shape[1]
        __SCREAMING_SNAKE_CASE							,      __SCREAMING_SNAKE_CASE :			Optional[Any]												=       self.num_attention_heads
        __SCREAMING_SNAKE_CASE :			List[str]												=       (
            batch,
            num_encoder_attention_heads,
            encoder_seq_length,
            self._config.hidden_size // num_encoder_attention_heads,
        )
        __SCREAMING_SNAKE_CASE :			Union[str, Any]												=       decoder_seq_length + 3
        __SCREAMING_SNAKE_CASE :			List[str]												=       (
            batch,
            num_decoder_attention_heads,
            decoder_past_length,
            self._config.hidden_size // num_decoder_attention_heads,
        )

        __SCREAMING_SNAKE_CASE :			Any												=       torch.cat(
            [common_inputs['''decoder_attention_mask'''], torch.ones(_lowerCamelCase						,							_lowerCamelCase						)]						,							dim=1						)

        __SCREAMING_SNAKE_CASE :			Union[str, Any]												=       []
        # If the number of encoder and decoder layers are present in the model configuration, both are considered
        __SCREAMING_SNAKE_CASE							,      __SCREAMING_SNAKE_CASE :			Union[str, Any]												=       self.num_layers
        __SCREAMING_SNAKE_CASE :			Any												=       min(_lowerCamelCase						,							_lowerCamelCase						)
        __SCREAMING_SNAKE_CASE :			Tuple												=       max(_lowerCamelCase						,							_lowerCamelCase						) - min_num_layers
        __SCREAMING_SNAKE_CASE :			Optional[int]												=       '''encoder''' if num_encoder_layers > num_decoder_layers else '''decoder'''

        for _ in range(_lowerCamelCase						):
         common_inputs["past_key_values"].append(
             (
                 torch.zeros(_lowerCamelCase						),
                 torch.zeros(_lowerCamelCase						),
                 torch.zeros(_lowerCamelCase						),
                 torch.zeros(_lowerCamelCase						),
             )						)
        # TODO: test this.
        __SCREAMING_SNAKE_CASE :			Any												=       encoder_shape if remaining_side_name == '''encoder''' else decoder_shape
        for _ in range(_lowerCamelCase						,							_lowerCamelCase						):
         common_inputs["past_key_values"].append((torch.zeros(_lowerCamelCase						), torch.zeros(_lowerCamelCase						))						)
       return common_inputs



      lowerCamelCase__						= _generate_dummy_inputs_for_default_and_seqaseq_lm

