


'''simple docstring'''

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

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


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

a_						:       List[Any]      			=				{
    """facebook/bart-large""": """https://huggingface.co/facebook/bart-large/resolve/main/config.json""",
    # See all BART models at https://huggingface.co/models?filter=bart
}



class   snake_case					(					lowercase    ):





  """simple docstring"""




  _lowerCamelCase						=						"bart"
  _lowerCamelCase						=						["past_key_values"]
  _lowerCamelCase						=						{"num_attention_heads": "encoder_attention_heads", "hidden_size": "d_model"}






  def __init__(					self    ,						UpperCamelCase=5_0265    ,						UpperCamelCase=1024    ,						UpperCamelCase=12    ,						UpperCamelCase=4096    ,						UpperCamelCase=16    ,						UpperCamelCase=12    ,						UpperCamelCase=4096    ,						UpperCamelCase=16    ,						UpperCamelCase=0.0    ,						UpperCamelCase=0.0    ,						UpperCamelCase="gelu"    ,						UpperCamelCase=1024    ,						UpperCamelCase=0.1    ,						UpperCamelCase=0.0    ,						UpperCamelCase=0.0    ,						UpperCamelCase=0.02    ,						UpperCamelCase=0.0    ,						UpperCamelCase=False    ,						UpperCamelCase=True    ,						UpperCamelCase=3    ,						UpperCamelCase=1    ,						UpperCamelCase=0    ,						UpperCamelCase=2    ,						UpperCamelCase=True    ,						UpperCamelCase=2    ,						UpperCamelCase=2    ,						**UpperCamelCase    ,						):







   """simple docstring"""
   lowerCamelCase_  				=						vocab_size
   lowerCamelCase_  				=						max_position_embeddings
   lowerCamelCase_  				=						d_model
   lowerCamelCase_  				=						encoder_ffn_dim
   lowerCamelCase_  				=						encoder_layers
   lowerCamelCase_  				=						encoder_attention_heads
   lowerCamelCase_  				=						decoder_ffn_dim
   lowerCamelCase_  				=						decoder_layers
   lowerCamelCase_  				=						decoder_attention_heads
   lowerCamelCase_  				=						dropout
   lowerCamelCase_  				=						attention_dropout
   lowerCamelCase_  				=						activation_dropout
   lowerCamelCase_  				=						activation_function
   lowerCamelCase_  				=						init_std
   lowerCamelCase_  				=						encoder_layerdrop
   lowerCamelCase_  				=						decoder_layerdrop
   lowerCamelCase_  				=						classifier_dropout
   lowerCamelCase_  				=						use_cache
   lowerCamelCase_  				=						encoder_layers
   lowerCamelCase_  				=						scale_embedding  # scale factor will be sqrt(d_model) if True

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

   # ensure backward compatibility for BART CNN models
   if self.forced_bos_token_id is None and kwargs.get("force_bos_token_to_be_generated"    ,						UpperCamelCase  ):
    lowerCamelCase_  				=						self.bos_token_id
    warnings.warn(
        f'''Please make sure the config includes `forced_bos_token_id={self.bos_token_id}` in future versions. '''
        "The config can simply be saved and uploaded again to be fixed."  )



class   snake_case					(					lowercase    ):





  """simple docstring"""




  @property
  def 						snake_case	(					self  ):







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

    if self.use_past:
     lowerCamelCase_  				=						{0: "batch"}
     lowerCamelCase_  				=						{0: "batch", 1: "past_decoder_sequence + sequence"}
    else:
     lowerCamelCase_  				=						{0: "batch", 1: "decoder_sequence"}
     lowerCamelCase_  				=						{0: "batch", 1: "decoder_sequence"}

    if self.use_past:
     self.fill_with_past_key_values_(UpperCamelCase    ,						direction="inputs"  )
   elif self.task == "causal-lm":
    # TODO: figure this case out.
    lowerCamelCase_  				=						OrderedDict(
        [
            ("input_ids", {0: "batch", 1: "encoder_sequence"}),
            ("attention_mask", {0: "batch", 1: "encoder_sequence"}),
        ]  )
    if self.use_past:
     lowerCamelCase_				,lowerCamelCase_  				=						self.num_layers
     for i in range(UpperCamelCase  ):
      lowerCamelCase_  				=						{0: "batch", 2: "past_sequence + sequence"}
      lowerCamelCase_  				=						{0: "batch", 2: "past_sequence + sequence"}
   else:
    lowerCamelCase_  				=						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 						snake_case	(					self  ):







   """simple docstring"""
   if self.task in ["default", "seq2seq-lm"]:
    lowerCamelCase_  				=						super().outputs
   else:
    lowerCamelCase_  				=						super(UpperCamelCase    ,						self  ).outputs
    if self.use_past:
     lowerCamelCase_				,lowerCamelCase_  				=						self.num_layers
     for i in range(UpperCamelCase  ):
      lowerCamelCase_  				=						{0: "batch", 2: "past_sequence + sequence"}
      lowerCamelCase_  				=						{0: "batch", 2: "past_sequence + sequence"}
   return common_outputs






  def 						snake_case	(					self    ,						UpperCamelCase    ,						UpperCamelCase = -1    ,						UpperCamelCase = -1    ,						UpperCamelCase = False    ,						UpperCamelCase = None    ,						):







   """simple docstring"""
   lowerCamelCase_  				=						self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
       UpperCamelCase    ,						UpperCamelCase    ,						UpperCamelCase    ,						UpperCamelCase    ,						UpperCamelCase  )

   # Generate decoder inputs
   lowerCamelCase_  				=						seq_length if not self.use_past else 1
   lowerCamelCase_  				=						self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
       UpperCamelCase    ,						UpperCamelCase    ,						UpperCamelCase    ,						UpperCamelCase    ,						UpperCamelCase  )
   lowerCamelCase_  				=						{f'''decoder_{name}''': tensor for name, tensor in decoder_inputs.items()}
   lowerCamelCase_  				=						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
    lowerCamelCase_				,lowerCamelCase_  				=						common_inputs["input_ids"].shape
    lowerCamelCase_  				=						common_inputs["decoder_input_ids"].shape[1]
    lowerCamelCase_				,lowerCamelCase_  				=						self.num_attention_heads
    lowerCamelCase_  				=						(
        batch,
        num_encoder_attention_heads,
        encoder_seq_length,
        self._config.hidden_size // num_encoder_attention_heads,
    )
    lowerCamelCase_  				=						decoder_seq_length + 3
    lowerCamelCase_  				=						(
        batch,
        num_decoder_attention_heads,
        decoder_past_length,
        self._config.hidden_size // num_decoder_attention_heads,
    )

    lowerCamelCase_  				=						torch.cat(
        [common_inputs["decoder_attention_mask"], torch.ones(UpperCamelCase    ,						UpperCamelCase  )]    ,						dim=1  )

    lowerCamelCase_  				=						[]
    # If the number of encoder and decoder layers are present in the model configuration, both are considered
    lowerCamelCase_				,lowerCamelCase_  				=						self.num_layers
    lowerCamelCase_  				=						min(UpperCamelCase    ,						UpperCamelCase  )
    lowerCamelCase_  				=						max(UpperCamelCase    ,						UpperCamelCase  ) - min_num_layers
    lowerCamelCase_  				=						"encoder" if num_encoder_layers > num_decoder_layers else "decoder"

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






  def 						snake_case	(					self    ,						UpperCamelCase    ,						UpperCamelCase = -1    ,						UpperCamelCase = -1    ,						UpperCamelCase = False    ,						UpperCamelCase = None    ,						):







   """simple docstring"""
   lowerCamelCase_  				=						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
    lowerCamelCase_				,lowerCamelCase_  				=						common_inputs["input_ids"].shape
    # Not using the same length for past_key_values
    lowerCamelCase_  				=						seqlen + 2
    lowerCamelCase_				,lowerCamelCase_  				=						self.num_layers
    lowerCamelCase_				,lowerCamelCase_  				=						self.num_attention_heads
    lowerCamelCase_  				=						(
        batch,
        num_encoder_attention_heads,
        past_key_values_length,
        self._config.hidden_size // num_encoder_attention_heads,
    )

    lowerCamelCase_  				=						common_inputs["attention_mask"].dtype
    lowerCamelCase_  				=						torch.cat(
        [common_inputs["attention_mask"], torch.ones(UpperCamelCase    ,						UpperCamelCase    ,						dtype=UpperCamelCase  )]    ,						dim=1  )
    lowerCamelCase_  				=						[
        (torch.zeros(UpperCamelCase  ), torch.zeros(UpperCamelCase  )) for _ in range(UpperCamelCase  )
    ]
   return common_inputs






  def 						snake_case	(					self    ,						UpperCamelCase    ,						UpperCamelCase = -1    ,						UpperCamelCase = -1    ,						UpperCamelCase = False    ,						UpperCamelCase = None    ,						):







   """simple docstring"""
   lowerCamelCase_  				=						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
   lowerCamelCase_  				=						tokenizer.num_special_tokens_to_add(UpperCamelCase  )
   lowerCamelCase_  				=						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
   lowerCamelCase_  				=						[" ".join([tokenizer.unk_token]  ) * seq_length] * batch_size
   lowerCamelCase_  				=						dict(tokenizer(UpperCamelCase    ,						return_tensors=UpperCamelCase  )  )
   return common_inputs






  def 						snake_case	(					self    ,						UpperCamelCase    ,						UpperCamelCase = -1    ,						UpperCamelCase = -1    ,						UpperCamelCase = False    ,						UpperCamelCase = None    ,						):







   """simple docstring"""
   if self.task in ["default", "seq2seq-lm"]:
    lowerCamelCase_  				=						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":
    lowerCamelCase_  				=						self._generate_dummy_inputs_for_causal_lm(
        UpperCamelCase    ,						batch_size=UpperCamelCase    ,						seq_length=UpperCamelCase    ,						is_pair=UpperCamelCase    ,						framework=UpperCamelCase  )
   else:
    lowerCamelCase_  				=						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 						snake_case	(					self    ,						UpperCamelCase    ,						UpperCamelCase    ,						UpperCamelCase    ,						UpperCamelCase  ):







   """simple docstring"""
   if self.task in ["default", "seq2seq-lm"]:
    lowerCamelCase_  				=						super()._flatten_past_key_values_(UpperCamelCase    ,						UpperCamelCase    ,						UpperCamelCase    ,						UpperCamelCase  )
   else:
    lowerCamelCase_  				=						super(UpperCamelCase    ,						self  )._flatten_past_key_values_(
        UpperCamelCase    ,						UpperCamelCase    ,						UpperCamelCase    ,						UpperCamelCase  )







'''simple docstring'''

import json
from typing import TYPE_CHECKING, List, Optional, Tuple

from tokenizers import pre_tokenizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging


if TYPE_CHECKING:
     from transformers.pipelines.conversational import Conversation


a_						:       Dict      			=				logging.get_logger(__name__)

a_						:       List[Any]      			=				{"""vocab_file""": """vocab.json""", """merges_file""": """merges.txt""", """tokenizer_file""": """tokenizer.json"""}

a_						:       Optional[Any]      			=				{
    """tokenizer_file""": {
        """EleutherAI/gpt-neox-20b""": """https://huggingface.co/EleutherAI/gpt-neox-20b/resolve/main/tokenizer.json""",
    },
}

a_						:       str      			=				{
    """gpt-neox-20b""": 2048,
}





class   snake_case					(					lowercase    ):





  """simple docstring"""




  _lowerCamelCase						=						VOCAB_FILES_NAMES
  _lowerCamelCase						=						PRETRAINED_VOCAB_FILES_MAP
  _lowerCamelCase						=						PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
  _lowerCamelCase						=						["input_ids", "attention_mask"]






  def __init__(					self    ,						UpperCamelCase=None    ,						UpperCamelCase=None    ,						UpperCamelCase=None    ,						UpperCamelCase="<|endoftext|>"    ,						UpperCamelCase="<|endoftext|>"    ,						UpperCamelCase="<|endoftext|>"    ,						UpperCamelCase=False    ,						**UpperCamelCase    ,						):







   """simple docstring"""
   super().__init__(
       UpperCamelCase    ,						UpperCamelCase    ,						tokenizer_file=UpperCamelCase    ,						unk_token=UpperCamelCase    ,						bos_token=UpperCamelCase    ,						eos_token=UpperCamelCase    ,						add_prefix_space=UpperCamelCase    ,						**UpperCamelCase    ,						)

   lowerCamelCase_  				=						json.loads(self.backend_tokenizer.pre_tokenizer.__getstate__()  )
   if pre_tok_state.get("add_prefix_space"    ,						UpperCamelCase  ) != add_prefix_space:
    lowerCamelCase_  				=						getattr(UpperCamelCase    ,						pre_tok_state.pop("type"  )  )
    lowerCamelCase_  				=						add_prefix_space
    lowerCamelCase_  				=						pre_tok_class(**UpperCamelCase  )

   lowerCamelCase_  				=						add_prefix_space






  def 						snake_case	(					self    ,						UpperCamelCase    ,						UpperCamelCase = None  ):







   """simple docstring"""
   lowerCamelCase_  				=						self._tokenizer.model.save(UpperCamelCase    ,						name=UpperCamelCase  )
   return tuple(UpperCamelCase  )







  def 						snake_case	(					self    ,						UpperCamelCase  ):







   """simple docstring"""
   lowerCamelCase_  				=						[]
   for is_user, text in conversation.iter_texts():
    input_ids.extend(self.encode(UpperCamelCase    ,						add_special_tokens=UpperCamelCase  ) + [self.eos_token_id]  )

   if len(UpperCamelCase  ) > self.model_max_length:
    lowerCamelCase_  				=						input_ids[-self.model_max_length :]
   return input_ids



