



'''simple docstring'''




from __future__ import annotations

import unittest

from transformers import RoFormerConfig, is_tf_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
				import tensorflow as tf

				from transformers import (
				    TFRoFormerForCausalLM,
				    TFRoFormerForMaskedLM,
				    TFRoFormerForMultipleChoice,
				    TFRoFormerForQuestionAnswering,
				    TFRoFormerForSequenceClassification,
				    TFRoFormerForTokenClassification,
				    TFRoFormerModel,
				)
				from transformers.models.roformer.modeling_tf_roformer import (
				    TFRoFormerSelfAttention,
				    TFRoFormerSinusoidalPositionalEmbedding,
				)







class      _lowerCAmelCase							:


	def __init__(self	,				lowercase	,				lowercase=13	,				lowercase=7	,				lowercase=True	,				lowercase=True	,				lowercase=True	,				lowercase=True	,				lowercase=99	,				lowercase=32	,				lowercase=2	,				lowercase=4	,				lowercase=37	,				lowercase="gelu"	,				lowercase=0.1	,				lowercase=0.1	,				lowercase=512	,				lowercase=16	,				lowercase=2	,				lowercase=0.02	,				lowercase=3	,				lowercase=4	,				lowercase=None	,				):
				A_     :						Dict     =					parent
				A_     :						Optional[int]     =					13
				A_     :						str     =					7
				A_     :						Optional[int]     =					True
				A_     :						List[Any]     =					True
				A_     :						str     =					True
				A_     :						str     =					True
				A_     :						str     =					99
				A_     :						Dict     =					32
				A_     :						str     =					2
				A_     :						Any     =					4
				A_     :						Tuple     =					37
				A_     :						List[Any]     =					"""gelu"""
				A_     :						Union[str, Any]     =					0.1
				A_     :						int     =					0.1
				A_     :						str     =					512
				A_     :						Dict     =					16
				A_     :						Optional[int]     =					2
				A_     :						Union[str, Any]     =					0.02
				A_     :						str     =					3
				A_     :						Tuple     =					4
				A_     :						Union[str, Any]     =					None


	def    _a     (self							):
				A_     :						Optional[Any]     =					ids_tensor([self.batch_size, self.seq_length]	,				self.vocab_size							)

				A_     :						Optional[int]     =					None
				if self.use_input_mask:
							A_     :						List[str]     =					random_attention_mask([self.batch_size, self.seq_length]							)

				A_     :						List[str]     =					None
				if self.use_token_type_ids:
							A_     :						Optional[Any]     =					ids_tensor([self.batch_size, self.seq_length]	,				self.type_vocab_size							)

				A_     :						Optional[int]     =					None
				A_     :						List[Any]     =					None
				A_     :						Any     =					None
				if self.use_labels:
							A_     :						Tuple     =					ids_tensor([self.batch_size]	,				self.type_sequence_label_size							)
							A_     :						Optional[int]     =					ids_tensor([self.batch_size, self.seq_length]	,				self.num_labels							)
							A_     :						str     =					ids_tensor([self.batch_size]	,				self.num_choices							)

				A_     :						List[str]     =					RoFormerConfig(
				    vocab_size=self.vocab_size	,				hidden_size=self.hidden_size	,				num_hidden_layers=self.num_hidden_layers	,				num_attention_heads=self.num_attention_heads	,				intermediate_size=self.intermediate_size	,				hidden_act=self.hidden_act	,				hidden_dropout_prob=self.hidden_dropout_prob	,				attention_probs_dropout_prob=self.attention_probs_dropout_prob	,				max_position_embeddings=self.max_position_embeddings	,				type_vocab_size=self.type_vocab_size	,				initializer_range=self.initializer_range	,				return_dict=lowercase	,				)

				return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels


	def    _a     (self	,				lowercase	,				lowercase	,				lowercase	,				lowercase	,				lowercase	,				lowercase	,				lowercase							):
				A_     :						Tuple     =					TFRoFormerModel(config=lowercase							)
				A_     :						int     =					{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}

				A_     :						str     =					[input_ids, input_mask]
				A_     :						Any     =					model(lowercase							)

				A_     :						Union[str, Any]     =					model(lowercase							)

				self.parent.assertEqual(result.last_hidden_state.shape	,				(self.batch_size, self.seq_length, self.hidden_size)							)


	def    _a     (self	,				lowercase	,				lowercase	,				lowercase	,				lowercase	,				lowercase	,				lowercase	,				lowercase							):
				A_     :						Any     =					True
				A_     :						Optional[int]     =					TFRoFormerForCausalLM(config=lowercase							)
				A_     :						List[Any]     =					{
				    """input_ids""": input_ids,
				    """attention_mask""": input_mask,
				    """token_type_ids""": token_type_ids,
				}
				A_     :						Union[str, Any]     =					model(lowercase							)["""logits"""]
				self.parent.assertListEqual(
				    list(prediction_scores.numpy().shape							)	,				[self.batch_size, self.seq_length, self.vocab_size]							)


	def    _a     (self	,				lowercase	,				lowercase	,				lowercase	,				lowercase	,				lowercase	,				lowercase	,				lowercase							):
				A_     :						Union[str, Any]     =					TFRoFormerForMaskedLM(config=lowercase							)
				A_     :						Union[str, Any]     =					{
				    """input_ids""": input_ids,
				    """attention_mask""": input_mask,
				    """token_type_ids""": token_type_ids,
				}
				A_     :						Dict     =					model(lowercase							)
				self.parent.assertEqual(result.logits.shape	,				(self.batch_size, self.seq_length, self.vocab_size)							)


	def    _a     (self	,				lowercase	,				lowercase	,				lowercase	,				lowercase	,				lowercase	,				lowercase	,				lowercase							):
				A_     :						Optional[int]     =					self.num_labels
				A_     :						Union[str, Any]     =					TFRoFormerForSequenceClassification(config=lowercase							)
				A_     :						Any     =					{
				    """input_ids""": input_ids,
				    """attention_mask""": input_mask,
				    """token_type_ids""": token_type_ids,
				}

				A_     :						str     =					model(lowercase							)
				self.parent.assertEqual(result.logits.shape	,				(self.batch_size, self.num_labels)							)


	def    _a     (self	,				lowercase	,				lowercase	,				lowercase	,				lowercase	,				lowercase	,				lowercase	,				lowercase							):
				A_     :						Optional[int]     =					self.num_choices
				A_     :						int     =					TFRoFormerForMultipleChoice(config=lowercase							)
				A_     :						Optional[int]     =					tf.tile(tf.expand_dims(lowercase	,				1							)	,				(1, self.num_choices, 1)							)
				A_     :						List[str]     =					tf.tile(tf.expand_dims(lowercase	,				1							)	,				(1, self.num_choices, 1)							)
				A_     :						Optional[int]     =					tf.tile(tf.expand_dims(lowercase	,				1							)	,				(1, self.num_choices, 1)							)
				A_     :						str     =					{
				    """input_ids""": multiple_choice_inputs_ids,
				    """attention_mask""": multiple_choice_input_mask,
				    """token_type_ids""": multiple_choice_token_type_ids,
				}
				A_     :						Optional[Any]     =					model(lowercase							)
				self.parent.assertEqual(result.logits.shape	,				(self.batch_size, self.num_choices)							)


	def    _a     (self	,				lowercase	,				lowercase	,				lowercase	,				lowercase	,				lowercase	,				lowercase	,				lowercase							):
				A_     :						Any     =					self.num_labels
				A_     :						Union[str, Any]     =					TFRoFormerForTokenClassification(config=lowercase							)
				A_     :						int     =					{
				    """input_ids""": input_ids,
				    """attention_mask""": input_mask,
				    """token_type_ids""": token_type_ids,
				}
				A_     :						str     =					model(lowercase							)
				self.parent.assertEqual(result.logits.shape	,				(self.batch_size, self.seq_length, self.num_labels)							)


	def    _a     (self	,				lowercase	,				lowercase	,				lowercase	,				lowercase	,				lowercase	,				lowercase	,				lowercase							):
				A_     :						List[Any]     =					TFRoFormerForQuestionAnswering(config=lowercase							)
				A_     :						List[Any]     =					{
				    """input_ids""": input_ids,
				    """attention_mask""": input_mask,
				    """token_type_ids""": token_type_ids,
				}

				A_     :						Tuple     =					model(lowercase							)
				self.parent.assertEqual(result.start_logits.shape	,				(self.batch_size, self.seq_length)							)
				self.parent.assertEqual(result.end_logits.shape	,				(self.batch_size, self.seq_length)							)


	def    _a     (self							):
				A_     :						Optional[int]     =					self.prepare_config_and_inputs()
				(
				    (
				    A_			
				),   (
				    A_			
				),   (
				    A_			
				),   (
				    A_			
				),   (
				    A_			
				),   (
				    A_			
				),   (
				    A_			
				),   			
				)     :						Any     =					config_and_inputs
				A_     :						Dict     =					{"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
				return config, inputs_dict







@require_tf
class      _lowerCAmelCase							(      _lowerCamelCase				,      _lowerCamelCase				,      unittest.TestCase			):
	__SCREAMING_SNAKE_CASE       :		Dict		      = (
	    (
	        TFRoFormerModel,
	        TFRoFormerForCausalLM,
	        TFRoFormerForMaskedLM,
	        TFRoFormerForQuestionAnswering,
	        TFRoFormerForSequenceClassification,
	        TFRoFormerForTokenClassification,
	        TFRoFormerForMultipleChoice,
	    )
	    if is_tf_available()
	    else ()
	)
	__SCREAMING_SNAKE_CASE       :		int		      = (
	    {
	        'feature-extraction': TFRoFormerModel,
	        'fill-mask': TFRoFormerForMaskedLM,
	        'question-answering': TFRoFormerForQuestionAnswering,
	        'text-classification': TFRoFormerForSequenceClassification,
	        'text-generation': TFRoFormerForCausalLM,
	        'token-classification': TFRoFormerForTokenClassification,
	        'zero-shot': TFRoFormerForSequenceClassification,
	    }
	    if is_tf_available()
	    else {}
	)

	__SCREAMING_SNAKE_CASE       :		Optional[Any]		      = False
	__SCREAMING_SNAKE_CASE       :		List[str]		      = False


	def    _a     (self	,				lowercase	,				lowercase	,				lowercase	,				lowercase	,				lowercase							):


				if pipeline_test_casse_name == "TextGenerationPipelineTests":
							return True

				return False


	def    _a     (self							):
				A_     :						Any     =					TFRoFormerModelTester(self							)
				A_     :						Dict     =					ConfigTester(self	,				config_class=lowercase	,				hidden_size=37							)


	def    _a     (self							):
				self.config_tester.run_common_tests()


	def    _a     (self							):
				A_     :						List[str]     =					self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_model(*lowercase							)


	def    _a     (self							):
				A_     :						int     =					self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_masked_lm(*lowercase							)


	def    _a     (self							):
				A_     :						Dict     =					self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_lm_head(*lowercase							)


	def    _a     (self							):
				A_     :						List[str]     =					self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_multiple_choice(*lowercase							)


	def    _a     (self							):
				A_     :						Dict     =					self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_question_answering(*lowercase							)


	def    _a     (self							):
				A_     :						Any     =					self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_sequence_classification(*lowercase							)


	def    _a     (self							):
				A_     :						str     =					self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_for_token_classification(*lowercase							)


	@slow
	def    _a     (self							):
				A_     :						Any     =					TFRoFormerModel.from_pretrained("""junnyu/roformer_chinese_base"""							)
				self.assertIsNotNone(lowercase							)







@require_tf
class      _lowerCAmelCase							(      unittest.TestCase			):


	@slow
	def    _a     (self							):
				A_     :						Optional[int]     =					TFRoFormerForMaskedLM.from_pretrained("""junnyu/roformer_chinese_base"""							)
				A_     :						int     =					tf.constant([[0, 1, 2, 3, 4, 5]]							)
				A_     :						Optional[Any]     =					model(lowercase							)[0]

				# TODO Replace vocab size
				A_     :						Dict     =					50000

				A_     :						Tuple     =					[1, 6, vocab_size]
				self.assertEqual(output.shape	,				lowercase							)

				print(output[:, :3, :3]							)

				# TODO Replace values below with what was printed above.
				A_     :						Tuple     =					tf.constant(
				    [
				        [
				            [-0.12_05_33_41, -1.0_26_49_01, 0.29_22_19_46],
				            [-1.5_13_37_83, 0.19_74_33, 0.15_19_06_07],
				            [-5.0_13_54_03, -3.90_02_56, -0.84_03_87_64],
				        ]
				    ]							)
				tf.debugging.assert_near(output[:, :3, :3]	,				lowercase	,				atol=1E-4							)







@require_tf
class      _lowerCAmelCase							(      unittest.TestCase			):
	__SCREAMING_SNAKE_CASE       :		int		      = 1E-4


	def    _a     (self							):
				A_     :						Dict     =					tf.constant([[4, 10]]							)
				A_     :						Tuple     =					TFRoFormerSinusoidalPositionalEmbedding(num_positions=6	,				embedding_dim=6							)

				A_     :						str     =					emba(input_ids.shape							)
				A_     :						Any     =					tf.constant(
				    [[0.00_00, 0.00_00, 0.00_00, 1.00_00, 1.00_00, 1.00_00], [0.84_15, 0.04_64, 0.00_22, 0.54_03, 0.99_89, 1.00_00]]							)

				tf.debugging.assert_near(lowercase	,				lowercase	,				atol=self.tolerance							)


	def    _a     (self							):
				A_     :						Tuple     =					tf.constant(
				    [
				        [0.00_00, 0.00_00, 0.00_00, 0.00_00, 0.00_00],
				        [0.84_15, 0.82_19, 0.80_20, 0.78_19, 0.76_17],
				        [0.90_93, 0.93_64, 0.95_81, 0.97_49, 0.98_70],
				    ]							)
				A_     :						int     =					TFRoFormerSinusoidalPositionalEmbedding(num_positions=512	,				embedding_dim=512							)
				emba([2, 16, 512]							)
				A_     :						Union[str, Any]     =					emba.weight[:3, :5]

				tf.debugging.assert_near(lowercase	,				lowercase	,				atol=self.tolerance							)







@require_tf
class      _lowerCAmelCase							(      unittest.TestCase			):
	__SCREAMING_SNAKE_CASE       :		int		      = 1E-4


	def    _a     (self							):
				A_     :						Dict     =					tf.reshape(tf.range(2 * 12 * 16 * 64	,				dtype=tf.floataa							)	,				shape=(2, 12, 16, 64)							) / 100

				A_     :						List[Any]     =					-tf.reshape(tf.range(2 * 12 * 16 * 64	,				dtype=tf.floataa							)	,				shape=(2, 12, 16, 64)							) / 100

				A_     :						Optional[int]     =					TFRoFormerSinusoidalPositionalEmbedding(num_positions=32	,				embedding_dim=64							)
				A_     :						Any     =					embed_positions([2, 16, 768]							)[None, None, :, :]

				A_,   A_     :						int     =					TFRoFormerSelfAttention.apply_rotary_position_embeddings(
				    lowercase	,				lowercase	,				lowercase							)

				A_     :						str     =					tf.constant(
				    [
				        [0.00_00, 0.01_00, 0.02_00, 0.03_00, 0.04_00, 0.05_00, 0.06_00, 0.07_00],
				        [-0.20_12, 0.88_97, 0.02_63, 0.94_01, 0.20_74, 0.94_63, 0.34_81, 0.93_43],
				        [-1.70_57, 0.62_71, -1.21_45, 1.38_97, -0.63_03, 1.76_47, -0.11_73, 1.89_85],
				        [-2.17_31, -1.63_97, -2.73_58, 0.28_54, -2.18_40, 1.71_83, -1.30_18, 2.48_71],
				        [0.27_17, -3.61_73, -2.92_06, -2.19_88, -3.66_38, 0.38_58, -2.91_55, 2.29_80],
				        [3.98_59, -2.15_80, -0.79_84, -4.49_04, -4.11_81, -2.02_52, -4.47_82, 1.12_53],
				    ]							)
				A_     :						Any     =					tf.constant(
				    [
				        [0.00_00, -0.01_00, -0.02_00, -0.03_00, -0.04_00, -0.05_00, -0.06_00, -0.07_00],
				        [0.20_12, -0.88_97, -0.02_63, -0.94_01, -0.20_74, -0.94_63, -0.34_81, -0.93_43],
				        [1.70_57, -0.62_71, 1.21_45, -1.38_97, 0.63_03, -1.76_47, 0.11_73, -1.89_85],
				        [2.17_31, 1.63_97, 2.73_58, -0.28_54, 2.18_40, -1.71_83, 1.30_18, -2.48_71],
				        [-0.27_17, 3.61_73, 2.92_06, 2.19_88, 3.66_38, -0.38_58, 2.91_55, -2.29_80],
				        [-3.98_59, 2.15_80, 0.79_84, 4.49_04, 4.11_81, 2.02_52, 4.47_82, -1.12_53],
				    ]							)

				tf.debugging.assert_near(query_layer[0, 0, :6, :8]	,				lowercase	,				atol=self.tolerance							)
				tf.debugging.assert_near(key_layer[0, 0, :6, :8]	,				lowercase	,				atol=self.tolerance							)




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