

"""simple docstring"""





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					 =				logging.get_logger(__name__)

_a					 =				{
    '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    (      lowercase  ):







 """simple docstring"""







 __UpperCAmelCase      :   Any  						=      "blenderbot"
 __UpperCAmelCase      :   Optional[Any]  						=      ["past_key_values"]
 __UpperCAmelCase      :   Dict  						=      {"num_attention_heads": "encoder_attention_heads", "hidden_size": "d_model"}


 def __init__(     self				:     str,   UpperCAmelCase__				:     List[Any]=8_0_0_8,   UpperCAmelCase__				:     Dict=1_2_8,   UpperCAmelCase__				:     Tuple=2,   UpperCAmelCase__				:     List[str]=1_0_2_4_0,   UpperCAmelCase__				:     Dict=3_2,   UpperCAmelCase__				:     Tuple=2_4,   UpperCAmelCase__				:     str=1_0_2_4_0,   UpperCAmelCase__				:     Any=3_2,   UpperCAmelCase__				:     Tuple=0.0,   UpperCAmelCase__				:     Tuple=0.0,   UpperCAmelCase__				:     Optional[Any]=True,   UpperCAmelCase__				:     List[str]=True,   UpperCAmelCase__				:     int="gelu",   UpperCAmelCase__				:     Any=2_5_6_0,   UpperCAmelCase__				:     Tuple=0.1,   UpperCAmelCase__				:     List[Any]=0.0,   UpperCAmelCase__				:     int=0.0,   UpperCAmelCase__				:     Tuple=0.02,   UpperCAmelCase__				:     Tuple=1,   UpperCAmelCase__				:     Any=False,   UpperCAmelCase__				:     List[str]=0,   UpperCAmelCase__				:     Dict=1,   UpperCAmelCase__				:     Dict=2,   UpperCAmelCase__				:     Union[str, Any]=3,   UpperCAmelCase__				:     int=2,   **UpperCAmelCase__				:     Any,   ):
    __lowercase								=		vocab_size
    __lowercase								=		max_position_embeddings
    __lowercase								=		d_model
    __lowercase								=		encoder_ffn_dim
    __lowercase								=		encoder_layers
    __lowercase								=		encoder_attention_heads
    __lowercase								=		decoder_ffn_dim
    __lowercase								=		decoder_layers
    __lowercase								=		decoder_attention_heads
    __lowercase								=		dropout
    __lowercase								=		attention_dropout
    __lowercase								=		activation_dropout
    __lowercase								=		activation_function
    __lowercase								=		init_std
    __lowercase								=		encoder_layerdrop
    __lowercase								=		decoder_layerdrop
    __lowercase								=		use_cache
    __lowercase								=		encoder_layers
    __lowercase								=		scale_embedding  # scale factor will be sqrt(d_model) if True

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







class    _lowerCAmelCase    (      lowercase  ):







 """simple docstring"""







 @property
 def    _lowercase					(     self				:     int      ):
    if self.task in ["default", "seq2seq-lm"]:
       __lowercase								=		OrderedDict(
           [
               ("input_ids", {0: "batch", 1: "encoder_sequence"}),
               ("attention_mask", {0: "batch", 1: "encoder_sequence"}),
           ]      )
       if self.use_past:
          __lowercase								=		{0: "batch"}
          __lowercase								=		{0: "batch", 1: "past_decoder_sequence + sequence"}
       else:
          __lowercase								=		{0: "batch", 1: "decoder_sequence"}
          __lowercase								=		{0: "batch", 1: "decoder_sequence"}
       if self.use_past:
          self.fill_with_past_key_values_(UpperCAmelCase__,   direction="inputs"      )
    elif self.task == "causal-lm":
       __lowercase								=		OrderedDict(
           [
               ("input_ids", {0: "batch", 1: "encoder_sequence"}),
               ("attention_mask", {0: "batch", 1: "encoder_sequence"}),
           ]      )
       if self.use_past:
          __lowercase						,__lowercase								=		self.num_layers
          for i in range(UpperCAmelCase__      ):
             __lowercase								=		{0: "batch", 2: "past_sequence + sequence"}
             __lowercase								=		{0: "batch", 2: "past_sequence + sequence"}
    else:
       __lowercase								=		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    _lowercase					(     self				:     List[Any]      ):
    if self.task in ["default", "seq2seq-lm"]:
       __lowercase								=		super().outputs
    else:
       __lowercase								=		super(UpperCAmelCase__,   self      ).outputs
       if self.use_past:
          __lowercase						,__lowercase								=		self.num_layers
          for i in range(UpperCAmelCase__      ):
             __lowercase								=		{0: "batch", 2: "past_sequence + sequence"}
             __lowercase								=		{0: "batch", 2: "past_sequence + sequence"}
    return common_outputs


 def    _lowercase					(     self				:     Tuple,   UpperCAmelCase__				:     PreTrainedTokenizer,   UpperCAmelCase__				:     int = -1,   UpperCAmelCase__				:     int = -1,   UpperCAmelCase__				:     bool = False,   UpperCAmelCase__				:     Optional[TensorType] = None,   ):
    __lowercase								=		self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
        UpperCAmelCase__,   UpperCAmelCase__,   UpperCAmelCase__,   UpperCAmelCase__,   UpperCAmelCase__      )
    # Generate decoder inputs
    __lowercase								=		seq_length if not self.use_past else 1
    __lowercase								=		self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
        UpperCAmelCase__,   UpperCAmelCase__,   UpperCAmelCase__,   UpperCAmelCase__,   UpperCAmelCase__      )
    __lowercase								=		{F"""decoder_{name}""": tensor for name, tensor in decoder_inputs.items()}
    __lowercase								=		dict(**UpperCAmelCase__,   **UpperCAmelCase__      )

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

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


 def    _lowercase					(     self				:     Union[str, Any],   UpperCAmelCase__				:     PreTrainedTokenizer,   UpperCAmelCase__				:     int = -1,   UpperCAmelCase__				:     int = -1,   UpperCAmelCase__				:     bool = False,   UpperCAmelCase__				:     Optional[TensorType] = None,   ):
    __lowercase								=		self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
        UpperCAmelCase__,   UpperCAmelCase__,   UpperCAmelCase__,   UpperCAmelCase__,   UpperCAmelCase__      )

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


 def    _lowercase					(     self				:     List[Any],   UpperCAmelCase__				:     PreTrainedTokenizer,   UpperCAmelCase__				:     int = -1,   UpperCAmelCase__				:     int = -1,   UpperCAmelCase__				:     bool = False,   UpperCAmelCase__				:     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
    __lowercase								=		compute_effective_axis_dimension(
        UpperCAmelCase__,   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
    __lowercase								=		tokenizer.num_special_tokens_to_add(UpperCAmelCase__      )
    __lowercase								=		compute_effective_axis_dimension(
        UpperCAmelCase__,   fixed_dimension=OnnxConfig.default_fixed_sequence,   num_token_to_add=UpperCAmelCase__      )

    # Generate dummy inputs according to compute batch and sequence
    __lowercase								=		[" ".join([tokenizer.unk_token]      ) * seq_length] * batch_size
    __lowercase								=		dict(tokenizer(UpperCAmelCase__,   return_tensors=UpperCAmelCase__      )      )
    return common_inputs


 def    _lowercase					(     self				:     Tuple,   UpperCAmelCase__				:     PreTrainedTokenizer,   UpperCAmelCase__				:     int = -1,   UpperCAmelCase__				:     int = -1,   UpperCAmelCase__				:     bool = False,   UpperCAmelCase__				:     Optional[TensorType] = None,   ):
    if self.task in ["default", "seq2seq-lm"]:
       __lowercase								=		self._generate_dummy_inputs_for_default_and_seqaseq_lm(
           UpperCAmelCase__,   batch_size=UpperCAmelCase__,   seq_length=UpperCAmelCase__,   is_pair=UpperCAmelCase__,   framework=UpperCAmelCase__      )

    elif self.task == "causal-lm":
       __lowercase								=		self._generate_dummy_inputs_for_causal_lm(
           UpperCAmelCase__,   batch_size=UpperCAmelCase__,   seq_length=UpperCAmelCase__,   is_pair=UpperCAmelCase__,   framework=UpperCAmelCase__      )
    else:
       __lowercase								=		self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
           UpperCAmelCase__,   batch_size=UpperCAmelCase__,   seq_length=UpperCAmelCase__,   is_pair=UpperCAmelCase__,   framework=UpperCAmelCase__      )

    return common_inputs


 def    _lowercase					(     self				:     Optional[Any],   UpperCAmelCase__				:     Tuple,   UpperCAmelCase__				:     str,   UpperCAmelCase__				:     Optional[int],   UpperCAmelCase__				:     List[Any]      ):
    if self.task in ["default", "seq2seq-lm"]:
       __lowercase								=		super()._flatten_past_key_values_(UpperCAmelCase__,   UpperCAmelCase__,   UpperCAmelCase__,   UpperCAmelCase__      )
    else:
       __lowercase								=		super(UpperCAmelCase__,   self      )._flatten_past_key_values_(
           UpperCAmelCase__,   UpperCAmelCase__,   UpperCAmelCase__,   UpperCAmelCase__      )



 def    _lowercase					(     self				:     Optional[int],   UpperCAmelCase__				:     Mapping[str, Mapping[int, str]],   UpperCAmelCase__				:     str      ):
    if direction not in ["inputs", "outputs"]:
       raise ValueError(F"""direction must either be \"inputs\" or \"outputs\", but {direction} was given"""      )

    __lowercase								=		"past_key_values" if direction == "inputs" else "present"
    __lowercase						,__lowercase								=		self.num_layers

    __lowercase								=		"past_encoder_sequence"
    __lowercase								=		"past_decoder_sequence" if direction == "inputs" else "past_decoder_sequence + sequence"

    for i in range(UpperCAmelCase__      ):
       __lowercase								=		{0: "batch", 2: decoder_sequence}
       __lowercase								=		{0: "batch", 2: decoder_sequence}
       __lowercase								=		{0: "batch", 2: encoder_sequence}
       __lowercase								=		{0: "batch", 2: encoder_sequence}







"""simple docstring"""





def     _A    (    UpperCamelCase_	:			str)      ->		int:
   '''simple docstring'''


   __lowercase								=		0
   for plain_chr in plain_text:
      __lowercase								=		(
          ord(UpperCamelCase_) + (hash_value << 6) + (hash_value << 16) - hash_value
      )
   return hash_value




