


"""simple docstring"""






import os
from shutil import copyfile
from typing import Any, Dict, List, Optional, Tuple

import sentencepiece as spm

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


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

UpperCamelCase__				:Optional[int]			   =	"""▁"""

UpperCamelCase__				:Union[str, Any]			   =	{"""vocab_file""": """sentencepiece.bpe.model"""}

UpperCamelCase__				:Union[str, Any]			   =	{
    """vocab_file""": {
        """facebook/mbart-large-50-one-to-many-mmt""": (
            """https://huggingface.co/facebook/mbart-large-50-one-to-many-mmt/resolve/main/sentencepiece.bpe.model"""
        ),
    }
}

UpperCamelCase__				:Optional[Any]			   =	{
    """facebook/mbart-large-50-one-to-many-mmt""": 1_024,
}

# fmt: off
UpperCamelCase__				:Any			   =	["""ar_AR""", """cs_CZ""", """de_DE""", """en_XX""", """es_XX""", """et_EE""", """fi_FI""", """fr_XX""", """gu_IN""", """hi_IN""", """it_IT""", """ja_XX""", """kk_KZ""", """ko_KR""", """lt_LT""", """lv_LV""", """my_MM""", """ne_NP""", """nl_XX""", """ro_RO""", """ru_RU""", """si_LK""", """tr_TR""", """vi_VN""", """zh_CN""", """af_ZA""", """az_AZ""", """bn_IN""", """fa_IR""", """he_IL""", """hr_HR""", """id_ID""", """ka_GE""", """km_KH""", """mk_MK""", """ml_IN""", """mn_MN""", """mr_IN""", """pl_PL""", """ps_AF""", """pt_XX""", """sv_SE""", """sw_KE""", """ta_IN""", """te_IN""", """th_TH""", """tl_XX""", """uk_UA""", """ur_PK""", """xh_ZA""", """gl_ES""", """sl_SI"""]






class      A(  lowerCamelCase__		):

		"""simple docstring"""





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

		A    =							[]
		A    =							[]
		def __init__( self					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__=None					,				SCREAMING_SNAKE_CASE__=None					,				SCREAMING_SNAKE_CASE__="</s>"					,				SCREAMING_SNAKE_CASE__="</s>"					,				SCREAMING_SNAKE_CASE__="<s>"					,				SCREAMING_SNAKE_CASE__="<unk>"					,				SCREAMING_SNAKE_CASE__="<pad>"					,				SCREAMING_SNAKE_CASE__="<mask>"					,				SCREAMING_SNAKE_CASE__ = None					,				**SCREAMING_SNAKE_CASE__					,				)      ->	None:

					"""simple docstring"""



					_UpperCamelCase					:Tuple					     =	AddedToken(SCREAMING_SNAKE_CASE__					,				lstrip=SCREAMING_SNAKE_CASE__					,				rstrip=SCREAMING_SNAKE_CASE__   ) if isinstance(SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__   ) else mask_token

					_UpperCamelCase					:List[Any]					     =	{} if sp_model_kwargs is None else sp_model_kwargs

					_UpperCamelCase					:str					     =	kwargs.get('''additional_special_tokens'''					,				[]   )
					kwargs["additional_special_tokens"] += [
					    code for code in FAIRSEQ_LANGUAGE_CODES if code not in kwargs["additional_special_tokens"]
					]

					super().__init__(
					    src_lang=SCREAMING_SNAKE_CASE__					,				tgt_lang=SCREAMING_SNAKE_CASE__					,				eos_token=SCREAMING_SNAKE_CASE__					,				unk_token=SCREAMING_SNAKE_CASE__					,				sep_token=SCREAMING_SNAKE_CASE__					,				cls_token=SCREAMING_SNAKE_CASE__					,				pad_token=SCREAMING_SNAKE_CASE__					,				mask_token=SCREAMING_SNAKE_CASE__					,				sp_model_kwargs=self.sp_model_kwargs					,				**SCREAMING_SNAKE_CASE__					,				)

					_UpperCamelCase					:int					     =	spm.SentencePieceProcessor(**self.sp_model_kwargs   )
					self.sp_model.Load(str(SCREAMING_SNAKE_CASE__   )   )
					_UpperCamelCase					:str					     =	vocab_file

					# Original fairseq vocab and spm vocab must be "aligned":
					# Vocab    |    0    |    1    |   2    |    3    |  4  |  5  |  6  |   7   |   8   |  9
					# -------- | ------- | ------- | ------ | ------- | --- | --- | --- | ----- | ----- | ----
					# fairseq  | '<s>'   | '<pad>' | '</s>' | '<unk>' | ',' | '.' | '▁' | 's'   | '▁de' | '-'
					# spm      | '<unk>' | '<s>'   | '</s>' | ','     | '.' | '▁' | 's' | '▁de' | '-'   | '▁a'

					# Mimic fairseq token-to-id alignment for the first 4 token
					_UpperCamelCase					:Optional[int]					     =	{'''<s>''': 0, '''<pad>''': 1, '''</s>''': 2, '''<unk>''': 3}

					# The first "real" token "," has position 4 in the original fairseq vocab and position 3 in the spm vocab
					_UpperCamelCase					:Any					     =	1

					_UpperCamelCase					:Optional[Any]					     =	len(self.sp_model   )
					_UpperCamelCase					:Any					     =	{
					    code: self.sp_model_size + i + self.fairseq_offset for i, code in enumerate(SCREAMING_SNAKE_CASE__   )
					}
					_UpperCamelCase					:Union[str, Any]					     =	{v: k for k, v in self.lang_code_to_id.items()}
					_UpperCamelCase					:Optional[Any]					     =	len(self.sp_model   ) + len(self.lang_code_to_id   ) + self.fairseq_offset

					self.fairseq_tokens_to_ids.update(self.lang_code_to_id   )
					_UpperCamelCase					:Tuple					     =	{v: k for k, v in self.fairseq_tokens_to_ids.items()}

					_UpperCamelCase					:int					     =	src_lang if src_lang is not None else '''en_XX'''
					_UpperCamelCase					:int					     =	self.lang_code_to_id[self._src_lang]
					_UpperCamelCase					:int					     =	tgt_lang
					self.set_src_lang_special_tokens(self._src_lang   )
		@property
		def   _UpperCamelCase( self   )      ->	int:

					"""simple docstring"""



					return len(self.sp_model   ) + len(self.lang_code_to_id   ) + self.fairseq_offset + 1  # Plus 1 for the mask token
		@property
		def   _UpperCamelCase( self   )      ->	str:

					"""simple docstring"""



					return self._src_lang
		@src_lang.setter
		def   _UpperCamelCase( self					,				SCREAMING_SNAKE_CASE__   )      ->	None:

					"""simple docstring"""



					_UpperCamelCase					:int					     =	new_src_lang
					self.set_src_lang_special_tokens(self._src_lang   )
		def __getstate__( self   )      ->	Dict:

					"""simple docstring"""



					_UpperCamelCase					:int					     =	self.__dict__.copy()
					_UpperCamelCase					:Any					     =	None
					return state
		def __setstate__( self					,				SCREAMING_SNAKE_CASE__   )      ->	None:

					"""simple docstring"""



					_UpperCamelCase					:List[str]					     =	d

					# for backward compatibility
					if not hasattr(self					,				'''sp_model_kwargs'''   ):
								_UpperCamelCase					:int					     =	{}

					_UpperCamelCase					:int					     =	spm.SentencePieceProcessor(**self.sp_model_kwargs   )
					self.sp_model.Load(self.vocab_file   )
		def   _UpperCamelCase( self   )      ->	Dict:

					"""simple docstring"""



					_UpperCamelCase					:Any					     =	{self.convert_ids_to_tokens(SCREAMING_SNAKE_CASE__   ): i for i in range(self.vocab_size   )}
					vocab.update(self.added_tokens_encoder   )
					return vocab
		def   _UpperCamelCase( self					,				SCREAMING_SNAKE_CASE__   )      ->	List[str]:

					"""simple docstring"""



					return self.sp_model.encode(SCREAMING_SNAKE_CASE__					,				out_type=SCREAMING_SNAKE_CASE__   )
		def   _UpperCamelCase( self					,				SCREAMING_SNAKE_CASE__   )      ->	int:

					"""simple docstring"""



					if token in self.fairseq_tokens_to_ids:
								return self.fairseq_tokens_to_ids[token]
					_UpperCamelCase					:Any					     =	self.sp_model.PieceToId(SCREAMING_SNAKE_CASE__   )

					# Need to return unknown token if the SP model returned 0
					return spm_id + self.fairseq_offset if spm_id else self.unk_token_id
		def   _UpperCamelCase( self					,				SCREAMING_SNAKE_CASE__   )      ->	str:

					"""simple docstring"""



					if index in self.fairseq_ids_to_tokens:
								return self.fairseq_ids_to_tokens[index]
					return self.sp_model.IdToPiece(index - self.fairseq_offset   )
		def   _UpperCamelCase( self					,				SCREAMING_SNAKE_CASE__   )      ->	str:

					"""simple docstring"""



					_UpperCamelCase					:Any					     =	[]
					_UpperCamelCase					:List[str]					     =	''''''
					_UpperCamelCase					:Any					     =	False
					for token in tokens:
								# make sure that special tokens are not decoded using sentencepiece model
								if token in self.all_special_tokens:
											if not prev_is_special:
														out_string += " "
											out_string += self.sp_model.decode(SCREAMING_SNAKE_CASE__   ) + token
											_UpperCamelCase					:Union[str, Any]					     =	True
											_UpperCamelCase					:Dict					     =	[]
								else:
											current_sub_tokens.append(SCREAMING_SNAKE_CASE__   )
											_UpperCamelCase					:Dict					     =	False
					out_string += self.sp_model.decode(SCREAMING_SNAKE_CASE__   )
					return out_string.strip()
		def   _UpperCamelCase( self					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__ = None   )      ->	Tuple[str]:

					"""simple docstring"""



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

					if os.path.abspath(self.vocab_file   ) != os.path.abspath(SCREAMING_SNAKE_CASE__   ) and os.path.isfile(self.vocab_file   ):
								copyfile(self.vocab_file					,				SCREAMING_SNAKE_CASE__   )
					elif not os.path.isfile(self.vocab_file   ):
								with open(SCREAMING_SNAKE_CASE__					,				'''wb'''   ) as fi:
											_UpperCamelCase					:Optional[Any]					     =	self.sp_model.serialized_model_proto()
											fi.write(SCREAMING_SNAKE_CASE__   )

					return (out_vocab_file,)
		def   _UpperCamelCase( self					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__ = None					,				SCREAMING_SNAKE_CASE__ = False   )      ->	List[int]:

					"""simple docstring"""



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

					_UpperCamelCase					:List[str]					     =	[1] * len(self.prefix_tokens   )
					_UpperCamelCase					:Tuple					     =	[1] * len(self.suffix_tokens   )
					if token_ids_a is None:
								return prefix_ones + ([0] * len(SCREAMING_SNAKE_CASE__   )) + suffix_ones
					return prefix_ones + ([0] * len(SCREAMING_SNAKE_CASE__   )) + ([0] * len(SCREAMING_SNAKE_CASE__   )) + suffix_ones
		def   _UpperCamelCase( self					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__ = None   )      ->	List[int]:

					"""simple docstring"""



					if token_ids_a is None:
								return self.prefix_tokens + token_ids_a + self.suffix_tokens
					# We don't expect to process pairs, but leave the pair logic for API consistency
					return self.prefix_tokens + token_ids_a + token_ids_a + self.suffix_tokens
		def   _UpperCamelCase( self					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__					,				**SCREAMING_SNAKE_CASE__   )      ->	List[str]:

					"""simple docstring"""



					if src_lang is None or tgt_lang is None:
								raise ValueError('''Translation requires a `src_lang` and a `tgt_lang` for this model'''   )
					_UpperCamelCase					:int					     =	src_lang
					_UpperCamelCase					:Dict					     =	self(SCREAMING_SNAKE_CASE__					,				add_special_tokens=SCREAMING_SNAKE_CASE__					,				return_tensors=SCREAMING_SNAKE_CASE__					,				**SCREAMING_SNAKE_CASE__   )
					_UpperCamelCase					:Tuple					     =	self.convert_tokens_to_ids(SCREAMING_SNAKE_CASE__   )
					_UpperCamelCase					:Optional[int]					     =	tgt_lang_id
					return inputs
		def   _UpperCamelCase( self					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__ = "en_XX"					,				SCREAMING_SNAKE_CASE__ = None					,				SCREAMING_SNAKE_CASE__ = "ro_RO"					,				**SCREAMING_SNAKE_CASE__					,				)      ->	BatchEncoding:

					"""simple docstring"""



					_UpperCamelCase					:Dict					     =	src_lang
					_UpperCamelCase					:Union[str, Any]					     =	tgt_lang
					return super().prepare_seqaseq_batch(SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__					,				**SCREAMING_SNAKE_CASE__   )
		def   _UpperCamelCase( self   )      ->	List[Any]:

					"""simple docstring"""



					return self.set_src_lang_special_tokens(self.src_lang   )
		def   _UpperCamelCase( self   )      ->	str:

					"""simple docstring"""



					return self.set_tgt_lang_special_tokens(self.tgt_lang   )
		def   _UpperCamelCase( self					,				SCREAMING_SNAKE_CASE__   )      ->	None:

					"""simple docstring"""



					_UpperCamelCase					:Tuple					     =	self.lang_code_to_id[src_lang]
					_UpperCamelCase					:Optional[int]					     =	[self.cur_lang_code_id]
					_UpperCamelCase					:Optional[int]					     =	[self.eos_token_id]





		def   _UpperCamelCase( self					,				SCREAMING_SNAKE_CASE__   )      ->	None:

					"""simple docstring"""



					_UpperCamelCase					:Dict					     =	self.lang_code_to_id[tgt_lang]
					_UpperCamelCase					:Tuple					     =	[self.cur_lang_code_id]
					_UpperCamelCase					:Optional[int]					     =	[self.eos_token_id]





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


UpperCamelCase__				:Dict			   =	logging.get_logger(__name__)

UpperCamelCase__				: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(  lowerCamelCase__		):

		"""simple docstring"""





		A    =							"bart"
		A    =							["past_key_values"]
		A    =							{"num_attention_heads": "encoder_attention_heads", "hidden_size": "d_model"}
		def __init__( self					,				SCREAMING_SNAKE_CASE__=5_02_65					,				SCREAMING_SNAKE_CASE__=10_24					,				SCREAMING_SNAKE_CASE__=12					,				SCREAMING_SNAKE_CASE__=40_96					,				SCREAMING_SNAKE_CASE__=16					,				SCREAMING_SNAKE_CASE__=12					,				SCREAMING_SNAKE_CASE__=40_96					,				SCREAMING_SNAKE_CASE__=16					,				SCREAMING_SNAKE_CASE__=0.0					,				SCREAMING_SNAKE_CASE__=0.0					,				SCREAMING_SNAKE_CASE__="gelu"					,				SCREAMING_SNAKE_CASE__=10_24					,				SCREAMING_SNAKE_CASE__=0.1					,				SCREAMING_SNAKE_CASE__=0.0					,				SCREAMING_SNAKE_CASE__=0.0					,				SCREAMING_SNAKE_CASE__=0.0_2					,				SCREAMING_SNAKE_CASE__=0.0					,				SCREAMING_SNAKE_CASE__=False					,				SCREAMING_SNAKE_CASE__=True					,				SCREAMING_SNAKE_CASE__=3					,				SCREAMING_SNAKE_CASE__=1					,				SCREAMING_SNAKE_CASE__=0					,				SCREAMING_SNAKE_CASE__=2					,				SCREAMING_SNAKE_CASE__=True					,				SCREAMING_SNAKE_CASE__=2					,				SCREAMING_SNAKE_CASE__=2					,				**SCREAMING_SNAKE_CASE__					,				)      ->	Optional[Any]:

					"""simple docstring"""



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

					super().__init__(
					    num_labels=SCREAMING_SNAKE_CASE__					,				pad_token_id=SCREAMING_SNAKE_CASE__					,				bos_token_id=SCREAMING_SNAKE_CASE__					,				eos_token_id=SCREAMING_SNAKE_CASE__					,				is_encoder_decoder=SCREAMING_SNAKE_CASE__					,				decoder_start_token_id=SCREAMING_SNAKE_CASE__					,				forced_eos_token_id=SCREAMING_SNAKE_CASE__					,				**SCREAMING_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'''					,				SCREAMING_SNAKE_CASE__   ):
								_UpperCamelCase					: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(  lowerCamelCase__		):

		"""simple docstring"""





		@property
		def   _UpperCamelCase( self   )      ->	Mapping[str, Mapping[int, str]]:

					"""simple docstring"""



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

								if self.use_past:
											_UpperCamelCase					:Optional[Any]					     =	{0: '''batch'''}
											_UpperCamelCase					:int					     =	{0: '''batch''', 1: '''past_decoder_sequence + sequence'''}
								else:
											_UpperCamelCase					:Optional[Any]					     =	{0: '''batch''', 1: '''decoder_sequence'''}
											_UpperCamelCase					:Optional[Any]					     =	{0: '''batch''', 1: '''decoder_sequence'''}

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

					"""simple docstring"""



					if self.task in ["default", "seq2seq-lm"]:
								_UpperCamelCase					:Optional[int]					     =	super().outputs
					else:
								_UpperCamelCase					:List[str]					     =	super(SCREAMING_SNAKE_CASE__					,				self   ).outputs
								if self.use_past:
											_UpperCamelCase     ,      _UpperCamelCase					:int					     =	self.num_layers
											for i in range(SCREAMING_SNAKE_CASE__   ):
														_UpperCamelCase					:Optional[Any]					     =	{0: '''batch''', 2: '''past_sequence + sequence'''}
														_UpperCamelCase					:Optional[Any]					     =	{0: '''batch''', 2: '''past_sequence + sequence'''}
					return common_outputs
		def   _UpperCamelCase( self					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__ = -1					,				SCREAMING_SNAKE_CASE__ = -1					,				SCREAMING_SNAKE_CASE__ = False					,				SCREAMING_SNAKE_CASE__ = None					,				)      ->	Mapping[str, Any]:

					"""simple docstring"""



					_UpperCamelCase					:str					     =	self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
					    SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__   )

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

								_UpperCamelCase					:Optional[int]					     =	torch.cat(
								    [common_inputs['''decoder_attention_mask'''], torch.ones(SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__   )]					,				dim=1   )

								_UpperCamelCase					:Union[str, Any]					     =	[]
								# If the number of encoder and decoder layers are present in the model configuration, both are considered
								_UpperCamelCase     ,      _UpperCamelCase					:int					     =	self.num_layers
								_UpperCamelCase					:Any					     =	min(SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__   )
								_UpperCamelCase					:Optional[int]					     =	max(SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__   ) - min_num_layers
								_UpperCamelCase					:int					     =	'''encoder''' if num_encoder_layers > num_decoder_layers else '''decoder'''

								for _ in range(SCREAMING_SNAKE_CASE__   ):
											common_inputs["past_key_values"].append(
											    (
											        torch.zeros(SCREAMING_SNAKE_CASE__   ),
											        torch.zeros(SCREAMING_SNAKE_CASE__   ),
											        torch.zeros(SCREAMING_SNAKE_CASE__   ),
											        torch.zeros(SCREAMING_SNAKE_CASE__   ),
											    )   )
								# TODO: test this.
								_UpperCamelCase					:Optional[int]					     =	encoder_shape if remaining_side_name == '''encoder''' else decoder_shape
								for _ in range(SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__   ):
											common_inputs["past_key_values"].append((torch.zeros(SCREAMING_SNAKE_CASE__   ), torch.zeros(SCREAMING_SNAKE_CASE__   ))   )
					return common_inputs
		def   _UpperCamelCase( self					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__ = -1					,				SCREAMING_SNAKE_CASE__ = -1					,				SCREAMING_SNAKE_CASE__ = False					,				SCREAMING_SNAKE_CASE__ = None					,				)      ->	Mapping[str, Any]:

					"""simple docstring"""



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

								_UpperCamelCase					:Tuple					     =	common_inputs['''attention_mask'''].dtype
								_UpperCamelCase					:List[Any]					     =	torch.cat(
								    [common_inputs['''attention_mask'''], torch.ones(SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__					,				dtype=SCREAMING_SNAKE_CASE__   )]					,				dim=1   )
								_UpperCamelCase					:int					     =	[
								    (torch.zeros(SCREAMING_SNAKE_CASE__   ), torch.zeros(SCREAMING_SNAKE_CASE__   )) for _ in range(SCREAMING_SNAKE_CASE__   )
								]
					return common_inputs
		def   _UpperCamelCase( self					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__ = -1					,				SCREAMING_SNAKE_CASE__ = -1					,				SCREAMING_SNAKE_CASE__ = False					,				SCREAMING_SNAKE_CASE__ = None					,				)      ->	Mapping[str, Any]:

					"""simple docstring"""



					_UpperCamelCase					:List[str]					     =	compute_effective_axis_dimension(
					    SCREAMING_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
					_UpperCamelCase					:str					     =	tokenizer.num_special_tokens_to_add(SCREAMING_SNAKE_CASE__   )
					_UpperCamelCase					:str					     =	compute_effective_axis_dimension(
					    SCREAMING_SNAKE_CASE__					,				fixed_dimension=OnnxConfig.default_fixed_sequence					,				num_token_to_add=SCREAMING_SNAKE_CASE__   )

					# Generate dummy inputs according to compute batch and sequence
					_UpperCamelCase					:List[Any]					     =	[''' '''.join([tokenizer.unk_token]   ) * seq_length] * batch_size
					_UpperCamelCase					:Optional[Any]					     =	dict(tokenizer(SCREAMING_SNAKE_CASE__					,				return_tensors=SCREAMING_SNAKE_CASE__   )   )
					return common_inputs
		def   _UpperCamelCase( self					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__ = -1					,				SCREAMING_SNAKE_CASE__ = -1					,				SCREAMING_SNAKE_CASE__ = False					,				SCREAMING_SNAKE_CASE__ = None					,				)      ->	Mapping[str, Any]:

					"""simple docstring"""



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

					elif self.task == "causal-lm":
								_UpperCamelCase					:Optional[Any]					     =	self._generate_dummy_inputs_for_causal_lm(
								    SCREAMING_SNAKE_CASE__					,				batch_size=SCREAMING_SNAKE_CASE__					,				seq_length=SCREAMING_SNAKE_CASE__					,				is_pair=SCREAMING_SNAKE_CASE__					,				framework=SCREAMING_SNAKE_CASE__   )
					else:
								_UpperCamelCase					:Any					     =	self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
								    SCREAMING_SNAKE_CASE__					,				batch_size=SCREAMING_SNAKE_CASE__					,				seq_length=SCREAMING_SNAKE_CASE__					,				is_pair=SCREAMING_SNAKE_CASE__					,				framework=SCREAMING_SNAKE_CASE__   )

					return common_inputs





		def   _UpperCamelCase( self					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__   )      ->	Dict:

					"""simple docstring"""



					if self.task in ["default", "seq2seq-lm"]:
								_UpperCamelCase					:Union[str, Any]					     =	super()._flatten_past_key_values_(SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__   )
					else:
								_UpperCamelCase					:Tuple					     =	super(SCREAMING_SNAKE_CASE__					,				self   )._flatten_past_key_values_(
								    SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__					,				SCREAMING_SNAKE_CASE__   )

