




import unittest
from unittest.util import safe_repr

from transformers import AutoTokenizer, RwkvConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
							import torch

							from transformers import (
							    RWKV_PRETRAINED_MODEL_ARCHIVE_LIST,
							    RwkvForCausalLM,
							    RwkvModel,
							)
							from transformers.pytorch_utils import is_torch_greater_or_equal_than_2_0
else:
							UpperCamelCase__		=						False


class     __SCREAMING_SNAKE_CASE							:

					def __init__(    self			,	__lowercase			,	__lowercase=14			,	__lowercase=7			,	__lowercase=True			,	__lowercase=False			,	__lowercase=True			,	__lowercase=True			,	__lowercase=True			,	__lowercase=99			,	__lowercase=32			,	__lowercase=5			,	__lowercase=37			,	__lowercase="gelu"			,	__lowercase=0.1			,	__lowercase=0.1			,	__lowercase=512			,	__lowercase=16			,	__lowercase=2			,	__lowercase=3			,	__lowercase=4			,	__lowercase=None			,	):







						'''simple docstring'''




						lowerCamelCase_							:		Any							       =							parent
						lowerCamelCase_							:		Any							       =							batch_size
						lowerCamelCase_							:		List[str]							       =							seq_length
						lowerCamelCase_							:		Union[str, Any]							       =							is_training
						lowerCamelCase_							:		Union[str, Any]							       =							use_token_type_ids
						lowerCamelCase_							:		str							       =							use_input_mask
						lowerCamelCase_							:		List[Any]							       =							use_labels
						lowerCamelCase_							:		str							       =							use_mc_token_ids
						lowerCamelCase_							:		Optional[Any]							       =							vocab_size
						lowerCamelCase_							:		int							       =							hidden_size
						lowerCamelCase_							:		List[Any]							       =							num_hidden_layers
						lowerCamelCase_							:		Any							       =							intermediate_size
						lowerCamelCase_							:		List[str]							       =							hidden_act
						lowerCamelCase_							:		str							       =							hidden_dropout_prob
						lowerCamelCase_							:		Tuple							       =							attention_probs_dropout_prob
						lowerCamelCase_							:		Optional[Any]							       =							max_position_embeddings
						lowerCamelCase_							:		Union[str, Any]							       =							type_vocab_size
						lowerCamelCase_							:		Dict							       =							type_sequence_label_size
						lowerCamelCase_							:		Union[str, Any]							       =							num_labels
						lowerCamelCase_							:		Optional[int]							       =							num_choices
						lowerCamelCase_							:		Tuple							       =							scope
						lowerCamelCase_							:		List[str]							       =							vocab_size - 1
						lowerCamelCase_							:		Optional[Any]							       =							vocab_size - 1
						lowerCamelCase_							:		int							       =							vocab_size - 1

					def      lowercase_							(    self ):







						'''simple docstring'''




						return RwkvConfig.from_pretrained('sgugger/rwkv-4-pile-7b' )

					def      lowercase_							(    self			,	__lowercase=False			,	__lowercase=False			,	__lowercase=False ):







						'''simple docstring'''




						lowerCamelCase_							:		str							       =							ids_tensor([self.batch_size, self.seq_length]			,	self.vocab_size )

						lowerCamelCase_							:		Tuple							       =							None
						if self.use_input_mask:
							lowerCamelCase_							:		int							       =							random_attention_mask([self.batch_size, self.seq_length] )

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

						lowerCamelCase_							:		Tuple							       =							None
						if self.use_mc_token_ids:
							lowerCamelCase_							:		int							       =							ids_tensor([self.batch_size, self.num_choices]			,	self.seq_length )

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

						lowerCamelCase_							:		List[str]							       =							self.get_config(
						    gradient_checkpointing=__lowercase			,	scale_attn_by_inverse_layer_idx=__lowercase			,	reorder_and_upcast_attn=__lowercase			,	)

						return (
						    config,
						    input_ids,
						    input_mask,
						    None,
						    token_type_ids,
						    mc_token_ids,
						    sequence_labels,
						    token_labels,
						    choice_labels,
						)

					def      lowercase_							(    self			,	__lowercase=False			,	__lowercase=False			,	__lowercase=False ):







						'''simple docstring'''




						return RwkvConfig(
						    vocab_size=self.vocab_size			,	hidden_size=self.hidden_size			,	num_hidden_layers=self.num_hidden_layers			,	intermediate_size=self.intermediate_size			,	activation_function=self.hidden_act			,	resid_pdrop=self.hidden_dropout_prob			,	attn_pdrop=self.attention_probs_dropout_prob			,	n_positions=self.max_position_embeddings			,	type_vocab_size=self.type_vocab_size			,	use_cache=__lowercase			,	bos_token_id=self.bos_token_id			,	eos_token_id=self.eos_token_id			,	pad_token_id=self.pad_token_id			,	gradient_checkpointing=__lowercase			,	scale_attn_by_inverse_layer_idx=__lowercase			,	reorder_and_upcast_attn=__lowercase			,	)

					def      lowercase_							(    self ):







						'''simple docstring'''




						lowerCamelCase_							:		Dict							       =							self.get_config()
						lowerCamelCase_							:		Optional[int]							       =							300
						return config

					def      lowercase_							(    self ):







						'''simple docstring'''




						(
						    (
						    lowerCamelCase_
						)       ,      (
						    lowerCamelCase_
						)       ,      (
						    lowerCamelCase_
						)       ,      (
						    lowerCamelCase_
						)       ,      (
						    lowerCamelCase_
						)       ,      (
						    lowerCamelCase_
						)       ,      (
						    lowerCamelCase_
						)       ,      (
						    lowerCamelCase_
						)       ,      (
						    lowerCamelCase_
						)       ,      
						)							:		List[str]							       =							self.prepare_config_and_inputs()

						lowerCamelCase_							:		str							       =							floats_tensor([self.batch_size, self.seq_length, self.hidden_size] )
						lowerCamelCase_							:		Optional[int]							       =							ids_tensor([self.batch_size, self.seq_length]			,	vocab_size=2 )

						return (
						    config,
						    input_ids,
						    input_mask,
						    head_mask,
						    token_type_ids,
						    sequence_labels,
						    token_labels,
						    choice_labels,
						    encoder_hidden_states,
						    encoder_attention_mask,
						)

					def      lowercase_							(    self			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	*__lowercase ):







						'''simple docstring'''




						lowerCamelCase_							:		str							       =							True
						lowerCamelCase_							:		Any							       =							RwkvModel(config=__lowercase )
						model.to(__lowercase )
						model.eval()

						lowerCamelCase_							:		str							       =							model(__lowercase )

						self.parent.assertEqual(result.last_hidden_state.shape			,	(self.batch_size, self.seq_length, self.hidden_size) )
						self.parent.assertEqual(len(result.hidden_states )			,	config.num_hidden_layers + 1 )

					def      lowercase_							(    self			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	*__lowercase ):







						'''simple docstring'''




						lowerCamelCase_							:		Dict							       =							RwkvForCausalLM(__lowercase )
						model.to(__lowercase )
						model.eval()

						lowerCamelCase_							:		int							       =							model(__lowercase			,	labels=__lowercase )
						self.parent.assertEqual(result.loss.shape			,	() )
						self.parent.assertEqual(result.logits.shape			,	(self.batch_size, self.seq_length, self.vocab_size) )

					def      lowercase_							(    self			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	*__lowercase ):







						'''simple docstring'''




						lowerCamelCase_							:		List[Any]							       =							RwkvModel(config=__lowercase )
						model.to(__lowercase )
						model.eval()

						lowerCamelCase_							:		Optional[Any]							       =							model(__lowercase )
						lowerCamelCase_							:		Any							       =							outputs.last_hidden_state

						lowerCamelCase_							:		List[Any]							       =							model(input_ids[:, :2] )
						lowerCamelCase_							:		List[str]							       =							outputs.last_hidden_state

						# Using the state computed on the first inputs, we will get the same output
						lowerCamelCase_							:		int							       =							model(input_ids[:, 2:]			,	state=outputs.state )
						lowerCamelCase_							:		List[str]							       =							outputs.last_hidden_state

						self.parent.assertTrue(torch.allclose(torch.cat([output_one, output_two]			,	dim=1 )			,	__lowercase			,	atol=1E-5 ) )

					def      lowercase_							(    self			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	*__lowercase			,	__lowercase=False ):







						'''simple docstring'''




						lowerCamelCase_							:		Tuple							       =							RwkvForCausalLM(__lowercase )
						model.to(__lowercase )
						if gradient_checkpointing:
							model.gradient_checkpointing_enable()

						lowerCamelCase_							:		Union[str, Any]							       =							model(__lowercase			,	labels=__lowercase )
						self.parent.assertEqual(result.loss.shape			,	() )
						self.parent.assertEqual(result.logits.shape			,	(self.batch_size, self.seq_length, self.vocab_size) )
						result.loss.backward()





					def      lowercase_							(    self ):







						'''simple docstring'''




						lowerCamelCase_							:		Tuple							       =							self.prepare_config_and_inputs()

						(
						    (
						    lowerCamelCase_
						)       ,      (
						    lowerCamelCase_
						)       ,      (
						    lowerCamelCase_
						)       ,      (
						    lowerCamelCase_
						)       ,      (
						    lowerCamelCase_
						)       ,      (
						    lowerCamelCase_
						)       ,      (
						    lowerCamelCase_
						)       ,      (
						    lowerCamelCase_
						)       ,      (
						    lowerCamelCase_
						)       ,      
						)							:		Any							       =							config_and_inputs

						lowerCamelCase_							:		Tuple							       =							{'input_ids': input_ids}

						return config, inputs_dict


@unittest.skipIf(
    not is_torch_greater_or_equal_than_2_0       ,					reason="""See https://github.com/huggingface/transformers/pull/24204"""  )
@require_torch
class     __SCREAMING_SNAKE_CASE							(		lowerCamelCase       ,					lowerCamelCase       ,					lowerCamelCase       ,					unittest.TestCase  ):
					_lowerCamelCase		  =			(RwkvModel, RwkvForCausalLM) if is_torch_available() else ()
					_lowerCamelCase		  =			(
					    {"""feature-extraction""": RwkvModel, """text-generation""": RwkvForCausalLM} if is_torch_available() else {}
					)
					# all_generative_model_classes = (RwkvForCausalLM,) if is_torch_available() else ()
					_lowerCamelCase		  =			False
					_lowerCamelCase		  =			False
					_lowerCamelCase		  =			False
					_lowerCamelCase		  =			False
					_lowerCamelCase		  =			False  # Rwkv does not support head masking

					def      lowercase_							(    self ):







						'''simple docstring'''




						lowerCamelCase_							:		Optional[int]							       =							RwkvModelTester(self )
						lowerCamelCase_							:		List[str]							       =							ConfigTester(
						    self			,	config_class=__lowercase			,	n_embd=37			,	common_properties=['hidden_size', 'num_hidden_layers'] )

					def      lowercase_							(    self			,	__lowercase			,	__lowercase			,	__lowercase=None ):







						'''simple docstring'''




						if isinstance(__lowercase			,	torch.Tensor ):
							lowerCamelCase_       ,      lowerCamelCase_							:		List[Any]							       =							member.max().item(), member.min().item()
						elif isinstance(__lowercase			,	__lowercase ) or isinstance(__lowercase			,	__lowercase ):
							lowerCamelCase_       ,      lowerCamelCase_							:		Union[str, Any]							       =							max(__lowercase ), min(__lowercase )

						if not isinstance(__lowercase			,	__lowercase ):
							raise TypeError('container should be a list or tuple' )
						elif len(__lowercase ) != 2:
							raise ValueError('container should have 2 elements' )

						lowerCamelCase_       ,      lowerCamelCase_							:		str							       =							container

						lowerCamelCase_							:		Tuple							       =							(min_value >= expected_min) and (max_value <= expected_max)

						if not is_inside_interval:
							lowerCamelCase_							:		Any							       =							'%s not found in %s' % (safe_repr(__lowercase ), safe_repr(__lowercase ))
							self.fail(self._formatMessage(__lowercase			,	__lowercase ) )

					def      lowercase_							(    self ):







						'''simple docstring'''




						self.config_tester.run_common_tests()

					def      lowercase_							(    self ):







						'''simple docstring'''




						lowerCamelCase_							:		Dict							       =							self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_rwkv_model(*__lowercase )

					def      lowercase_							(    self ):







						'''simple docstring'''




						lowerCamelCase_							:		Union[str, Any]							       =							self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_causl_lm(*__lowercase )

					def      lowercase_							(    self ):







						'''simple docstring'''




						lowerCamelCase_							:		Optional[Any]							       =							self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_state_equivalency(*__lowercase )

					def      lowercase_							(    self ):







						'''simple docstring'''




						lowerCamelCase_       ,      lowerCamelCase_							:		str							       =							self.model_tester.prepare_config_and_inputs_for_common()

						for model_class in self.all_model_classes:
							lowerCamelCase_							:		Optional[int]							       =							model_class(config=__lowercase )
							for name, param in model.named_parameters():
								if "time_decay" in name:
									if param.requires_grad:
										self.assertTrue(param.data.max().item() == 3.0 )
										self.assertTrue(param.data.min().item() == -5.0 )
								elif "time_first" in name:
									if param.requires_grad:
										# check if it's a ones like
										self.assertTrue(torch.allclose(param.data			,	torch.ones_like(param.data )			,	atol=1E-5			,	rtol=1E-5 ) )
								elif any(x in name for x in ['time_mix_key', 'time_mix_receptance'] ):
									if param.requires_grad:
										self.assertInterval(
										    param.data			,	[0.0, 1.0]			,	msg=f"Parameter {name} of model {model_class} seems not properly initialized"			,	)
								elif "time_mix_value" in name:
									if param.requires_grad:
										self.assertInterval(
										    param.data			,	[0.0, 1.3]			,	msg=f"Parameter {name} of model {model_class} seems not properly initialized"			,	)

					def      lowercase_							(    self ):







						'''simple docstring'''




						lowerCamelCase_       ,      lowerCamelCase_							:		Optional[int]							       =							self.model_tester.prepare_config_and_inputs_for_common()
						lowerCamelCase_							:		Any							       =							True

						lowerCamelCase_							:		Any							       =							getattr(self.model_tester			,	'seq_length'			,	__lowercase )

						for model_class in self.all_model_classes:
							lowerCamelCase_							:		Any							       =							True
							lowerCamelCase_							:		Union[str, Any]							       =							False
							lowerCamelCase_							:		Tuple							       =							True
							lowerCamelCase_							:		Tuple							       =							model_class(__lowercase )
							model.to(__lowercase )
							model.eval()

							lowerCamelCase_							:		List[Any]							       =							self._prepare_for_class(__lowercase			,	__lowercase )
							lowerCamelCase_							:		List[str]							       =							inputs['input_ids'].shape[0]
							with torch.no_grad():
								lowerCamelCase_							:		Optional[int]							       =							model(**__lowercase )
							lowerCamelCase_							:		Dict							       =							outputs.attentions
							self.assertEqual(len(__lowercase )			,	self.model_tester.num_hidden_layers )

							# check that output_attentions also work using config
							del inputs_dict["output_attentions"]
							lowerCamelCase_							:		Any							       =							True
							lowerCamelCase_							:		Tuple							       =							model_class(__lowercase )
							model.to(__lowercase )
							model.eval()

							lowerCamelCase_							:		Dict							       =							self._prepare_for_class(__lowercase			,	__lowercase )
							lowerCamelCase_							:		Any							       =							inputs['input_ids'].shape[0]
							with torch.no_grad():
								lowerCamelCase_							:		Tuple							       =							model(**__lowercase )
							lowerCamelCase_							:		Union[str, Any]							       =							outputs.attentions
							self.assertEqual(len(__lowercase )			,	self.model_tester.num_hidden_layers )

							self.assertListEqual(
							    list(attentions[0].shape[-3:] )			,	[batch_size, seq_len, config.hidden_size]			,	)
							lowerCamelCase_							:		List[Any]							       =							len(__lowercase )

							# Check attention is always last and order is fine
							lowerCamelCase_							:		int							       =							True
							lowerCamelCase_							:		Any							       =							True
							lowerCamelCase_							:		Union[str, Any]							       =							model_class(__lowercase )
							model.to(__lowercase )
							model.eval()

							lowerCamelCase_							:		str							       =							self._prepare_for_class(__lowercase			,	__lowercase )
							lowerCamelCase_							:		Optional[Any]							       =							inputs['input_ids'].shape[0]
							with torch.no_grad():
								lowerCamelCase_							:		Union[str, Any]							       =							model(**__lowercase )

							lowerCamelCase_							:		List[Any]							       =							1
							self.assertEqual(out_len + added_hidden_states			,	len(__lowercase ) )

							lowerCamelCase_							:		Dict							       =							outputs.attentions

							self.assertEqual(len(__lowercase )			,	self.model_tester.num_hidden_layers )
							self.assertListEqual(
							    list(self_attentions[0].shape[-3:] )			,	[batch_size, seq_len, config.hidden_size]			,	)





					@slow
					def      lowercase_							(    self ):







						'''simple docstring'''




						for model_name in RWKV_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
							lowerCamelCase_							:		Optional[int]							       =							RwkvModel.from_pretrained(__lowercase )
							self.assertIsNotNone(__lowercase )


@unittest.skipIf(
    not is_torch_greater_or_equal_than_2_0       ,					reason="""See https://github.com/huggingface/transformers/pull/24204"""  )
@slow
class     __SCREAMING_SNAKE_CASE							(		unittest.TestCase  ):

					def      lowercase_							(    self ):







						'''simple docstring'''




						lowerCamelCase_							:		List[str]							       =							'RWKV/rwkv-4-169m-pile'
						lowerCamelCase_							:		str							       =							AutoTokenizer.from_pretrained(self.model_id )

					def      lowercase_							(    self ):







						'''simple docstring'''




						lowerCamelCase_							:		Optional[int]							       =							'Hello my name is Jasmine and I am a newbie to the'
						lowerCamelCase_							:		Tuple							       =							RwkvForCausalLM.from_pretrained(self.model_id ).to(__lowercase )

						lowerCamelCase_							:		int							       =							self.tokenizer('Hello my name is'			,	return_tensors='pt' ).input_ids.to(__lowercase )
						lowerCamelCase_							:		Tuple							       =							model.generate(__lowercase			,	max_new_tokens=10 )
						lowerCamelCase_							:		Union[str, Any]							       =							self.tokenizer.decode(output[0].tolist() )

						self.assertEqual(__lowercase			,	__lowercase )





					def      lowercase_							(    self ):







						'''simple docstring'''




						lowerCamelCase_							:		str							       =							'Hello my name is Jasmine and I am a newbie to the'

						lowerCamelCase_							:		str							       =							self.tokenizer('Hello my name is'			,	return_tensors='pt' ).input_ids.to(__lowercase )
						lowerCamelCase_							:		Tuple							       =							RwkvForCausalLM.from_pretrained(self.model_id			,	torch_dtype=torch.bfloataa ).to(__lowercase )

						lowerCamelCase_							:		List[str]							       =							model.generate(__lowercase			,	max_new_tokens=10 )
						lowerCamelCase_							:		Dict							       =							self.tokenizer.decode(output[0].tolist() )

						self.assertEqual(__lowercase			,	__lowercase )






from collections import OrderedDict
from typing import Any, Mapping, Optional

from ... import PreTrainedTokenizer
from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig, OnnxSeqaSeqConfigWithPast
from ...onnx.utils import compute_effective_axis_dimension
from ...utils import TensorType, is_torch_available, logging


UpperCamelCase__		=						logging.get_logger(__name__)

UpperCamelCase__		=						{
    'facebook/m2m100_418M': 'https://huggingface.co/facebook/m2m100_418M/resolve/main/config.json',
    # See all M2M100 models at https://huggingface.co/models?filter=m2m_100
}


class     __SCREAMING_SNAKE_CASE							(		lowerCamelCase  ):
					_lowerCamelCase		  =			"""m2m_100"""
					_lowerCamelCase		  =			["""past_key_values"""]
					_lowerCamelCase		  =			{"""num_attention_heads""": """encoder_attention_heads""", """hidden_size""": """d_model"""}

					def __init__(    self			,	__lowercase=128_112			,	__lowercase=1_024			,	__lowercase=12			,	__lowercase=4_096			,	__lowercase=16			,	__lowercase=12			,	__lowercase=4_096			,	__lowercase=16			,	__lowercase=0.05			,	__lowercase=0.05			,	__lowercase=True			,	__lowercase=True			,	__lowercase="relu"			,	__lowercase=1_024			,	__lowercase=0.1			,	__lowercase=0.1			,	__lowercase=0.0			,	__lowercase=0.02			,	__lowercase=2			,	__lowercase=True			,	__lowercase=1			,	__lowercase=0			,	__lowercase=2			,	**__lowercase			,	):







						'''simple docstring'''




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

						super().__init__(
						    pad_token_id=__lowercase			,	bos_token_id=__lowercase			,	eos_token_id=__lowercase			,	is_encoder_decoder=__lowercase			,	decoder_start_token_id=__lowercase			,	**__lowercase			,	)


class     __SCREAMING_SNAKE_CASE							(		lowerCamelCase  ):

					@property
					def      lowercase_							(    self ):







						'''simple docstring'''




						lowerCamelCase_							:		Any							       =							OrderedDict(
						    [
						        ('input_ids', {0: 'batch', 1: 'encoder_sequence'}),
						        ('attention_mask', {0: 'batch', 1: 'encoder_sequence'}),
						    ] )

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

						if self.use_past:
							self.fill_with_past_key_values_(__lowercase			,	direction='inputs' )
						return common_inputs

					def      lowercase_							(    self			,	__lowercase			,	__lowercase = -1			,	__lowercase = -1			,	__lowercase = False			,	__lowercase = None			,	):







						'''simple docstring'''




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

					def      lowercase_							(    self			,	__lowercase			,	__lowercase = -1			,	__lowercase = -1			,	__lowercase = False			,	__lowercase = None			,	):







						'''simple docstring'''




						lowerCamelCase_							:		Optional[Any]							       =							self._generate_dummy_inputs_for_sequence_classification_and_question_answering(
						    __lowercase			,	__lowercase			,	__lowercase			,	__lowercase			,	__lowercase )

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

							lowerCamelCase_							:		List[Any]							       =							torch.cat(
							    [common_inputs['decoder_attention_mask'], torch.ones(__lowercase			,	__lowercase )]			,	dim=1 )

							lowerCamelCase_							:		Tuple							       =							[]
							# If the number of encoder and decoder layers are present in the model configuration, both are considered
							lowerCamelCase_       ,      lowerCamelCase_							:		int							       =							self.num_layers
							lowerCamelCase_							:		Optional[int]							       =							min(__lowercase			,	__lowercase )
							lowerCamelCase_							:		int							       =							max(__lowercase			,	__lowercase ) - min_num_layers
							lowerCamelCase_							:		Union[str, Any]							       =							'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.
							lowerCamelCase_							:		Optional[int]							       =							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





					_lowerCamelCase		  =			_generate_dummy_inputs_for_default_and_seqaseq_lm
