import json
import os
import re
import unicodedata
from typing import Optional, Tuple

from ...tokenization_utils import PreTrainedTokenizer, _is_control, _is_punctuation, _is_whitespace
from ...utils import logging


_SCREAMING_SNAKE_CASE   		=			logging.get_logger(__name__)

_SCREAMING_SNAKE_CASE   		=			{
    """vocab_file""": """vocab.json""",
    """merges_file""": """merges.txt""",
}

_SCREAMING_SNAKE_CASE   		=			{
    """vocab_file""": {"""openai-gpt""": """https://huggingface.co/openai-gpt/resolve/main/vocab.json"""},
    """merges_file""": {"""openai-gpt""": """https://huggingface.co/openai-gpt/resolve/main/merges.txt"""},
}

_SCREAMING_SNAKE_CASE   		=			{
    """openai-gpt""": 5_1_2,
}





def  lowercase(  UpperCamelCase_					)		->  Optional[Any]:







 '''simple docstring'''
 UpperCamelCase      =			text.strip()
 if not text:
  return []
 UpperCamelCase      =			text.split()
 return tokens
class SCREAMING_SNAKE_CASE_		(			__lowerCAmelCase		):







   def __init__(    self	:	int      ,      lowerCamelCase_	:	str=True      ,      lowerCamelCase_	:	str=None      ,      lowerCamelCase_	:	Union[str, Any]=True      ,      lowerCamelCase_	:	int=None      ,      lowerCamelCase_	:	int=True      ,      ):





    """simple docstring"""


    if never_split is None:
     UpperCamelCase      =			[]
    UpperCamelCase      =			do_lower_case
    UpperCamelCase      =			set(lowerCamelCase_							)
    UpperCamelCase      =			tokenize_chinese_chars
    UpperCamelCase      =			strip_accents
    UpperCamelCase      =			do_split_on_punc







   def 	lowerCamelCase_  (    self	:	str      ,      lowerCamelCase_	:	Optional[int]      ,      lowerCamelCase_	:	Dict=None							):





    """simple docstring"""


    UpperCamelCase      =			self.never_split.union(set(lowerCamelCase_							)							) if never_split else self.never_split
    UpperCamelCase      =			self._clean_text(lowerCamelCase_							)

    # This was added on November 1st, 2018 for the multilingual and Chinese
    # models. This is also applied to the English models now, but it doesn't
    # matter since the English models were not trained on any Chinese data
    # and generally don't have any Chinese data in them (there are Chinese
    # characters in the vocabulary because Wikipedia does have some Chinese
    # words in the English Wikipedia.).
    if self.tokenize_chinese_chars:
     UpperCamelCase      =			self._tokenize_chinese_chars(lowerCamelCase_							)
    # prevents treating the same character with different unicode codepoints as different characters
    UpperCamelCase      =			unicodedata.normalize("""NFC"""      ,      lowerCamelCase_							)
    UpperCamelCase      =			whitespace_tokenize(lowerCamelCase_							)
    UpperCamelCase      =			[]
    for token in orig_tokens:
     if token not in never_split:
      if self.do_lower_case:
       UpperCamelCase      =			token.lower()
       if self.strip_accents is not False:
        UpperCamelCase      =			self._run_strip_accents(lowerCamelCase_							)
      elif self.strip_accents:
       UpperCamelCase      =			self._run_strip_accents(lowerCamelCase_							)
     split_tokens.extend(self._run_split_on_punc(lowerCamelCase_      ,      lowerCamelCase_							)							)

    UpperCamelCase      =			whitespace_tokenize(""" """.join(lowerCamelCase_							)							)
    return output_tokens







   def 	lowerCamelCase_  (    self	:	Optional[int]      ,      lowerCamelCase_	:	Optional[int]							):





    """simple docstring"""


    UpperCamelCase      =			unicodedata.normalize("""NFD"""      ,      lowerCamelCase_							)
    UpperCamelCase      =			[]
    for char in text:
     UpperCamelCase      =			unicodedata.category(lowerCamelCase_							)
     if cat == "Mn":
      continue
     output.append(lowerCamelCase_							)
    return "".join(lowerCamelCase_							)







   def 	lowerCamelCase_  (    self	:	Optional[Any]      ,      lowerCamelCase_	:	Union[str, Any]      ,      lowerCamelCase_	:	Optional[int]=None							):





    """simple docstring"""


    if not self.do_split_on_punc or (never_split is not None and text in never_split):
     return [text]
    UpperCamelCase      =			list(lowerCamelCase_							)
    UpperCamelCase      =			0
    UpperCamelCase      =			True
    UpperCamelCase      =			[]
    while i < len(lowerCamelCase_							):
     UpperCamelCase      =			chars[i]
     if _is_punctuation(lowerCamelCase_							):
      output.append([char]							)
      UpperCamelCase      =			True
     else:
      if start_new_word:
       output.append([]							)
      UpperCamelCase      =			False
      output[-1].append(lowerCamelCase_							)
     i += 1

    return ["".join(lowerCamelCase_							) for x in output]







   def 	lowerCamelCase_  (    self	:	str      ,      lowerCamelCase_	:	str							):





    """simple docstring"""


    UpperCamelCase      =			[]
    for char in text:
     UpperCamelCase      =			ord(lowerCamelCase_							)
     if self._is_chinese_char(lowerCamelCase_							):
      output.append(""" """							)
      output.append(lowerCamelCase_							)
      output.append(""" """							)
     else:
      output.append(lowerCamelCase_							)
    return "".join(lowerCamelCase_							)







   def 	lowerCamelCase_  (    self	:	Union[str, Any]      ,      lowerCamelCase_	:	Any							):





    """simple docstring"""


    if (
        (cp >= 0x4e00 and cp <= 0x9fff)
        or (cp >= 0x3400 and cp <= 0x4dbf)  #
        or (cp >= 0x20000 and cp <= 0x2a6df)  #
        or (cp >= 0x2a700 and cp <= 0x2b73f)  #
        or (cp >= 0x2b740 and cp <= 0x2b81f)  #
        or (cp >= 0x2b820 and cp <= 0x2ceaf)  #
        or (cp >= 0xf900 and cp <= 0xfaff)
        or (cp >= 0x2f800 and cp <= 0x2fa1f)  #
    ):  #
     return True

    return False







   def 	lowerCamelCase_  (    self	:	Union[str, Any]      ,      lowerCamelCase_	:	int							):





    """simple docstring"""


    UpperCamelCase      =			[]
    for char in text:
     UpperCamelCase      =			ord(lowerCamelCase_							)
     if cp == 0 or cp == 0xfffd or _is_control(lowerCamelCase_							):
      continue
     if _is_whitespace(lowerCamelCase_							):
      output.append(""" """							)
     else:
      output.append(lowerCamelCase_							)
    return "".join(lowerCamelCase_							)





def  lowercase(  UpperCamelCase_					)		->  List[Any]:







 '''simple docstring'''
 UpperCamelCase      =			set()
 UpperCamelCase      =			word[0]
 for char in word[1:]:
  pairs.add((prev_char, char)					)
  UpperCamelCase      =			char
 return pairs





def  lowercase(  UpperCamelCase_					)		->  Any:







 '''simple docstring'''
 UpperCamelCase      =			text.replace("""—"""       ,				"""-"""					)
 UpperCamelCase      =			text.replace("""–"""       ,				"""-"""					)
 UpperCamelCase      =			text.replace("""―"""       ,				"""-"""					)
 UpperCamelCase      =			text.replace("""…"""       ,				"""..."""					)
 UpperCamelCase      =			text.replace("""´"""       ,				"""'"""					)
 UpperCamelCase      =			re.sub(R"""(-+|~+|!+|\"+|;+|\?+|\++|,+|\)+|\(+|\\+|\/+|\*+|\[+|\]+|}+|{+|\|+|_+)"""       ,				R""" \1 """       ,				UpperCamelCase_					)
 UpperCamelCase      =			re.sub(R"""\s*\n\s*"""       ,				""" \n """       ,				UpperCamelCase_					)
 UpperCamelCase      =			re.sub(R"""[^\S\n]+"""       ,				""" """       ,				UpperCamelCase_					)
 return text.strip()


class SCREAMING_SNAKE_CASE_		(			__lowerCAmelCase		):
   __lowerCAmelCase											=							VOCAB_FILES_NAMES
   __lowerCAmelCase											=							PRETRAINED_VOCAB_FILES_MAP
   __lowerCAmelCase											=							PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
   __lowerCAmelCase											=							["""input_ids""", """attention_mask"""]







   def __init__(    self	:	Any      ,      lowerCamelCase_	:	Any      ,      lowerCamelCase_	:	List[str]      ,      lowerCamelCase_	:	Optional[int]="<unk>"      ,      **lowerCamelCase_	:	int							):





    """simple docstring"""


    super().__init__(unk_token=lowerCamelCase_      ,      **lowerCamelCase_							)

    try:
     import ftfy
     from spacy.lang.en import English

     UpperCamelCase      =			English()
     UpperCamelCase      =			_nlp.tokenizer
     UpperCamelCase      =			ftfy.fix_text
    except ImportError:
     logger.warning("""ftfy or spacy is not installed using BERT BasicTokenizer instead of SpaCy & ftfy."""							)
     UpperCamelCase      =			BasicTokenizer(do_lower_case=lowerCamelCase_							)
     UpperCamelCase      =			None

    with open(lowerCamelCase_      ,      encoding="""utf-8"""							) as vocab_handle:
     UpperCamelCase      =			json.load(lowerCamelCase_							)
    UpperCamelCase      =			{v: k for k, v in self.encoder.items()}
    with open(lowerCamelCase_      ,      encoding="""utf-8"""							) as merges_handle:
     UpperCamelCase      =			merges_handle.read().split("""\n"""							)[1:-1]
    UpperCamelCase      =			[tuple(merge.split()							) for merge in merges]
    UpperCamelCase      =			dict(zip(lowerCamelCase_      ,      range(len(lowerCamelCase_							)							)							)							)
    UpperCamelCase      =			{}







   @property
   def 	lowerCamelCase_  (    self	:	Optional[int]							):





    """simple docstring"""


    return True







   @property
   def 	lowerCamelCase_  (    self	:	str							):





    """simple docstring"""


    return len(self.encoder							)







   def 	lowerCamelCase_  (    self	:	Optional[Any]							):





    """simple docstring"""


    return dict(self.encoder      ,      **self.added_tokens_encoder							)







   def 	lowerCamelCase_  (    self	:	int      ,      lowerCamelCase_	:	int							):





    """simple docstring"""


    UpperCamelCase      =			tuple(token[:-1]							) + (token[-1] + """</w>""",)
    if token in self.cache:
     return self.cache[token]
    UpperCamelCase      =			get_pairs(lowerCamelCase_							)

    if not pairs:
     return token + "</w>"

    while True:
     UpperCamelCase      =			min(lowerCamelCase_      ,      key=lambda lowerCamelCase_							: self.bpe_ranks.get(lowerCamelCase_      ,      float("""inf"""							)							)							)
     if bigram not in self.bpe_ranks:
      break
     UpperCamelCase     ,    UpperCamelCase      =			bigram
     UpperCamelCase      =			[]
     UpperCamelCase      =			0
     while i < len(lowerCamelCase_							):
      try:
       UpperCamelCase      =			word.index(lowerCamelCase_      ,      lowerCamelCase_							)
      except ValueError:
       new_word.extend(word[i:]							)
       break
      else:
       new_word.extend(word[i:j]							)
       UpperCamelCase      =			j

      if word[i] == first and i < len(lowerCamelCase_							) - 1 and word[i + 1] == second:
       new_word.append(first + second							)
       i += 2
      else:
       new_word.append(word[i]							)
       i += 1
     UpperCamelCase      =			tuple(lowerCamelCase_							)
     UpperCamelCase      =			new_word
     if len(lowerCamelCase_							) == 1:
      break
     else:
      UpperCamelCase      =			get_pairs(lowerCamelCase_							)
    UpperCamelCase      =			""" """.join(lowerCamelCase_							)
    if word == "\n  </w>":
     UpperCamelCase      =			"""\n</w>"""
    UpperCamelCase      =			word
    return word







   def 	lowerCamelCase_  (    self	:	Any      ,      lowerCamelCase_	:	str							):





    """simple docstring"""


    UpperCamelCase      =			[]
    if self.fix_text is None:
     # Using BERT's BasicTokenizer
     UpperCamelCase      =			self.nlp.tokenize(lowerCamelCase_							)
     for token in text:
      split_tokens.extend(list(self.bpe(lowerCamelCase_							).split(""" """							)							)							)
    else:
     # Using SpaCy & ftfy (original tokenization process of OpenAI GPT)
     UpperCamelCase      =			self.nlp(text_standardize(self.fix_text(lowerCamelCase_							)							)							)
     for token in text:
      split_tokens.extend(list(self.bpe(token.text.lower()							).split(""" """							)							)							)
    return split_tokens







   def 	lowerCamelCase_  (    self	:	List[Any]      ,      lowerCamelCase_	:	Any							):





    """simple docstring"""


    return self.encoder.get(lowerCamelCase_      ,      self.encoder.get(self.unk_token							)							)







   def 	lowerCamelCase_  (    self	:	Dict      ,      lowerCamelCase_	:	Tuple							):





    """simple docstring"""


    return self.decoder.get(lowerCamelCase_      ,      self.unk_token							)







   def 	lowerCamelCase_  (    self	:	Union[str, Any]      ,      lowerCamelCase_	:	int							):





    """simple docstring"""


    UpperCamelCase      =			"""""".join(lowerCamelCase_							).replace("""</w>"""      ,      """ """							).strip()
    return out_string







   def 	lowerCamelCase_  (    self	:	Union[str, Any]      ,      lowerCamelCase_	:	str      ,      lowerCamelCase_	:	Optional[str] = None							):





    """simple docstring"""


    if not os.path.isdir(lowerCamelCase_							):
     logger.error(f"""Vocabulary path ({save_directory}) should be a directory"""							)
     return
    UpperCamelCase      =			os.path.join(
        lowerCamelCase_      ,      (filename_prefix + """-""" if filename_prefix else """""") + VOCAB_FILES_NAMES["""vocab_file"""]							)
    UpperCamelCase      =			os.path.join(
        lowerCamelCase_      ,      (filename_prefix + """-""" if filename_prefix else """""") + VOCAB_FILES_NAMES["""merges_file"""]							)

    with open(lowerCamelCase_      ,      """w"""      ,      encoding="""utf-8"""							) as f:
     f.write(json.dumps(self.encoder      ,      indent=2      ,      sort_keys=lowerCamelCase_      ,      ensure_ascii=lowerCamelCase_							) + """\n"""							)

    UpperCamelCase      =			0
    with open(lowerCamelCase_      ,      """w"""      ,      encoding="""utf-8"""							) as writer:
     writer.write("""#version: 0.2\n"""							)
     for bpe_tokens, token_index in sorted(self.bpe_ranks.items()      ,      key=lambda lowerCamelCase_							: kv[1]							):
      if index != token_index:
       logger.warning(
           f"""Saving vocabulary to {merge_file}: BPE merge indices are not consecutive."""
           """ Please check that the tokenizer is not corrupted!"""							)
       UpperCamelCase      =			token_index
      writer.write(""" """.join(lowerCamelCase_							) + """\n"""							)
      index += 1

    return vocab_file, merge_file

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


_SCREAMING_SNAKE_CASE   		=			logging.get_logger(__name__)

_SCREAMING_SNAKE_CASE   		=			{
    """facebook/mbart-large-cc25""": """https://huggingface.co/facebook/mbart-large-cc25/resolve/main/config.json""",
    # See all MBART models at https://huggingface.co/models?filter=mbart
}
class SCREAMING_SNAKE_CASE_		(			__lowerCAmelCase		):
   __lowerCAmelCase											=							"""mbart"""
   __lowerCAmelCase											=							["""past_key_values"""]
   __lowerCAmelCase											=							{"""num_attention_heads""": """encoder_attention_heads""", """hidden_size""": """d_model"""}







   def __init__(    self	:	Optional[int]      ,      lowerCamelCase_	:	Dict=5_0265      ,      lowerCamelCase_	:	Tuple=1024      ,      lowerCamelCase_	:	int=12      ,      lowerCamelCase_	:	Tuple=4096      ,      lowerCamelCase_	:	int=16      ,      lowerCamelCase_	:	Dict=12      ,      lowerCamelCase_	:	Dict=4096      ,      lowerCamelCase_	:	Optional[int]=16      ,      lowerCamelCase_	:	int=0.0      ,      lowerCamelCase_	:	Tuple=0.0      ,      lowerCamelCase_	:	int=True      ,      lowerCamelCase_	:	List[str]=True      ,      lowerCamelCase_	:	List[str]="gelu"      ,      lowerCamelCase_	:	str=1024      ,      lowerCamelCase_	:	int=0.1      ,      lowerCamelCase_	:	List[Any]=0.0      ,      lowerCamelCase_	:	Dict=0.0      ,      lowerCamelCase_	:	Union[str, Any]=0.0_2      ,      lowerCamelCase_	:	Tuple=0.0      ,      lowerCamelCase_	:	int=False      ,      lowerCamelCase_	:	List[Any]=1      ,      lowerCamelCase_	:	Union[str, Any]=0      ,      lowerCamelCase_	:	Optional[Any]=2      ,      lowerCamelCase_	:	Any=2      ,      **lowerCamelCase_	:	int      ,      ):





    """simple docstring"""


    UpperCamelCase      =			vocab_size
    UpperCamelCase      =			max_position_embeddings
    UpperCamelCase      =			d_model
    UpperCamelCase      =			encoder_ffn_dim
    UpperCamelCase      =			encoder_layers
    UpperCamelCase      =			encoder_attention_heads
    UpperCamelCase      =			decoder_ffn_dim
    UpperCamelCase      =			decoder_layers
    UpperCamelCase      =			decoder_attention_heads
    UpperCamelCase      =			dropout
    UpperCamelCase      =			attention_dropout
    UpperCamelCase      =			activation_dropout
    UpperCamelCase      =			activation_function
    UpperCamelCase      =			init_std
    UpperCamelCase      =			encoder_layerdrop
    UpperCamelCase      =			decoder_layerdrop
    UpperCamelCase      =			classifier_dropout
    UpperCamelCase      =			use_cache
    UpperCamelCase      =			encoder_layers
    UpperCamelCase      =			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_      ,      forced_eos_token_id=lowerCamelCase_      ,      **lowerCamelCase_      ,      )





class SCREAMING_SNAKE_CASE_		(			__lowerCAmelCase		):







   @property
   def 	lowerCamelCase_  (    self	:	List[str]							):





    """simple docstring"""


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

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

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





    """simple docstring"""


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







   def 	lowerCamelCase_  (    self	:	List[Any]      ,      lowerCamelCase_	:	PreTrainedTokenizer      ,      lowerCamelCase_	:	int = -1      ,      lowerCamelCase_	:	int = -1      ,      lowerCamelCase_	:	bool = False      ,      lowerCamelCase_	:	Optional[TensorType] = None      ,      ):





    """simple docstring"""


    UpperCamelCase      =			self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
        lowerCamelCase_      ,      lowerCamelCase_      ,      lowerCamelCase_      ,      lowerCamelCase_      ,      lowerCamelCase_							)

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

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

     UpperCamelCase      =			[]
     # If the number of encoder and decoder layers are present in the model configuration, both are considered
     UpperCamelCase     ,    UpperCamelCase      =			self.num_layers
     UpperCamelCase      =			min(lowerCamelCase_      ,      lowerCamelCase_							)
     UpperCamelCase      =			max(lowerCamelCase_      ,      lowerCamelCase_							) - min_num_layers
     UpperCamelCase      =			"""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.
     UpperCamelCase      =			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







   def 	lowerCamelCase_  (    self	:	Dict      ,      lowerCamelCase_	:	PreTrainedTokenizer      ,      lowerCamelCase_	:	int = -1      ,      lowerCamelCase_	:	int = -1      ,      lowerCamelCase_	:	bool = False      ,      lowerCamelCase_	:	Optional[TensorType] = None      ,      ):





    """simple docstring"""


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

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







   def 	lowerCamelCase_  (    self	:	Optional[Any]      ,      lowerCamelCase_	:	PreTrainedTokenizer      ,      lowerCamelCase_	:	int = -1      ,      lowerCamelCase_	:	int = -1      ,      lowerCamelCase_	:	bool = False      ,      lowerCamelCase_	:	Optional[TensorType] = None      ,      ):





    """simple docstring"""


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







   def 	lowerCamelCase_  (    self	:	List[Any]      ,      lowerCamelCase_	:	PreTrainedTokenizer      ,      lowerCamelCase_	:	int = -1      ,      lowerCamelCase_	:	int = -1      ,      lowerCamelCase_	:	bool = False      ,      lowerCamelCase_	:	Optional[TensorType] = None      ,      ):





    """simple docstring"""


    if self.task in ["default", "seq2seq-lm"]:
     UpperCamelCase      =			self._generate_dummy_inputs_for_default_and_seqaseq_lm(
         lowerCamelCase_      ,      batch_size=lowerCamelCase_      ,      seq_length=lowerCamelCase_      ,      is_pair=lowerCamelCase_      ,      framework=lowerCamelCase_							)

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

    return common_inputs







   def 	lowerCamelCase_  (    self	:	Optional[Any]      ,      lowerCamelCase_	:	int      ,      lowerCamelCase_	:	Union[str, Any]      ,      lowerCamelCase_	:	Optional[Any]      ,      lowerCamelCase_	:	List[str]							):





    """simple docstring"""


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