

'''simple docstring'''


import json
import os
from functools import lru_cache
from typing import TYPE_CHECKING, List, Optional, Tuple

import regex as re

from ...tokenization_utils import AddedToken, PreTrainedTokenizer
from ...utils import logging


if TYPE_CHECKING:
			from transformers.pipelines.conversational import Conversation

lowerCAmelCase__						:       Union[str, Any]										=						logging.get_logger(__name__)


lowerCAmelCase__						:       Dict										=						{
    """vocab_file""": """vocab.json""",
    """merges_file""": """merges.txt""",
    """tokenizer_config_file""": """tokenizer_config.json""",
}

lowerCAmelCase__						:       Union[str, Any]										=						{
    """vocab_file""": {"""facebook/blenderbot-3B""": """https://huggingface.co/facebook/blenderbot-3B/resolve/main/vocab.json"""},
    """merges_file""": {"""facebook/blenderbot-3B""": """https://huggingface.co/facebook/blenderbot-3B/resolve/main/merges.txt"""},
    """tokenizer_config_file""": {
        """facebook/blenderbot-3B""": """https://huggingface.co/facebook/blenderbot-3B/resolve/main/tokenizer_config.json"""
    },
}

lowerCAmelCase__						:       Optional[int]										=						{"""facebook/blenderbot-3B""": 128}




@lru_cache()
# Copied from transformers.models.roberta.tokenization_roberta.bytes_to_unicode
def 	_a       (				):

		"""simple docstring"""

		snake_case__						:       List[str]       						=  (
		    list(range(ord('''!'''     )   ,							ord('''~'''     ) + 1     )     ) + list(range(ord('''¡'''     )   ,							ord('''¬'''     ) + 1     )     ) + list(range(ord('''®'''     )   ,							ord('''ÿ'''     ) + 1     )     )
		)
		snake_case__						:       List[Any]       						=  bs[:]
		snake_case__						:       List[Any]       						=  0
		for b in range(2**8     ):
				if b not in bs:
						bs.append(lowerCamelCase__     )
						cs.append(2**8 + n     )
						n += 1
		snake_case__						:       List[str]       						=  [chr(lowerCamelCase__     ) for n in cs]
		return dict(zip(lowerCamelCase__   ,							lowerCamelCase__     )     )




def 	_a       (				__lowerCAmelCase		:      str     ):

		"""simple docstring"""

		snake_case__						:       Any       						=  set()
		snake_case__						:       Tuple       						=  word[0]
		for char in word[1:]:
				pairs.add((prev_char, char)     )
				snake_case__						:       Optional[Any]       						=  char
		return pairs





class     a			(				SCREAMING_SNAKE_CASE       ):






						"""simple docstring"""




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







						def __init__(							self					:      Tuple			,			snake_case_					:      Optional[Any]			,			snake_case_					:      Union[str, Any]			,			snake_case_					:      List[Any]="replace"			,			snake_case_					:      List[str]="<s>"			,			snake_case_					:      str="</s>"			,			snake_case_					:      str="</s>"			,			snake_case_					:      str="<s>"			,			snake_case_					:      List[str]="<unk>"			,			snake_case_					:      List[str]="<pad>"			,			snake_case_					:      Optional[Any]="<mask>"			,			snake_case_					:      str=False			,			**snake_case_					:      Any			,			):



								'''simple docstring'''



								snake_case__						:       Tuple       						=  AddedToken(snake_case_			,			lstrip=snake_case_			,			rstrip=snake_case_  ) if isinstance(snake_case_			,			snake_case_  ) else bos_token
								snake_case__						:       Any       						=  AddedToken(snake_case_			,			lstrip=snake_case_			,			rstrip=snake_case_  ) if isinstance(snake_case_			,			snake_case_  ) else eos_token
								snake_case__						:       List[str]       						=  AddedToken(snake_case_			,			lstrip=snake_case_			,			rstrip=snake_case_  ) if isinstance(snake_case_			,			snake_case_  ) else sep_token
								snake_case__						:       Union[str, Any]       						=  AddedToken(snake_case_			,			lstrip=snake_case_			,			rstrip=snake_case_  ) if isinstance(snake_case_			,			snake_case_  ) else cls_token
								snake_case__						:       Dict       						=  AddedToken(snake_case_			,			lstrip=snake_case_			,			rstrip=snake_case_  ) if isinstance(snake_case_			,			snake_case_  ) else unk_token
								snake_case__						:       Union[str, Any]       						=  AddedToken(snake_case_			,			lstrip=snake_case_			,			rstrip=snake_case_  ) if isinstance(snake_case_			,			snake_case_  ) else pad_token

								# Mask token behave like a normal word, i.e. include the space before it
								snake_case__						:       Optional[int]       						=  AddedToken(snake_case_			,			lstrip=snake_case_			,			rstrip=snake_case_  ) if isinstance(snake_case_			,			snake_case_  ) else mask_token

								super().__init__(
								    errors=snake_case_			,			bos_token=snake_case_			,			eos_token=snake_case_			,			unk_token=snake_case_			,			sep_token=snake_case_			,			cls_token=snake_case_			,			pad_token=snake_case_			,			mask_token=snake_case_			,			add_prefix_space=snake_case_			,			**snake_case_			,			)

								with open(snake_case_			,			encoding='''utf-8'''  ) as vocab_handle:
										snake_case__						:       Dict       						=  json.load(snake_case_  )
								snake_case__						:       List[Any]       						=  {v: k for k, v in self.encoder.items()}
								snake_case__						:       List[Any]       						=  errors  # how to handle errors in decoding
								snake_case__						:       int       						=  bytes_to_unicode()
								snake_case__						:       Dict       						=  {v: k for k, v in self.byte_encoder.items()}
								with open(snake_case_			,			encoding='''utf-8'''  ) as merges_handle:
										snake_case__						:       Optional[int]       						=  merges_handle.read().split('''\n'''  )[1:-1]
								snake_case__						:       Any       						=  [tuple(merge.split()  ) for merge in bpe_merges]
								snake_case__						:       int       						=  dict(zip(snake_case_			,			range(len(snake_case_  )  )  )  )
								snake_case__						:       Any       						=  {}
								snake_case__						:       List[str]       						=  add_prefix_space

								# Should have added re.IGNORECASE so BPE merges can happen for capitalized versions of contractions
								snake_case__						:       List[str]       						=  re.compile(R'''\'s|\'t|\'re|\'ve|\'m|\'ll|\'d| ?\p{L}+| ?\p{N}+| ?[^\s\p{L}\p{N}]+|\s+(?!\S)|\s+'''  )







						@property
						# Copied from transformers.models.roberta.tokenization_roberta.RobertaTokenizer.vocab_size with Roberta->Blenderbot, RoBERTa->Blenderbot
						def       __magic_name__							(							self					:      Optional[Any]  ):



								'''simple docstring'''



								return len(self.encoder  )







						def       __magic_name__							(							self					:      str  ):



								'''simple docstring'''



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







						def       __magic_name__							(							self					:      Any			,			snake_case_					:      List[str]  ):



								'''simple docstring'''



								if token in self.cache:
										return self.cache[token]
								snake_case__						:       List[Any]       						=  tuple(snake_case_  )
								snake_case__						:       Dict       						=  get_pairs(snake_case_  )

								if not pairs:
										return token

								while True:
										snake_case__						:       Union[str, Any]       						=  min(snake_case_			,			key=lambda snake_case_  : self.bpe_ranks.get(snake_case_			,			float('''inf'''  )  )  )
										if bigram not in self.bpe_ranks:
												break
										snake_case__						,       snake_case__						:       Union[str, Any]       						=  bigram
										snake_case__						:       Union[str, Any]       						=  []
										snake_case__						:       Union[str, Any]       						=  0
										while i < len(snake_case_  ):
												try:
														snake_case__						:       Union[str, Any]       						=  word.index(snake_case_			,			snake_case_  )
												except ValueError:
														new_word.extend(word[i:]  )
														break
												else:
														new_word.extend(word[i:j]  )
														snake_case__						:       int       						=  j

												if word[i] == first and i < len(snake_case_  ) - 1 and word[i + 1] == second:
														new_word.append(first + second  )
														i += 2
												else:
														new_word.append(word[i]  )
														i += 1
										snake_case__						:       List[Any]       						=  tuple(snake_case_  )
										snake_case__						:       Union[str, Any]       						=  new_word
										if len(snake_case_  ) == 1:
												break
										else:
												snake_case__						:       Any       						=  get_pairs(snake_case_  )
								snake_case__						:       Optional[Any]       						=  ''' '''.join(snake_case_  )
								snake_case__						:       List[Any]       						=  word
								return word







						def       __magic_name__							(							self					:      List[str]			,			snake_case_					:      Dict  ):



								'''simple docstring'''



								snake_case__						:       List[str]       						=  []
								for token in re.findall(self.pat			,			snake_case_  ):
										snake_case__						:       Any       						=  ''''''.join(
										    self.byte_encoder[b] for b in token.encode('''utf-8'''  )  )  # Maps all our bytes to unicode strings, avoiding control tokens of the BPE (spaces in our case)
										bpe_tokens.extend(bpe_token for bpe_token in self.bpe(snake_case_  ).split(''' '''  )  )
								return bpe_tokens







						def       __magic_name__							(							self					:      int			,			snake_case_					:      Any  ):



								'''simple docstring'''



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







						def       __magic_name__							(							self					:      Union[str, Any]			,			snake_case_					:      Optional[int]  ):



								'''simple docstring'''



								return self.decoder.get(snake_case_  )







						def       __magic_name__							(							self					:      Optional[Any]			,			snake_case_					:      Any  ):



								'''simple docstring'''



								snake_case__						:       Dict       						=  ''''''.join(snake_case_  )
								snake_case__						:       Dict       						=  bytearray([self.byte_decoder[c] for c in text]  ).decode('''utf-8'''			,			errors=self.errors  )
								return text







						def       __magic_name__							(							self					:      List[str]			,			snake_case_					:      str			,			snake_case_					:      Optional[str] = None  ):



								'''simple docstring'''



								if not os.path.isdir(snake_case_  ):
										logger.error(F"""Vocabulary path ({save_directory}) should be a directory"""  )
										return
								snake_case__						:       Any       						=  os.path.join(
								    snake_case_			,			(filename_prefix + '''-''' if filename_prefix else '''''') + VOCAB_FILES_NAMES['''vocab_file''']  )
								snake_case__						:       int       						=  os.path.join(
								    snake_case_			,			(filename_prefix + '''-''' if filename_prefix else '''''') + VOCAB_FILES_NAMES['''merges_file''']  )

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

								snake_case__						:       Union[str, Any]       						=  0
								with open(snake_case_			,			'''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 snake_case_  : 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!'''  )
														snake_case__						:       Optional[Any]       						=  token_index
												writer.write(''' '''.join(snake_case_  ) + '''\n'''  )
												index += 1

								return vocab_file, merge_file







						def       __magic_name__							(							self					:      Optional[int]			,			snake_case_					:      List[int]			,			snake_case_					:      Optional[List[int]] = None			,			snake_case_					:      bool = False  ):



								'''simple docstring'''



								if already_has_special_tokens:
										return super().get_special_tokens_mask(
										    token_ids_a=snake_case_			,			token_ids_a=snake_case_			,			already_has_special_tokens=snake_case_  )

								if token_ids_a is None:
										return [1] + ([0] * len(snake_case_  )) + [1]
								return [1] + ([0] * len(snake_case_  )) + [1, 1] + ([0] * len(snake_case_  )) + [1]







						def       __magic_name__							(							self					:      Any			,			snake_case_					:      List[int]			,			snake_case_					:      Optional[List[int]] = None  ):



								'''simple docstring'''



								snake_case__						:       Optional[int]       						=  [self.sep_token_id]
								snake_case__						:       int       						=  [self.cls_token_id]

								if token_ids_a is None:
										return len(cls + token_ids_a + sep  ) * [0]
								return len(cls + token_ids_a + sep + sep + token_ids_a + sep  ) * [0]







						def       __magic_name__							(							self					:      Union[str, Any]			,			snake_case_					:      Optional[int]			,			snake_case_					:      List[str]=False			,			**snake_case_					:      Union[str, Any]  ):



								'''simple docstring'''



								snake_case__						:       str       						=  kwargs.pop('''add_prefix_space'''			,			self.add_prefix_space  )
								if (is_split_into_words or add_prefix_space) and (len(snake_case_  ) > 0 and not text[0].isspace()):
										snake_case__						:       str       						=  ''' ''' + text
								return (text, kwargs)







						def       __magic_name__							(							self					:      Any			,			snake_case_					:      List[int]			,			snake_case_					:      Optional[List[int]] = None  ):



								'''simple docstring'''



								return token_ids_a + [self.eos_token_id]







						def       __magic_name__							(							self					:      Optional[Any]			,			snake_case_					:      "Conversation"  ):



								'''simple docstring'''



								snake_case__						:       Optional[int]       						=  []
								for is_user, text in conversation.iter_texts():
										if is_user:
												# We need to space prefix as it's being done within blenderbot
												inputs.append(''' ''' + text  )
										else:
												# Generated responses should contain them already.
												inputs.append(snake_case_  )

								snake_case__						:       List[Any]       						=  '''  '''.join(snake_case_  )
								snake_case__						:       Tuple       						=  self.encode(snake_case_  )
								if len(snake_case_  ) > self.model_max_length:
										snake_case__						:       List[str]       						=  input_ids[-self.model_max_length :]
										logger.warning(F"""Trimmed input from conversation as it was longer than {self.model_max_length} tokens."""  )
								return input_ids






'''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


lowerCAmelCase__						:       Optional[Any]										=						logging.get_logger(__name__)

lowerCAmelCase__						:       Optional[int]										=						{
    """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     a			(				SCREAMING_SNAKE_CASE       ):






						"""simple docstring"""




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







						def __init__(							self					:      Optional[Any]			,			snake_case_					:      Tuple=5_0_2_6_5			,			snake_case_					:      Dict=1_0_2_4			,			snake_case_					:      int=1_2			,			snake_case_					:      int=4_0_9_6			,			snake_case_					:      str=1_6			,			snake_case_					:      List[Any]=1_2			,			snake_case_					:      List[Any]=4_0_9_6			,			snake_case_					:      Any=1_6			,			snake_case_					:      str=0.0			,			snake_case_					:      Optional[int]=0.0			,			snake_case_					:      List[Any]="gelu"			,			snake_case_					:      List[Any]=1_0_2_4			,			snake_case_					:      Union[str, Any]=0.1			,			snake_case_					:      int=0.0			,			snake_case_					:      Tuple=0.0			,			snake_case_					:      Optional[Any]=0.0_2			,			snake_case_					:      Dict=0.0			,			snake_case_					:      str=False			,			snake_case_					:      Optional[int]=True			,			snake_case_					:      Any=3			,			snake_case_					:      int=1			,			snake_case_					:      int=0			,			snake_case_					:      Optional[Any]=2			,			snake_case_					:      str=True			,			snake_case_					:      int=2			,			snake_case_					:      Union[str, Any]=2			,			**snake_case_					:      int			,			):



								'''simple docstring'''



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

								super().__init__(
								    num_labels=snake_case_			,			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_			,			)

								# ensure backward compatibility for BART CNN models
								if self.forced_bos_token_id is None and kwargs.get('''force_bos_token_to_be_generated'''			,			snake_case_  ):
										snake_case__						:       Union[str, Any]       						=  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     a			(				SCREAMING_SNAKE_CASE       ):






						"""simple docstring"""




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



								'''simple docstring'''



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

										if self.use_past:
												snake_case__						:       List[str]       						=  {0: '''batch'''}
												snake_case__						:       int       						=  {0: '''batch''', 1: '''past_decoder_sequence + sequence'''}
										else:
												snake_case__						:       List[Any]       						=  {0: '''batch''', 1: '''decoder_sequence'''}
												snake_case__						:       Optional[int]       						=  {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.
										snake_case__						:       int       						=  OrderedDict(
										    [
										        ('''input_ids''', {0: '''batch''', 1: '''encoder_sequence'''}),
										        ('''attention_mask''', {0: '''batch''', 1: '''encoder_sequence'''}),
										    ]  )
										if self.use_past:
												snake_case__						,       snake_case__						:       Tuple       						=  self.num_layers
												for i in range(snake_case_  ):
														snake_case__						:       List[str]       						=  {0: '''batch''', 2: '''past_sequence + sequence'''}
														snake_case__						:       Tuple       						=  {0: '''batch''', 2: '''past_sequence + sequence'''}
								else:
										snake_case__						:       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       __magic_name__							(							self					:      Optional[int]  ):



								'''simple docstring'''



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







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



								'''simple docstring'''



								snake_case__						:       Union[str, Any]       						=  self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
								    snake_case_			,			snake_case_			,			snake_case_			,			snake_case_			,			snake_case_  )

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

										snake_case__						:       Optional[Any]       						=  torch.cat(
										    [common_inputs['''decoder_attention_mask'''], torch.ones(snake_case_			,			snake_case_  )]			,			dim=1  )

										snake_case__						:       Any       						=  []
										# If the number of encoder and decoder layers are present in the model configuration, both are considered
										snake_case__						,       snake_case__						:       str       						=  self.num_layers
										snake_case__						:       Any       						=  min(snake_case_			,			snake_case_  )
										snake_case__						:       Union[str, Any]       						=  max(snake_case_			,			snake_case_  ) - min_num_layers
										snake_case__						:       Optional[int]       						=  '''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.
										snake_case__						:       int       						=  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       __magic_name__							(							self					:      List[str]			,			snake_case_					:      PreTrainedTokenizer			,			snake_case_					:      int = -1			,			snake_case_					:      int = -1			,			snake_case_					:      bool = False			,			snake_case_					:      Optional[TensorType] = None			,			):



								'''simple docstring'''



								snake_case__						:       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
										snake_case__						,       snake_case__						:       Dict       						=  common_inputs['''input_ids'''].shape
										# Not using the same length for past_key_values
										snake_case__						:       str       						=  seqlen + 2
										snake_case__						,       snake_case__						:       Union[str, Any]       						=  self.num_layers
										snake_case__						,       snake_case__						:       Optional[int]       						=  self.num_attention_heads
										snake_case__						:       str       						=  (
										    batch,
										    num_encoder_attention_heads,
										    past_key_values_length,
										    self._config.hidden_size // num_encoder_attention_heads,
										)

										snake_case__						:       List[Any]       						=  common_inputs['''attention_mask'''].dtype
										snake_case__						:       List[Any]       						=  torch.cat(
										    [common_inputs['''attention_mask'''], torch.ones(snake_case_			,			snake_case_			,			dtype=snake_case_  )]			,			dim=1  )
										snake_case__						:       Optional[Any]       						=  [
										    (torch.zeros(snake_case_  ), torch.zeros(snake_case_  )) for _ in range(snake_case_  )
										]
								return common_inputs







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



								'''simple docstring'''



								snake_case__						:       str       						=  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
								snake_case__						:       List[Any]       						=  tokenizer.num_special_tokens_to_add(snake_case_  )
								snake_case__						:       List[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
								snake_case__						:       Any       						=  [''' '''.join([tokenizer.unk_token]  ) * seq_length] * batch_size
								snake_case__						:       Any       						=  dict(tokenizer(snake_case_			,			return_tensors=snake_case_  )  )
								return common_inputs







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



								'''simple docstring'''



								if self.task in ["default", "seq2seq-lm"]:
										snake_case__						:       int       						=  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":
										snake_case__						:       Optional[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:
										snake_case__						:       Optional[int]       						=  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       __magic_name__							(							self					:      Tuple			,			snake_case_					:      List[str]			,			snake_case_					:      Union[str, Any]			,			snake_case_					:      Any			,			snake_case_					:      Any  ):



								'''simple docstring'''



								if self.task in ["default", "seq2seq-lm"]:
										snake_case__						:       Optional[Any]       						=  super()._flatten_past_key_values_(snake_case_			,			snake_case_			,			snake_case_			,			snake_case_  )
								else:
										snake_case__						:       Union[str, Any]       						=  super(snake_case_			,			self  )._flatten_past_key_values_(
										    snake_case_			,			snake_case_			,			snake_case_			,			snake_case_  )



