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

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

lowerCAmelCase								=						{
    """vocab_file""": {
        """gpt2""": """https://huggingface.co/gpt2/resolve/main/vocab.json""",
        """gpt2-medium""": """https://huggingface.co/gpt2-medium/resolve/main/vocab.json""",
        """gpt2-large""": """https://huggingface.co/gpt2-large/resolve/main/vocab.json""",
        """gpt2-xl""": """https://huggingface.co/gpt2-xl/resolve/main/vocab.json""",
        """distilgpt2""": """https://huggingface.co/distilgpt2/resolve/main/vocab.json""",
    },
    """merges_file""": {
        """gpt2""": """https://huggingface.co/gpt2/resolve/main/merges.txt""",
        """gpt2-medium""": """https://huggingface.co/gpt2-medium/resolve/main/merges.txt""",
        """gpt2-large""": """https://huggingface.co/gpt2-large/resolve/main/merges.txt""",
        """gpt2-xl""": """https://huggingface.co/gpt2-xl/resolve/main/merges.txt""",
        """distilgpt2""": """https://huggingface.co/distilgpt2/resolve/main/merges.txt""",
    },
}

lowerCAmelCase								=						{
    """gpt2""": 10_24,
    """gpt2-medium""": 10_24,
    """gpt2-large""": 10_24,
    """gpt2-xl""": 10_24,
    """distilgpt2""": 10_24,
}






@lru_cache()
def        lowerCAmelCase_       (		)       ->Dict:
			lowerCamelCase__     :					Union[str, Any]		=(
			    list(range(ord('!'      )							,   ord('~'      ) + 1      )      ) + list(range(ord('¡'      )							,   ord('¬'      ) + 1      )      ) + list(range(ord('®'      )							,   ord('ÿ'      ) + 1      )      )
			)
			lowerCamelCase__     :					int		=bs[:]
			lowerCamelCase__     :					Tuple		=0
			for b in range(2**8      ):
						if b not in bs:
									bs.append(snake_case_      )
									cs.append(2**8 + n      )
									n += 1
			lowerCamelCase__     :					Any		=[chr(snake_case_      ) for n in cs]
			return dict(zip(snake_case_							,   snake_case_      )      )






def        lowerCAmelCase_       (		snake_case_		:      int      )       ->List[str]:
			lowerCamelCase__     :					Union[str, Any]		=set()
			lowerCamelCase__     :					Tuple		=word[0]
			for char in word[1:]:
						pairs.add((prev_char, char)      )
						lowerCamelCase__     :					Optional[int]		=char
			return pairs

class    A_     (					A__       ):



							"""simple docstring"""






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





							def __init__(  self  :str					,							lowerCamelCase_  :Optional[int]					,							lowerCamelCase_  :int					,							lowerCamelCase_  :Dict="replace"					,							lowerCamelCase_  :int="<|endoftext|>"					,							lowerCamelCase_  :Tuple="<|endoftext|>"					,							lowerCamelCase_  :Optional[int]="<|endoftext|>"					,							lowerCamelCase_  :Optional[int]=None					,							lowerCamelCase_  :Union[str, Any]=False					,							lowerCamelCase_  :Union[str, Any]=False					,							**lowerCamelCase_  :List[str]					,							):





										"""simple docstring"""

										lowerCamelCase__     :					Optional[int]		=AddedToken(lowerCamelCase_					,							lstrip=lowerCamelCase_					,							rstrip=lowerCamelCase_	) if isinstance(lowerCamelCase_					,							lowerCamelCase_	) else bos_token
										lowerCamelCase__     :					Union[str, Any]		=AddedToken(lowerCamelCase_					,							lstrip=lowerCamelCase_					,							rstrip=lowerCamelCase_	) if isinstance(lowerCamelCase_					,							lowerCamelCase_	) else eos_token
										lowerCamelCase__     :					Optional[Any]		=AddedToken(lowerCamelCase_					,							lstrip=lowerCamelCase_					,							rstrip=lowerCamelCase_	) if isinstance(lowerCamelCase_					,							lowerCamelCase_	) else unk_token
										lowerCamelCase__     :					List[str]		=AddedToken(lowerCamelCase_					,							lstrip=lowerCamelCase_					,							rstrip=lowerCamelCase_	) if isinstance(lowerCamelCase_					,							lowerCamelCase_	) else pad_token
										super().__init__(
										    errors=lowerCamelCase_					,							unk_token=lowerCamelCase_					,							bos_token=lowerCamelCase_					,							eos_token=lowerCamelCase_					,							pad_token=lowerCamelCase_					,							add_prefix_space=lowerCamelCase_					,							add_bos_token=lowerCamelCase_					,							**lowerCamelCase_					,							)
										lowerCamelCase__     :					Optional[int]		=add_bos_token

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

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





							@property
							def 				UpperCAmelCase__							(  self  :Any	):





										"""simple docstring"""

										return len(self.encoder	)





							def 				UpperCAmelCase__							(  self  :Any	):





										"""simple docstring"""

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





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





										"""simple docstring"""

										if token in self.cache:
													return self.cache[token]
										lowerCamelCase__     :					Optional[Any]		=tuple(lowerCamelCase_	)
										lowerCamelCase__     :					int		=get_pairs(lowerCamelCase_	)

										if not pairs:
													return token

										while True:
													lowerCamelCase__     :					str		=min(lowerCamelCase_					,							key=lambda lowerCamelCase_	: self.bpe_ranks.get(lowerCamelCase_					,							float('inf'	)	)	)
													if bigram not in self.bpe_ranks:
																break
													lowerCamelCase__	,    lowerCamelCase__     :					Dict		=bigram
													lowerCamelCase__     :					str		=[]
													lowerCamelCase__     :					Tuple		=0
													while i < len(lowerCamelCase_	):
																try:
																			lowerCamelCase__     :					Dict		=word.index(lowerCamelCase_					,							lowerCamelCase_	)
																except ValueError:
																			new_word.extend(word[i:]	)
																			break
																else:
																			new_word.extend(word[i:j]	)
																			lowerCamelCase__     :					Tuple		=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
													lowerCamelCase__     :					Union[str, Any]		=tuple(lowerCamelCase_	)
													lowerCamelCase__     :					Union[str, Any]		=new_word
													if len(lowerCamelCase_	) == 1:
																break
													else:
																lowerCamelCase__     :					int		=get_pairs(lowerCamelCase_	)
										lowerCamelCase__     :					str		=' '.join(lowerCamelCase_	)
										lowerCamelCase__     :					List[Any]		=word
										return word





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





										"""simple docstring"""

										if self.add_bos_token:
													lowerCamelCase__     :					Dict		=[self.bos_token_id]
										else:
													lowerCamelCase__     :					List[Any]		=[]

										lowerCamelCase__     :					Any		=bos_token_ids + token_ids_a

										if token_ids_a is None:
													return output

										return output + bos_token_ids + token_ids_a





							def 				UpperCAmelCase__							(  self  :int					,							lowerCamelCase_  :List[int]					,							lowerCamelCase_  :Optional[List[int]] = None					,							lowerCamelCase_  :bool = False	):





										"""simple docstring"""

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

										if not self.add_bos_token:
													return super().get_special_tokens_mask(
													    token_ids_a=lowerCamelCase_					,							token_ids_a=lowerCamelCase_					,							already_has_special_tokens=lowerCamelCase_	)

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





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





										"""simple docstring"""

										lowerCamelCase__     :					Dict		=[]
										for token in re.findall(self.pat					,							lowerCamelCase_	):
													lowerCamelCase__     :					str		=''.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(lowerCamelCase_	).split(' '	)	)
										return bpe_tokens





							def 				UpperCAmelCase__							(  self  :int					,							lowerCamelCase_  :List[str]	):





										"""simple docstring"""

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





							def 				UpperCAmelCase__							(  self  :Optional[Any]					,							lowerCamelCase_  :Any	):





										"""simple docstring"""

										return self.decoder.get(lowerCamelCase_	)





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





										"""simple docstring"""

										lowerCamelCase__     :					Tuple		=''.join(lowerCamelCase_	)
										lowerCamelCase__     :					List[Any]		=bytearray([self.byte_decoder[c] for c in text]	).decode('utf-8'					,							errors=self.errors	)
										return text





							def 				UpperCAmelCase__							(  self  :Optional[int]					,							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
										lowerCamelCase__     :					Tuple		=os.path.join(
										    lowerCamelCase_					,							(filename_prefix + '-' if filename_prefix else '') + VOCAB_FILES_NAMES['vocab_file']	)
										lowerCamelCase__     :					List[Any]		=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'	)

										lowerCamelCase__     :					int		=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!'	)
																			lowerCamelCase__     :					Dict		=token_index
																writer.write(' '.join(lowerCamelCase_	) + '\n'	)
																index += 1

										return vocab_file, merge_file





							def 				UpperCAmelCase__							(  self  :List[str]					,							lowerCamelCase_  :int					,							lowerCamelCase_  :Tuple=False					,							**lowerCamelCase_  :Dict	):





										"""simple docstring"""

										lowerCamelCase__     :					int		=kwargs.pop('add_prefix_space'					,							self.add_prefix_space	)
										if is_split_into_words or add_prefix_space:
													lowerCamelCase__     :					Any		=' ' + text
										return (text, kwargs)





							def 				UpperCAmelCase__							(  self  :List[Any]					,							lowerCamelCase_  :"Conversation"	):





										"""simple docstring"""

										lowerCamelCase__     :					List[str]		=[]
										for is_user, text in conversation.iter_texts():
													input_ids.extend(self.encode(lowerCamelCase_					,							add_special_tokens=lowerCamelCase_	) + [self.eos_token_id]	)
										if len(lowerCamelCase_	) > self.model_max_length:
													lowerCamelCase__     :					str		=input_ids[-self.model_max_length :]
										return input_ids

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


lowerCAmelCase								=						logging.get_logger(__name__)

lowerCAmelCase								=						{
    """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    A_     (					A__       ):



							"""simple docstring"""






							SCREAMING_SNAKE_CASE_     				=       """blenderbot"""
							SCREAMING_SNAKE_CASE_     				=       ["""past_key_values"""]
							SCREAMING_SNAKE_CASE_     				=       {"""num_attention_heads""": """encoder_attention_heads""", """hidden_size""": """d_model"""}





							def __init__(  self  :Optional[int]					,							lowerCamelCase_  :Optional[Any]=8_008					,							lowerCamelCase_  :Optional[Any]=128					,							lowerCamelCase_  :Optional[int]=2					,							lowerCamelCase_  :Tuple=10_240					,							lowerCamelCase_  :Optional[int]=32					,							lowerCamelCase_  :Optional[int]=24					,							lowerCamelCase_  :Optional[Any]=10_240					,							lowerCamelCase_  :Union[str, Any]=32					,							lowerCamelCase_  :Any=0.0					,							lowerCamelCase_  :int=0.0					,							lowerCamelCase_  :str=True					,							lowerCamelCase_  :List[Any]=True					,							lowerCamelCase_  :Tuple="gelu"					,							lowerCamelCase_  :str=2_560					,							lowerCamelCase_  :Union[str, Any]=0.1					,							lowerCamelCase_  :Optional[int]=0.0					,							lowerCamelCase_  :Union[str, Any]=0.0					,							lowerCamelCase_  :List[str]=0.02					,							lowerCamelCase_  :Any=1					,							lowerCamelCase_  :List[Any]=False					,							lowerCamelCase_  :str=0					,							lowerCamelCase_  :Dict=1					,							lowerCamelCase_  :List[Any]=2					,							lowerCamelCase_  :int=3					,							lowerCamelCase_  :int=2					,							**lowerCamelCase_  :List[str]					,							):





										"""simple docstring"""

										lowerCamelCase__     :					Optional[int]		=vocab_size
										lowerCamelCase__     :					Optional[int]		=max_position_embeddings
										lowerCamelCase__     :					Dict		=d_model
										lowerCamelCase__     :					str		=encoder_ffn_dim
										lowerCamelCase__     :					Optional[Any]		=encoder_layers
										lowerCamelCase__     :					List[Any]		=encoder_attention_heads
										lowerCamelCase__     :					Any		=decoder_ffn_dim
										lowerCamelCase__     :					Any		=decoder_layers
										lowerCamelCase__     :					Any		=decoder_attention_heads
										lowerCamelCase__     :					Dict		=dropout
										lowerCamelCase__     :					Any		=attention_dropout
										lowerCamelCase__     :					Dict		=activation_dropout
										lowerCamelCase__     :					Tuple		=activation_function
										lowerCamelCase__     :					List[Any]		=init_std
										lowerCamelCase__     :					str		=encoder_layerdrop
										lowerCamelCase__     :					Any		=decoder_layerdrop
										lowerCamelCase__     :					Union[str, Any]		=use_cache
										lowerCamelCase__     :					List[str]		=encoder_layers
										lowerCamelCase__     :					Optional[int]		=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_					,							decoder_start_token_id=lowerCamelCase_					,							encoder_no_repeat_ngram_size=lowerCamelCase_					,							forced_eos_token_id=lowerCamelCase_					,							**lowerCamelCase_					,							)






class    A_     (					A__       ):



							"""simple docstring"""






							@property
							def 				UpperCAmelCase__							(  self  :Tuple	):





										"""simple docstring"""

										if self.task in ["default", "seq2seq-lm"]:
													lowerCamelCase__     :					Dict		=OrderedDict(
													    [
													        ('input_ids', {0: 'batch', 1: 'encoder_sequence'}),
													        ('attention_mask', {0: 'batch', 1: 'encoder_sequence'}),
													    ]	)
													if self.use_past:
																lowerCamelCase__     :					Dict		={0: 'batch'}
																lowerCamelCase__     :					Tuple		={0: 'batch', 1: 'past_decoder_sequence + sequence'}
													else:
																lowerCamelCase__     :					Optional[int]		={0: 'batch', 1: 'decoder_sequence'}
																lowerCamelCase__     :					Tuple		={0: 'batch', 1: 'decoder_sequence'}
													if self.use_past:
																self.fill_with_past_key_values_(lowerCamelCase_					,							direction='inputs'	)
										elif self.task == "causal-lm":
													lowerCamelCase__     :					Any		=OrderedDict(
													    [
													        ('input_ids', {0: 'batch', 1: 'encoder_sequence'}),
													        ('attention_mask', {0: 'batch', 1: 'encoder_sequence'}),
													    ]	)
													if self.use_past:
																lowerCamelCase__	,    lowerCamelCase__     :					List[Any]		=self.num_layers
																for i in range(lowerCamelCase_	):
																			lowerCamelCase__     :					Tuple		={0: 'batch', 2: 'past_sequence + sequence'}
																			lowerCamelCase__     :					Optional[int]		={0: 'batch', 2: 'past_sequence + sequence'}
										else:
													lowerCamelCase__     :					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
							# Copied from transformers.models.bart.configuration_bart.BartOnnxConfig.outputs
							def 				UpperCAmelCase__							(  self  :List[str]	):





										"""simple docstring"""

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





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





										"""simple docstring"""

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

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





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





										"""simple docstring"""

										lowerCamelCase__     :					Union[str, Any]		=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
													lowerCamelCase__	,    lowerCamelCase__     :					Optional[int]		=common_inputs['input_ids'].shape
													lowerCamelCase__     :					List[Any]		=seqlen
													lowerCamelCase__	,    lowerCamelCase__     :					Tuple		=self.num_layers
													lowerCamelCase__	,    lowerCamelCase__     :					List[str]		=self.num_attention_heads
													lowerCamelCase__     :					Optional[int]		=(
													    batch,
													    num_encoder_attention_heads,
													    past_key_values_length,
													    self._config.hidden_size // num_encoder_attention_heads,
													)
													lowerCamelCase__     :					List[str]		=common_inputs['attention_mask'].dtype
													lowerCamelCase__     :					Tuple		=torch.cat(
													    [common_inputs['attention_mask'], torch.ones(lowerCamelCase_					,							lowerCamelCase_					,							dtype=lowerCamelCase_	)]					,							dim=1	)
													lowerCamelCase__     :					Optional[int]		=[
													    (torch.zeros(lowerCamelCase_	), torch.zeros(lowerCamelCase_	)) for _ in range(lowerCamelCase_	)
													]
										return common_inputs





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





										"""simple docstring"""

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





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





										"""simple docstring"""

										if self.task in ["default", "seq2seq-lm"]:
													lowerCamelCase__     :					str		=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":
													lowerCamelCase__     :					List[Any]		=self._generate_dummy_inputs_for_causal_lm(
													    lowerCamelCase_					,							batch_size=lowerCamelCase_					,							seq_length=lowerCamelCase_					,							is_pair=lowerCamelCase_					,							framework=lowerCamelCase_	)
										else:
													lowerCamelCase__     :					Dict		=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 				UpperCAmelCase__							(  self  :Optional[int]					,							lowerCamelCase_  :Tuple					,							lowerCamelCase_  :Optional[Any]					,							lowerCamelCase_  :List[Any]					,							lowerCamelCase_  :Dict	):





										"""simple docstring"""

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





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





										"""simple docstring"""

										if direction not in ["inputs", "outputs"]:
													raise ValueError(f"""direction must either be \"inputs\" or \"outputs\", but {direction} was given"""	)

										lowerCamelCase__     :					Optional[Any]		='past_key_values' if direction == 'inputs' else 'present'
										lowerCamelCase__	,    lowerCamelCase__     :					Union[str, Any]		=self.num_layers

										lowerCamelCase__     :					Optional[Any]		='past_encoder_sequence'
										lowerCamelCase__     :					Union[str, Any]		='past_decoder_sequence' if direction == 'inputs' else 'past_decoder_sequence + sequence'

										for i in range(lowerCamelCase_	):
													lowerCamelCase__     :					Union[str, Any]		={0: 'batch', 2: decoder_sequence}
													lowerCamelCase__     :					Any		={0: 'batch', 2: decoder_sequence}
													lowerCamelCase__     :					List[Any]		={0: 'batch', 2: encoder_sequence}
													lowerCamelCase__     :					Tuple		={0: 'batch', 2: encoder_sequence}