



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


lowerCamelCase							:str       = logging.get_logger(__name__)

lowerCamelCase							:List[Any]       = '''▁'''

lowerCamelCase							:List[str]       = {'''vocab_file''': '''sentencepiece.bpe.model'''}

lowerCamelCase							:str       = {
    '''vocab_file''': {
        '''facebook/nllb-200-distilled-600M''': (
            '''https://huggingface.co/facebook/nllb-200-distilled-600M/blob/main/sentencepiece.bpe.model'''
        ),
    }
}

lowerCamelCase							:List[Any]       = {
    '''facebook/nllb-200-distilled-600M''': 1_0_2_4,
}

# fmt: off
lowerCamelCase							:Tuple       = ['''ace_Arab''', '''ace_Latn''', '''acm_Arab''', '''acq_Arab''', '''aeb_Arab''', '''afr_Latn''', '''ajp_Arab''', '''aka_Latn''', '''amh_Ethi''', '''apc_Arab''', '''arb_Arab''', '''ars_Arab''', '''ary_Arab''', '''arz_Arab''', '''asm_Beng''', '''ast_Latn''', '''awa_Deva''', '''ayr_Latn''', '''azb_Arab''', '''azj_Latn''', '''bak_Cyrl''', '''bam_Latn''', '''ban_Latn''', '''bel_Cyrl''', '''bem_Latn''', '''ben_Beng''', '''bho_Deva''', '''bjn_Arab''', '''bjn_Latn''', '''bod_Tibt''', '''bos_Latn''', '''bug_Latn''', '''bul_Cyrl''', '''cat_Latn''', '''ceb_Latn''', '''ces_Latn''', '''cjk_Latn''', '''ckb_Arab''', '''crh_Latn''', '''cym_Latn''', '''dan_Latn''', '''deu_Latn''', '''dik_Latn''', '''dyu_Latn''', '''dzo_Tibt''', '''ell_Grek''', '''eng_Latn''', '''epo_Latn''', '''est_Latn''', '''eus_Latn''', '''ewe_Latn''', '''fao_Latn''', '''pes_Arab''', '''fij_Latn''', '''fin_Latn''', '''fon_Latn''', '''fra_Latn''', '''fur_Latn''', '''fuv_Latn''', '''gla_Latn''', '''gle_Latn''', '''glg_Latn''', '''grn_Latn''', '''guj_Gujr''', '''hat_Latn''', '''hau_Latn''', '''heb_Hebr''', '''hin_Deva''', '''hne_Deva''', '''hrv_Latn''', '''hun_Latn''', '''hye_Armn''', '''ibo_Latn''', '''ilo_Latn''', '''ind_Latn''', '''isl_Latn''', '''ita_Latn''', '''jav_Latn''', '''jpn_Jpan''', '''kab_Latn''', '''kac_Latn''', '''kam_Latn''', '''kan_Knda''', '''kas_Arab''', '''kas_Deva''', '''kat_Geor''', '''knc_Arab''', '''knc_Latn''', '''kaz_Cyrl''', '''kbp_Latn''', '''kea_Latn''', '''khm_Khmr''', '''kik_Latn''', '''kin_Latn''', '''kir_Cyrl''', '''kmb_Latn''', '''kon_Latn''', '''kor_Hang''', '''kmr_Latn''', '''lao_Laoo''', '''lvs_Latn''', '''lij_Latn''', '''lim_Latn''', '''lin_Latn''', '''lit_Latn''', '''lmo_Latn''', '''ltg_Latn''', '''ltz_Latn''', '''lua_Latn''', '''lug_Latn''', '''luo_Latn''', '''lus_Latn''', '''mag_Deva''', '''mai_Deva''', '''mal_Mlym''', '''mar_Deva''', '''min_Latn''', '''mkd_Cyrl''', '''plt_Latn''', '''mlt_Latn''', '''mni_Beng''', '''khk_Cyrl''', '''mos_Latn''', '''mri_Latn''', '''zsm_Latn''', '''mya_Mymr''', '''nld_Latn''', '''nno_Latn''', '''nob_Latn''', '''npi_Deva''', '''nso_Latn''', '''nus_Latn''', '''nya_Latn''', '''oci_Latn''', '''gaz_Latn''', '''ory_Orya''', '''pag_Latn''', '''pan_Guru''', '''pap_Latn''', '''pol_Latn''', '''por_Latn''', '''prs_Arab''', '''pbt_Arab''', '''quy_Latn''', '''ron_Latn''', '''run_Latn''', '''rus_Cyrl''', '''sag_Latn''', '''san_Deva''', '''sat_Beng''', '''scn_Latn''', '''shn_Mymr''', '''sin_Sinh''', '''slk_Latn''', '''slv_Latn''', '''smo_Latn''', '''sna_Latn''', '''snd_Arab''', '''som_Latn''', '''sot_Latn''', '''spa_Latn''', '''als_Latn''', '''srd_Latn''', '''srp_Cyrl''', '''ssw_Latn''', '''sun_Latn''', '''swe_Latn''', '''swh_Latn''', '''szl_Latn''', '''tam_Taml''', '''tat_Cyrl''', '''tel_Telu''', '''tgk_Cyrl''', '''tgl_Latn''', '''tha_Thai''', '''tir_Ethi''', '''taq_Latn''', '''taq_Tfng''', '''tpi_Latn''', '''tsn_Latn''', '''tso_Latn''', '''tuk_Latn''', '''tum_Latn''', '''tur_Latn''', '''twi_Latn''', '''tzm_Tfng''', '''uig_Arab''', '''ukr_Cyrl''', '''umb_Latn''', '''urd_Arab''', '''uzn_Latn''', '''vec_Latn''', '''vie_Latn''', '''war_Latn''', '''wol_Latn''', '''xho_Latn''', '''ydd_Hebr''', '''yor_Latn''', '''yue_Hant''', '''zho_Hans''', '''zho_Hant''', '''zul_Latn''']







class      _lowerCAmelCase							(      __UpperCAmelCase			):
	__SCREAMING_SNAKE_CASE       :		Optional[Any]		      = VOCAB_FILES_NAMES
	__SCREAMING_SNAKE_CASE       :		Optional[Any]		      = PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
	__SCREAMING_SNAKE_CASE       :		List[Any]		      = PRETRAINED_VOCAB_FILES_MAP
	__SCREAMING_SNAKE_CASE       :		int		      = ['input_ids', 'attention_mask']

	__SCREAMING_SNAKE_CASE       :		List[int]		      = []
	__SCREAMING_SNAKE_CASE       :		List[int]		      = []


	def __init__(self	,				lowercase	,				lowercase="<s>"	,				lowercase="</s>"	,				lowercase="</s>"	,				lowercase="<s>"	,				lowercase="<unk>"	,				lowercase="<pad>"	,				lowercase="<mask>"	,				lowercase=None	,				lowercase=None	,				lowercase=None	,				lowercase = None	,				lowercase=None	,				lowercase=False	,				**lowercase	,				):
				# Mask token behave like a normal word, i.e. include the space before it
				A_     :						Dict     =					AddedToken(lowercase	,				lstrip=lowercase	,				rstrip=lowercase							) if isinstance(lowercase	,				lowercase							) else mask_token

				A_     :						List[str]     =					{} if sp_model_kwargs is None else sp_model_kwargs
				A_     :						int     =					legacy_behaviour

				super().__init__(
				    bos_token=lowercase	,				eos_token=lowercase	,				unk_token=lowercase	,				sep_token=lowercase	,				cls_token=lowercase	,				pad_token=lowercase	,				mask_token=lowercase	,				tokenizer_file=lowercase	,				src_lang=lowercase	,				tgt_lang=lowercase	,				additional_special_tokens=lowercase	,				sp_model_kwargs=self.sp_model_kwargs	,				legacy_behaviour=lowercase	,				**lowercase	,				)

				A_     :						Any     =					spm.SentencePieceProcessor(**self.sp_model_kwargs							)
				self.sp_model.Load(str(lowercase							)							)
				A_     :						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>' | 'an' | '▁n' | '▁m' | '▁t' | '▁k' | '▁a'
				# spm      | '<unk>' | '<s>'   | '</s>' | 'an'    | '▁n' | '▁m' | '▁t' | '▁k' | '▁a' | '▁s'

				# Mimic fairseq token-to-id alignment for the first 4 token
				A_     :						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
				A_     :						Union[str, Any]     =					1

				A_     :						int     =					len(self.sp_model							)
				A_     :						Optional[int]     =					{
				    code: self.sp_model_size + i + self.fairseq_offset for i, code in enumerate(lowercase							)
				}
				A_     :						int     =					{v: k for k, v in self.lang_code_to_id.items()}
				A_     :						str     =					len(self.sp_model							) + len(self.lang_code_to_id							) + self.fairseq_offset

				self.fairseq_tokens_to_ids.update(self.lang_code_to_id							)
				A_     :						Optional[int]     =					{v: k for k, v in self.fairseq_tokens_to_ids.items()}
				A_     :						str     =					list(self.lang_code_to_id.keys()							)

				if additional_special_tokens is not None:
							# Only add those special tokens if they are not already there.
							self._additional_special_tokens.extend(
							    [t for t in additional_special_tokens if t not in self._additional_special_tokens]							)

				A_     :						Dict     =					src_lang if src_lang is not None else """eng_Latn"""
				A_     :						str     =					self.lang_code_to_id[self._src_lang]
				A_     :						List[Any]     =					tgt_lang
				self.set_src_lang_special_tokens(self._src_lang							)


	def __getstate__(self							):
				A_     :						str     =					self.__dict__.copy()
				A_     :						Tuple     =					None
				A_     :						int     =					self.sp_model.serialized_model_proto()
				return state


	def __setstate__(self	,				lowercase							):
				A_     :						Tuple     =					d

				# for backward compatibility
				if not hasattr(self	,				"""sp_model_kwargs"""							):
							A_     :						Optional[int]     =					{}

				A_     :						Optional[Any]     =					spm.SentencePieceProcessor(**self.sp_model_kwargs							)
				self.sp_model.LoadFromSerializedProto(self.sp_model_proto							)


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


	@property
	def    _a     (self							):
				return self._src_lang


	@src_lang.setter
	def    _a     (self	,				lowercase							):
				A_     :						int     =					new_src_lang
				self.set_src_lang_special_tokens(self._src_lang							)


	def    _a     (self	,				lowercase	,				lowercase = None	,				lowercase = False							):

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

				A_     :						str     =					[1] * len(self.prefix_tokens							)
				A_     :						Optional[Any]     =					[1] * len(self.suffix_tokens							)
				if token_ids_a is None:
							return prefix_ones + ([0] * len(lowercase							)) + suffix_ones
				return prefix_ones + ([0] * len(lowercase							)) + ([0] * len(lowercase							)) + suffix_ones


	def    _a     (self	,				lowercase	,				lowercase = None							):
				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    _a     (self	,				lowercase	,				lowercase = None							):
				A_     :						Tuple     =					[self.sep_token_id]
				A_     :						Any     =					[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    _a     (self	,				lowercase	,				lowercase	,				lowercase	,				lowercase	,				**lowercase							):
				if src_lang is None or tgt_lang is None:
							raise ValueError("""Translation requires a `src_lang` and a `tgt_lang` for this model"""							)
				A_     :						List[str]     =					src_lang
				A_     :						Dict     =					self(lowercase	,				add_special_tokens=lowercase	,				return_tensors=lowercase	,				**lowercase							)
				A_     :						List[str]     =					self.convert_tokens_to_ids(lowercase							)
				A_     :						Dict     =					tgt_lang_id
				return inputs


	def    _a     (self							):
				A_     :						Dict     =					{self.convert_ids_to_tokens(lowercase							): i for i in range(self.vocab_size							)}
				vocab.update(self.added_tokens_encoder							)
				return vocab


	def    _a     (self	,				lowercase							):
				return self.sp_model.encode(lowercase	,				out_type=lowercase							)


	def    _a     (self	,				lowercase							):
				if token in self.fairseq_tokens_to_ids:
							return self.fairseq_tokens_to_ids[token]
				A_     :						str     =					self.sp_model.PieceToId(lowercase							)

				# 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    _a     (self	,				lowercase							):
				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    _a     (self	,				lowercase							):
				A_     :						Optional[Any]     =					"""""".join(lowercase							).replace(lowercase	,				""" """							).strip()
				return out_string


	def    _a     (self	,				lowercase	,				lowercase = None							):
				if not os.path.isdir(lowercase							):
							logger.error(F'Vocabulary path ({save_directory}) should be a directory'							)
							return
				A_     :						Union[str, Any]     =					os.path.join(
				    lowercase	,				(filename_prefix + """-""" if filename_prefix else """""") + VOCAB_FILES_NAMES["""vocab_file"""]							)

				if os.path.abspath(self.vocab_file							) != os.path.abspath(lowercase							) and os.path.isfile(self.vocab_file							):
							copyfile(self.vocab_file	,				lowercase							)
				elif not os.path.isfile(self.vocab_file							):
							with open(lowercase	,				"""wb"""							) as fi:
										A_     :						Dict     =					self.sp_model.serialized_model_proto()
										fi.write(lowercase							)

				return (out_vocab_file,)


	def    _a     (self	,				lowercase	,				lowercase = "eng_Latn"	,				lowercase = None	,				lowercase = "fra_Latn"	,				**lowercase	,				):
				A_     :						Tuple     =					src_lang
				A_     :						Optional[Any]     =					tgt_lang
				return super().prepare_seqaseq_batch(lowercase	,				lowercase	,				**lowercase							)


	def    _a     (self							):
				return self.set_src_lang_special_tokens(self.src_lang							)


	def    _a     (self							):
				return self.set_tgt_lang_special_tokens(self.tgt_lang							)


	def    _a     (self	,				lowercase							):
				A_     :						List[str]     =					self.lang_code_to_id[src_lang]
				if self.legacy_behaviour:
							A_     :						int     =					[]
							A_     :						Tuple     =					[self.eos_token_id, self.cur_lang_code]
				else:
							A_     :						Tuple     =					[self.cur_lang_code]
							A_     :						Optional[Any]     =					[self.eos_token_id]


	def    _a     (self	,				lowercase							):
				A_     :						int     =					self.lang_code_to_id[lang]
				if self.legacy_behaviour:
							A_     :						Tuple     =					[]
							A_     :						List[str]     =					[self.eos_token_id, self.cur_lang_code]
				else:
							A_     :						Union[str, Any]     =					[self.cur_lang_code]
							A_     :						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


lowerCamelCase							:Dict       = logging.get_logger(__name__)

lowerCamelCase							:Any       = {
    '''facebook/bart-large''': '''https://huggingface.co/facebook/bart-large/resolve/main/config.json''',
    # See all BART models at https://huggingface.co/models?filter=bart
}







class      _lowerCAmelCase							(      __UpperCAmelCase			):
	__SCREAMING_SNAKE_CASE       :		List[Any]		      = 'bart'
	__SCREAMING_SNAKE_CASE       :		Union[str, Any]		      = ['past_key_values']
	__SCREAMING_SNAKE_CASE       :		Dict		      = {'num_attention_heads': 'encoder_attention_heads', 'hidden_size': 'd_model'}


	def __init__(self	,				lowercase=50265	,				lowercase=1024	,				lowercase=12	,				lowercase=4096	,				lowercase=16	,				lowercase=12	,				lowercase=4096	,				lowercase=16	,				lowercase=0.0	,				lowercase=0.0	,				lowercase="gelu"	,				lowercase=1024	,				lowercase=0.1	,				lowercase=0.0	,				lowercase=0.0	,				lowercase=0.02	,				lowercase=0.0	,				lowercase=False	,				lowercase=True	,				lowercase=3	,				lowercase=1	,				lowercase=0	,				lowercase=2	,				lowercase=True	,				lowercase=2	,				lowercase=2	,				**lowercase	,				):
				A_     :						Optional[int]     =					vocab_size
				A_     :						Dict     =					max_position_embeddings
				A_     :						Dict     =					d_model
				A_     :						Any     =					encoder_ffn_dim
				A_     :						Dict     =					encoder_layers
				A_     :						Optional[int]     =					encoder_attention_heads
				A_     :						Tuple     =					decoder_ffn_dim
				A_     :						List[str]     =					decoder_layers
				A_     :						int     =					decoder_attention_heads
				A_     :						Dict     =					dropout
				A_     :						List[str]     =					attention_dropout
				A_     :						int     =					activation_dropout
				A_     :						Dict     =					activation_function
				A_     :						List[Any]     =					init_std
				A_     :						Dict     =					encoder_layerdrop
				A_     :						Tuple     =					decoder_layerdrop
				A_     :						Optional[int]     =					classifier_dropout
				A_     :						Union[str, Any]     =					use_cache
				A_     :						Dict     =					encoder_layers
				A_     :						Dict     =					scale_embedding  # scale factor will be sqrt(d_model) if True

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

				# ensure backward compatibility for BART CNN models
				if self.forced_bos_token_id is None and kwargs.get("""force_bos_token_to_be_generated"""	,				lowercase							):
							A_     :						List[str]     =					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      _lowerCAmelCase							(      __UpperCAmelCase			):


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

							if self.use_past:
										A_     :						Union[str, Any]     =					{0: """batch"""}
										A_     :						List[Any]     =					{0: """batch""", 1: """past_decoder_sequence + sequence"""}
							else:
										A_     :						Optional[int]     =					{0: """batch""", 1: """decoder_sequence"""}
										A_     :						List[str]     =					{0: """batch""", 1: """decoder_sequence"""}

							if self.use_past:
										self.fill_with_past_key_values_(lowercase	,				direction="""inputs"""							)
				elif self.task == "causal-lm":
							# TODO: figure this case out.
							A_     :						List[Any]     =					OrderedDict(
							    [
							        ("""input_ids""", {0: """batch""", 1: """encoder_sequence"""}),
							        ("""attention_mask""", {0: """batch""", 1: """encoder_sequence"""}),
							    ]							)
							if self.use_past:
										A_,   A_     :						Optional[int]     =					self.num_layers
										for i in range(lowercase							):
													A_     :						List[str]     =					{0: """batch""", 2: """past_sequence + sequence"""}
													A_     :						List[str]     =					{0: """batch""", 2: """past_sequence + sequence"""}
				else:
							A_     :						Union[str, 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    _a     (self							):
				if self.task in ["default", "seq2seq-lm"]:
							A_     :						int     =					super().outputs
				else:
							A_     :						int     =					super(lowercase	,				self							).outputs
							if self.use_past:
										A_,   A_     :						Union[str, Any]     =					self.num_layers
										for i in range(lowercase							):
													A_     :						List[str]     =					{0: """batch""", 2: """past_sequence + sequence"""}
													A_     :						Optional[int]     =					{0: """batch""", 2: """past_sequence + sequence"""}
				return common_outputs


	def    _a     (self	,				lowercase	,				lowercase = -1	,				lowercase = -1	,				lowercase = False	,				lowercase = None	,				):
				A_     :						Optional[int]     =					self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
				    lowercase	,				lowercase	,				lowercase	,				lowercase	,				lowercase							)

				# Generate decoder inputs
				A_     :						int     =					seq_length if not self.use_past else 1
				A_     :						int     =					self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
				    lowercase	,				lowercase	,				lowercase	,				lowercase	,				lowercase							)
				A_     :						Optional[int]     =					{F'decoder_{name}': tensor for name, tensor in decoder_inputs.items()}
				A_     :						Dict     =					dict(**lowercase	,				**lowercase							)

				if self.use_past:
							if not is_torch_available():
										raise ValueError("""Cannot generate dummy past_keys inputs without PyTorch installed."""							)
							else:
										import torch
							A_,   A_     :						Union[str, Any]     =					common_inputs["""input_ids"""].shape
							A_     :						Optional[Any]     =					common_inputs["""decoder_input_ids"""].shape[1]
							A_,   A_     :						str     =					self.num_attention_heads
							A_     :						Tuple     =					(
							    batch,
							    num_encoder_attention_heads,
							    encoder_seq_length,
							    self._config.hidden_size // num_encoder_attention_heads,
							)
							A_     :						Tuple     =					decoder_seq_length + 3
							A_     :						Tuple     =					(
							    batch,
							    num_decoder_attention_heads,
							    decoder_past_length,
							    self._config.hidden_size // num_decoder_attention_heads,
							)

							A_     :						List[str]     =					torch.cat(
							    [common_inputs["""decoder_attention_mask"""], torch.ones(lowercase	,				lowercase							)]	,				dim=1							)

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

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


	def    _a     (self	,				lowercase	,				lowercase = -1	,				lowercase = -1	,				lowercase = False	,				lowercase = None	,				):
				A_     :						Dict     =					self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
				    lowercase	,				lowercase	,				lowercase	,				lowercase	,				lowercase							)

				if self.use_past:
							if not is_torch_available():
										raise ValueError("""Cannot generate dummy past_keys inputs without PyTorch installed."""							)
							else:
										import torch
							A_,   A_     :						List[str]     =					common_inputs["""input_ids"""].shape
							# Not using the same length for past_key_values
							A_     :						Optional[Any]     =					seqlen + 2
							A_,   A_     :						str     =					self.num_layers
							A_,   A_     :						Optional[int]     =					self.num_attention_heads
							A_     :						str     =					(
							    batch,
							    num_encoder_attention_heads,
							    past_key_values_length,
							    self._config.hidden_size // num_encoder_attention_heads,
							)

							A_     :						Union[str, Any]     =					common_inputs["""attention_mask"""].dtype
							A_     :						int     =					torch.cat(
							    [common_inputs["""attention_mask"""], torch.ones(lowercase	,				lowercase	,				dtype=lowercase							)]	,				dim=1							)
							A_     :						int     =					[
							    (torch.zeros(lowercase							), torch.zeros(lowercase							)) for _ in range(lowercase							)
							]
				return common_inputs


	def    _a     (self	,				lowercase	,				lowercase = -1	,				lowercase = -1	,				lowercase = False	,				lowercase = None	,				):
				# Copied from OnnxConfig.generate_dummy_inputs
				# Did not use super(OnnxConfigWithPast, self).generate_dummy_inputs for code clarity.
				# If dynamic axis (-1) we forward with a fixed dimension of 2 samples to avoid optimizations made by ONNX
				A_     :						List[Any]     =					compute_effective_axis_dimension(
				    lowercase	,				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
				A_     :						Union[str, Any]     =					tokenizer.num_special_tokens_to_add(lowercase							)
				A_     :						List[Any]     =					compute_effective_axis_dimension(
				    lowercase	,				fixed_dimension=OnnxConfig.default_fixed_sequence	,				num_token_to_add=lowercase							)

				# Generate dummy inputs according to compute batch and sequence
				A_     :						str     =					[""" """.join([tokenizer.unk_token]							) * seq_length] * batch_size
				A_     :						Tuple     =					dict(tokenizer(lowercase	,				return_tensors=lowercase							)							)
				return common_inputs


	def    _a     (self	,				lowercase	,				lowercase = -1	,				lowercase = -1	,				lowercase = False	,				lowercase = None	,				):
				if self.task in ["default", "seq2seq-lm"]:
							A_     :						Union[str, Any]     =					self._generate_dummy_inputs_for_default_and_seqaseq_lm(
							    lowercase	,				batch_size=lowercase	,				seq_length=lowercase	,				is_pair=lowercase	,				framework=lowercase							)

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

				return common_inputs


	def    _a     (self	,				lowercase	,				lowercase	,				lowercase	,				lowercase							):
				if self.task in ["default", "seq2seq-lm"]:
							A_     :						Optional[Any]     =					super()._flatten_past_key_values_(lowercase	,				lowercase	,				lowercase	,				lowercase							)
				else:
							A_     :						List[Any]     =					super(lowercase	,				self							)._flatten_past_key_values_(
							    lowercase	,				lowercase	,				lowercase	,				lowercase							)