


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

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


a					:				List[Any]       =      logging.get_logger(__name__)

a					:				str       =      {
    'facebook/blenderbot-3B': 'https://huggingface.co/facebook/blenderbot-3B/resolve/main/config.json',
    # See all Blenderbot models at https://huggingface.co/models?filter=blenderbot
}

class   lowerCamelCase						(	SCREAMING_SNAKE_CASE  ):
       _UpperCamelCase     		=   """blenderbot"""
       _UpperCamelCase     		=   ["""past_key_values"""]
       _UpperCamelCase     		=   {"""num_attention_heads""": """encoder_attention_heads""", """hidden_size""": """d_model"""}

       def __init__(      self						,    a__=80_08						,    a__=1_28						,    a__=2						,    a__=1_02_40						,    a__=32						,    a__=24						,    a__=1_02_40						,    a__=32						,    a__=0.0						,    a__=0.0						,    a__=True						,    a__=True						,    a__="gelu"						,    a__=25_60						,    a__=0.1						,    a__=0.0						,    a__=0.0						,    a__=0.02						,    a__=1						,    a__=False						,    a__=0						,    a__=1						,    a__=2						,    a__=3						,    a__=2						,    **a__						,    ):






        '''simple docstring'''






        snake_case :			int							=   vocab_size
        snake_case :			Dict							=   max_position_embeddings
        snake_case :			List[Any]							=   d_model
        snake_case :			Optional[int]							=   encoder_ffn_dim
        snake_case :			Dict							=   encoder_layers
        snake_case :			List[str]							=   encoder_attention_heads
        snake_case :			Union[str, Any]							=   decoder_ffn_dim
        snake_case :			Tuple							=   decoder_layers
        snake_case :			Union[str, Any]							=   decoder_attention_heads
        snake_case :			Optional[int]							=   dropout
        snake_case :			Union[str, Any]							=   attention_dropout
        snake_case :			List[Any]							=   activation_dropout
        snake_case :			Optional[Any]							=   activation_function
        snake_case :			List[Any]							=   init_std
        snake_case :			Any							=   encoder_layerdrop
        snake_case :			int							=   decoder_layerdrop
        snake_case :			Any							=   use_cache
        snake_case :			Any							=   encoder_layers
        snake_case :			List[str]							=   scale_embedding  # scale factor will be sqrt(d_model) if True

        super().__init__(
            pad_token_id=a__						,    bos_token_id=a__						,    eos_token_id=a__						,    is_encoder_decoder=a__						,    decoder_start_token_id=a__						,    encoder_no_repeat_ngram_size=a__						,    forced_eos_token_id=a__						,    **a__						,    )







class   lowerCamelCase						(	SCREAMING_SNAKE_CASE  ):

       @property
       def 					UpperCAmelCase					(      self       ):






        '''simple docstring'''






        if self.task in ["default", "seq2seq-lm"]:
         snake_case :			Any							=   OrderedDict(
             [
                 ('''input_ids''', {0: '''batch''', 1: '''encoder_sequence'''}),
                 ('''attention_mask''', {0: '''batch''', 1: '''encoder_sequence'''}),
             ]       )
         if self.use_past:
          snake_case :			List[Any]							=   {0: '''batch'''}
          snake_case :			Tuple							=   {0: '''batch''', 1: '''past_decoder_sequence + sequence'''}
         else:
          snake_case :			Optional[Any]							=   {0: '''batch''', 1: '''decoder_sequence'''}
          snake_case :			Optional[Any]							=   {0: '''batch''', 1: '''decoder_sequence'''}
         if self.use_past:
          self.fill_with_past_key_values_(a__						,    direction='''inputs'''       )
        elif self.task == "causal-lm":
         snake_case :			List[str]							=   OrderedDict(
             [
                 ('''input_ids''', {0: '''batch''', 1: '''encoder_sequence'''}),
                 ('''attention_mask''', {0: '''batch''', 1: '''encoder_sequence'''}),
             ]       )
         if self.use_past:
          snake_case	,       snake_case :			Dict							=   self.num_layers
          for i in range(a__       ):
           snake_case :			str							=   {0: '''batch''', 2: '''past_sequence + sequence'''}
           snake_case :			Optional[int]							=   {0: '''batch''', 2: '''past_sequence + sequence'''}
        else:
         snake_case :			Any							=   OrderedDict(
             [
                 ('''input_ids''', {0: '''batch''', 1: '''encoder_sequence'''}),
                 ('''attention_mask''', {0: '''batch''', 1: '''encoder_sequence'''}),
                 ('''decoder_input_ids''', {0: '''batch''', 1: '''decoder_sequence'''}),
                 ('''decoder_attention_mask''', {0: '''batch''', 1: '''decoder_sequence'''}),
             ]       )

        return common_inputs

       @property
       # Copied from transformers.models.bart.configuration_bart.BartOnnxConfig.outputs
       def 					UpperCAmelCase					(      self       ):






        '''simple docstring'''






        if self.task in ["default", "seq2seq-lm"]:
         snake_case :			List[Any]							=   super().outputs
        else:
         snake_case :			List[Any]							=   super(a__						,    self       ).outputs
         if self.use_past:
          snake_case	,       snake_case :			int							=   self.num_layers
          for i in range(a__       ):
           snake_case :			Union[str, Any]							=   {0: '''batch''', 2: '''past_sequence + sequence'''}
           snake_case :			Optional[Any]							=   {0: '''batch''', 2: '''past_sequence + sequence'''}
        return common_outputs

       def 					UpperCAmelCase					(      self						,    a__						,    a__ = -1						,    a__ = -1						,    a__ = False						,    a__ = None						,    ):






        '''simple docstring'''






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

        if self.use_past:
         if not is_torch_available():
          raise ValueError('''Cannot generate dummy past_keys inputs without PyTorch installed.'''       )
         else:
          import torch
         snake_case	,       snake_case :			Any							=   common_inputs['''input_ids'''].shape
         snake_case :			Optional[Any]							=   common_inputs['''decoder_input_ids'''].shape[1]
         snake_case	,       snake_case :			Tuple							=   self.num_attention_heads
         snake_case :			Optional[int]							=   (
             batch,
             num_encoder_attention_heads,
             encoder_seq_length,
             self._config.hidden_size // num_encoder_attention_heads,
         )
         snake_case :			int							=   decoder_seq_length
         snake_case :			Tuple							=   (
             batch,
             num_decoder_attention_heads,
             decoder_past_length,
             self._config.hidden_size // num_decoder_attention_heads,
         )
         snake_case :			Any							=   torch.cat(
             [common_inputs['''decoder_attention_mask'''], torch.ones(a__						,    a__       )]						,    dim=1       )
         snake_case :			int							=   []
         snake_case	,       snake_case :			str							=   self.num_layers

         for _ in range(a__       ):
          common_inputs["past_key_values"].append(
              (
                  torch.zeros(a__       ),
                  torch.zeros(a__       ),
                  torch.zeros(a__       ),
                  torch.zeros(a__       ),
              )       )
        return common_inputs

       def 					UpperCAmelCase					(      self						,    a__						,    a__ = -1						,    a__ = -1						,    a__ = False						,    a__ = None						,    ):






        '''simple docstring'''






        snake_case :			Dict							=   self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
            a__						,    a__						,    a__						,    a__						,    a__       )

        if self.use_past:
         if not is_torch_available():
          raise ValueError('''Cannot generate dummy past_keys inputs without PyTorch installed.'''       )
         else:
          import torch
         snake_case	,       snake_case :			int							=   common_inputs['''input_ids'''].shape
         snake_case :			str							=   seqlen
         snake_case	,       snake_case :			int							=   self.num_layers
         snake_case	,       snake_case :			int							=   self.num_attention_heads
         snake_case :			Union[str, Any]							=   (
             batch,
             num_encoder_attention_heads,
             past_key_values_length,
             self._config.hidden_size // num_encoder_attention_heads,
         )
         snake_case :			Tuple							=   common_inputs['''attention_mask'''].dtype
         snake_case :			Any							=   torch.cat(
             [common_inputs['''attention_mask'''], torch.ones(a__						,    a__						,    dtype=a__       )]						,    dim=1       )
         snake_case :			Tuple							=   [
             (torch.zeros(a__       ), torch.zeros(a__       )) for _ in range(a__       )
         ]
        return common_inputs

       def 					UpperCAmelCase					(      self						,    a__						,    a__ = -1						,    a__ = -1						,    a__ = False						,    a__ = None						,    ):






        '''simple docstring'''






        snake_case :			int							=   compute_effective_axis_dimension(
            a__						,    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
        snake_case :			Any							=   tokenizer.num_special_tokens_to_add(a__       )
        snake_case :			List[Any]							=   compute_effective_axis_dimension(
            a__						,    fixed_dimension=OnnxConfig.default_fixed_sequence						,    num_token_to_add=a__       )

        # Generate dummy inputs according to compute batch and sequence
        snake_case :			Tuple							=   [''' '''.join([tokenizer.unk_token]       ) * seq_length] * batch_size
        snake_case :			int							=   dict(tokenizer(a__						,    return_tensors=a__       )       )
        return common_inputs

       def 					UpperCAmelCase					(      self						,    a__						,    a__ = -1						,    a__ = -1						,    a__ = False						,    a__ = None						,    ):






        '''simple docstring'''






        if self.task in ["default", "seq2seq-lm"]:
         snake_case :			Union[str, Any]							=   self._generate_dummy_inputs_for_default_and_seqaseq_lm(
             a__						,    batch_size=a__						,    seq_length=a__						,    is_pair=a__						,    framework=a__       )

        elif self.task == "causal-lm":
         snake_case :			List[str]							=   self._generate_dummy_inputs_for_causal_lm(
             a__						,    batch_size=a__						,    seq_length=a__						,    is_pair=a__						,    framework=a__       )
        else:
         snake_case :			List[Any]							=   self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
             a__						,    batch_size=a__						,    seq_length=a__						,    is_pair=a__						,    framework=a__       )

        return common_inputs

       def 					UpperCAmelCase					(      self						,    a__						,    a__						,    a__						,    a__       ):






        '''simple docstring'''






        if self.task in ["default", "seq2seq-lm"]:
         snake_case :			str							=   super()._flatten_past_key_values_(a__						,    a__						,    a__						,    a__       )
        else:
         snake_case :			Dict							=   super(a__						,    self       )._flatten_past_key_values_(
             a__						,    a__						,    a__						,    a__       )



       def 					UpperCAmelCase					(      self						,    a__						,    a__       ):






        '''simple docstring'''






        if direction not in ["inputs", "outputs"]:
         raise ValueError(f'''direction must either be "inputs" or "outputs", but {direction} was given'''       )

        snake_case :			Dict							=   '''past_key_values''' if direction == '''inputs''' else '''present'''
        snake_case	,       snake_case :			Optional[Any]							=   self.num_layers

        snake_case :			Union[str, Any]							=   '''past_encoder_sequence'''
        snake_case :			Dict							=   '''past_decoder_sequence''' if direction == '''inputs''' else '''past_decoder_sequence + sequence'''

        for i in range(a__       ):
         snake_case :			Dict							=   {0: '''batch''', 2: decoder_sequence}
         snake_case :			int							=   {0: '''batch''', 2: decoder_sequence}
         snake_case :			Optional[Any]							=   {0: '''batch''', 2: encoder_sequence}
         snake_case :			Tuple							=   {0: '''batch''', 2: encoder_sequence}










import functools
import operator

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


a					:				Dict       =      logging.get_logger(__name__)

a					:				str       =      {
    '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   lowerCamelCase						(	SCREAMING_SNAKE_CASE  ):
       _UpperCamelCase     		=   """hubert"""

       def __init__(      self						,    a__=32						,    a__=7_68						,    a__=12						,    a__=12						,    a__=30_72						,    a__="gelu"						,    a__=0.1						,    a__=0.1						,    a__=0.1						,    a__=True						,    a__=0.0						,    a__=0.1						,    a__=0.1						,    a__=0.02						,    a__=1e-5						,    a__="group"						,    a__="gelu"						,    a__=(5_12, 5_12, 5_12, 5_12, 5_12, 5_12, 5_12)						,    a__=(5, 2, 2, 2, 2, 2, 2)						,    a__=(10, 3, 3, 3, 3, 2, 2)						,    a__=False						,    a__=1_28						,    a__=16						,    a__=False						,    a__=True						,    a__=0.05						,    a__=10						,    a__=2						,    a__=0.0						,    a__=10						,    a__=0						,    a__="sum"						,    a__=False						,    a__=False						,    a__=2_56						,    a__=0						,    a__=1						,    a__=2						,    **a__						,    ):






        '''simple docstring'''






        super().__init__(**a__						,    pad_token_id=a__						,    bos_token_id=a__						,    eos_token_id=a__       )
        snake_case :			List[str]							=   hidden_size
        snake_case :			List[str]							=   feat_extract_norm
        snake_case :			List[str]							=   feat_extract_activation
        snake_case :			Dict							=   list(a__       )
        snake_case :			Tuple							=   list(a__       )
        snake_case :			Dict							=   list(a__       )
        snake_case :			str							=   conv_bias
        snake_case :			Dict							=   num_conv_pos_embeddings
        snake_case :			Union[str, Any]							=   num_conv_pos_embedding_groups
        snake_case :			Optional[int]							=   len(self.conv_dim       )
        snake_case :			Tuple							=   num_hidden_layers
        snake_case :			Any							=   intermediate_size
        snake_case :			Optional[Any]							=   hidden_act
        snake_case :			str							=   num_attention_heads
        snake_case :			List[Any]							=   hidden_dropout
        snake_case :			Union[str, Any]							=   attention_dropout
        snake_case :			Dict							=   activation_dropout
        snake_case :			List[str]							=   feat_proj_layer_norm
        snake_case :			List[str]							=   feat_proj_dropout
        snake_case :			Union[str, Any]							=   final_dropout
        snake_case :			List[str]							=   layerdrop
        snake_case :			str							=   layer_norm_eps
        snake_case :			Tuple							=   initializer_range
        snake_case :			str							=   vocab_size
        snake_case :			Tuple							=   do_stable_layer_norm
        snake_case :			Dict							=   use_weighted_layer_sum
        snake_case :			Optional[Any]							=   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 :			Optional[int]							=   apply_spec_augment
        snake_case :			int							=   mask_time_prob
        snake_case :			Dict							=   mask_time_length
        snake_case :			Any							=   mask_time_min_masks
        snake_case :			Any							=   mask_feature_prob
        snake_case :			Union[str, Any]							=   mask_feature_length
        snake_case :			List[Any]							=   mask_feature_min_masks

        # ctc loss
        snake_case :			List[str]							=   ctc_loss_reduction
        snake_case :			Dict							=   ctc_zero_infinity



       @property
       def 					UpperCAmelCase					(      self       ):






        '''simple docstring'''






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






