




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


_snake_case										=       logging.get_logger(__name__)

_snake_case										=       {
    "facebook/blenderbot_small-90M": "https://huggingface.co/facebook/blenderbot_small-90M/resolve/main/config.json",
    # See all BlenderbotSmall models at https://huggingface.co/models?filter=blenderbot_small
}







class 						lowercase							(   UpperCamelCase__		):
     _a							 =						"blenderbot-small"
     _a							 =						["past_key_values"]
     _a							 =						{"num_attention_heads": "encoder_attention_heads", "hidden_size": "d_model"}

     def __init__(  self		,     _a=5_0265		,     _a=512		,     _a=8		,     _a=2048		,     _a=16		,     _a=8		,     _a=2048		,     _a=16		,     _a=0.0		,     _a=0.0		,     _a=True		,     _a=True		,     _a="gelu"		,     _a=512		,     _a=0.1		,     _a=0.0		,     _a=0.0		,     _a=0.02		,     _a=1		,     _a=False		,     _a=0		,     _a=1		,     _a=2		,     _a=2		,     **_a		,     )						->							str:
           _A							:     Dict			=						vocab_size
           _A							:     List[Any]			=						max_position_embeddings
           _A							:     Union[str, Any]			=						d_model
           _A							:     List[str]			=						encoder_ffn_dim
           _A							:     Optional[int]			=						encoder_layers
           _A							:     str			=						encoder_attention_heads
           _A							:     int			=						decoder_ffn_dim
           _A							:     int			=						decoder_layers
           _A							:     int			=						decoder_attention_heads
           _A							:     List[Any]			=						dropout
           _A							:     int			=						attention_dropout
           _A							:     List[str]			=						activation_dropout
           _A							:     int			=						activation_function
           _A							:     str			=						init_std
           _A							:     Optional[int]			=						encoder_layerdrop
           _A							:     Tuple			=						decoder_layerdrop
           _A							:     Dict			=						use_cache
           _A							:     Any			=						encoder_layers
           _A							:     Optional[Any]			=						scale_embedding  # scale factor will be sqrt(d_model) if True

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







class 						lowercase							(   UpperCamelCase__		):

     @property
     def 					a__	(  self				)						->							Optional[int]:





           if self.task in ["default", "seq2seq-lm"]:
                 _A							:     List[str]			=						OrderedDict(
                     [
                         ("""input_ids""", {0: """batch""", 1: """encoder_sequence"""}),
                         ("""attention_mask""", {0: """batch""", 1: """encoder_sequence"""}),
                     ]				)

                 if self.use_past:
                       _A							:     Optional[Any]			=						{0: "batch"}
                       _A							:     int			=						{0: "batch", 1: "past_decoder_sequence + sequence"}
                 else:
                       _A							:     str			=						{0: "batch", 1: "decoder_sequence"}
                       _A							:     Any			=						{0: "batch", 1: "decoder_sequence"}

                 if self.use_past:
                       self.fill_with_past_key_values_(snake_case__		,     direction="""inputs"""				)
           elif self.task == "causal-lm":
                 # TODO: figure this case out.
                 _A							:     Tuple			=						OrderedDict(
                     [
                         ("""input_ids""", {0: """batch""", 1: """encoder_sequence"""}),
                         ("""attention_mask""", {0: """batch""", 1: """encoder_sequence"""}),
                     ]				)
                 if self.use_past:
                       _A							:     Union[str, Any]			=						self.num_layers
                       for i in range(snake_case__				):
                             _A							:     List[Any]			=						{0: "batch", 2: "past_sequence + sequence"}
                             _A							:     Optional[int]			=						{0: "batch", 2: "past_sequence + sequence"}
           else:
                 _A							:     List[str]			=						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
     def 					a__	(  self				)						->							Any:





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

     def 					a__	(  self		,     _a		,     _a = -1		,     _a = -1		,     _a = False		,     _a = None		,     )						->							int:
           _A							:     List[Any]			=						self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
               snake_case__		,     snake_case__		,     snake_case__		,     snake_case__		,     snake_case__				)

           # Generate decoder inputs
           _A							:     str			=						seq_length if not self.use_past else 1
           _A							:     Tuple			=						self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
               snake_case__		,     snake_case__		,     snake_case__		,     snake_case__		,     snake_case__				)
           _A							:     Any			=						{F'''decoder_{name}''': tensor for name, tensor in decoder_inputs.items()}
           _A							:     str			=						dict(**snake_case__		,     **snake_case__				)

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

                 _A							:     Dict			=						torch.cat(
                     [common_inputs["""decoder_attention_mask"""], torch.ones(snake_case__		,     snake_case__				)]		,     dim=1				)

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

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

     def 					a__	(  self		,     _a		,     _a = -1		,     _a = -1		,     _a = False		,     _a = None		,     )						->							List[str]:
           _A							:     Union[str, Any]			=						self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
               snake_case__		,     snake_case__		,     snake_case__		,     snake_case__		,     snake_case__				)

           if self.use_past:
                 if not is_torch_available():
                       raise ValueError("""Cannot generate dummy past_keys inputs without PyTorch installed."""				)
                 else:
                       import torch
                 _A							:     Dict			=						common_inputs["input_ids"].shape
                 # Not using the same length for past_key_values
                 _A							:     List[Any]			=						seqlen + 2
                 _A							:     Optional[int]			=						self.num_layers
                 _A							:     Tuple			=						self.num_attention_heads
                 _A							:     Optional[int]			=						(
                     batch,
                     num_encoder_attention_heads,
                     past_key_values_length,
                     self._config.hidden_size // num_encoder_attention_heads,
                 )

                 _A							:     List[Any]			=						common_inputs["attention_mask"].dtype
                 _A							:     List[str]			=						torch.cat(
                     [common_inputs["""attention_mask"""], torch.ones(snake_case__		,     snake_case__		,     dtype=snake_case__				)]		,     dim=1				)
                 _A							:     Union[str, Any]			=						[
                     (torch.zeros(snake_case__				), torch.zeros(snake_case__				)) for _ in range(snake_case__				)
                 ]
           return common_inputs

     def 					a__	(  self		,     _a		,     _a = -1		,     _a = -1		,     _a = False		,     _a = None		,     )						->							str:
           _A							:     Optional[int]			=						compute_effective_axis_dimension(
               snake_case__		,     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
           _A							:     Any			=						tokenizer.num_special_tokens_to_add(snake_case__				)
           _A							:     str			=						compute_effective_axis_dimension(
               snake_case__		,     fixed_dimension=OnnxConfig.default_fixed_sequence		,     num_token_to_add=snake_case__				)

           # Generate dummy inputs according to compute batch and sequence
           _A							:     List[Any]			=						[" ".join([tokenizer.unk_token]				) * seq_length] * batch_size
           _A							:     Tuple			=						dict(tokenizer(snake_case__		,     return_tensors=snake_case__				)				)
           return common_inputs

     def 					a__	(  self		,     _a		,     _a = -1		,     _a = -1		,     _a = False		,     _a = None		,     )						->							str:





           if self.task in ["default", "seq2seq-lm"]:
                 _A							:     List[str]			=						self._generate_dummy_inputs_for_default_and_seqaseq_lm(
                     snake_case__		,     batch_size=snake_case__		,     seq_length=snake_case__		,     is_pair=snake_case__		,     framework=snake_case__				)

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

           return common_inputs



     def 					a__	(  self		,     _a		,     _a		,     _a		,     _a				)						->							Optional[int]:





           if self.task in ["default", "seq2seq-lm"]:
                 _A							:     Tuple			=						super()._flatten_past_key_values_(snake_case__		,     snake_case__		,     snake_case__		,     snake_case__				)
           else:
                 _A							:     Dict			=						super(snake_case__		,     self				)._flatten_past_key_values_(
                     snake_case__		,     snake_case__		,     snake_case__		,     snake_case__				)





"""simple docstring"""







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


lowerCAmelCase__      				=   logging.get_logger(__name__)

lowerCAmelCase__      				=   {
    '''facebook/dpr-ctx_encoder-single-nq-base''': (
        '''https://huggingface.co/facebook/dpr-ctx_encoder-single-nq-base/resolve/main/config.json'''
    ),
    '''facebook/dpr-question_encoder-single-nq-base''': (
        '''https://huggingface.co/facebook/dpr-question_encoder-single-nq-base/resolve/main/config.json'''
    ),
    '''facebook/dpr-reader-single-nq-base''': (
        '''https://huggingface.co/facebook/dpr-reader-single-nq-base/resolve/main/config.json'''
    ),
    '''facebook/dpr-ctx_encoder-multiset-base''': (
        '''https://huggingface.co/facebook/dpr-ctx_encoder-multiset-base/resolve/main/config.json'''
    ),
    '''facebook/dpr-question_encoder-multiset-base''': (
        '''https://huggingface.co/facebook/dpr-question_encoder-multiset-base/resolve/main/config.json'''
    ),
    '''facebook/dpr-reader-multiset-base''': (
        '''https://huggingface.co/facebook/dpr-reader-multiset-base/resolve/main/config.json'''
    ),
}


class       SCREAMING_SNAKE_CASE__				(		lowercase				):
       """simple docstring"""


       a  :				int   ="dpr"

       def __init__(						self		,     snake_case__=30_522		,     snake_case__=768		,     snake_case__=12		,     snake_case__=12		,     snake_case__=3_072		,     snake_case__="gelu"		,     snake_case__=0.1		,     snake_case__=0.1		,     snake_case__=512		,     snake_case__=2		,     snake_case__=0.02		,     snake_case__=1e-12		,     snake_case__=0		,     snake_case__="absolute"		,     snake_case__ = 0		,     **snake_case__		,     ):






         """simple docstring"""





         super().__init__(pad_token_id=snake_case__		,     **snake_case__						)

         lowerCAmelCase     :     Union[str, Any]								=							vocab_size
         lowerCAmelCase     :     str								=							hidden_size
         lowerCAmelCase     :     Any								=							num_hidden_layers
         lowerCAmelCase     :     Optional[int]								=							num_attention_heads
         lowerCAmelCase     :     Union[str, Any]								=							hidden_act
         lowerCAmelCase     :     Dict								=							intermediate_size
         lowerCAmelCase     :     Union[str, Any]								=							hidden_dropout_prob
         lowerCAmelCase     :     Dict								=							attention_probs_dropout_prob
         lowerCAmelCase     :     Dict								=							max_position_embeddings
         lowerCAmelCase     :     Tuple								=							type_vocab_size
         lowerCAmelCase     :     Any								=							initializer_range
         lowerCAmelCase     :     Any								=							layer_norm_eps
         lowerCAmelCase     :     Dict								=							projection_dim
         lowerCAmelCase     :     Dict								=							position_embedding_type





