






import unittest

from parameterized import parameterized

from transformers import LlamaConfig, is_torch_available, set_seed
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, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
							import torch

							from transformers import LlamaForCausalLM, LlamaForSequenceClassification, LlamaModel, LlamaTokenizer


class   __SCREAMING_SNAKE_CASE:
							def __init__(     self:      int       ,	UpperCamelCase:      int       ,	UpperCamelCase:      Union[str, Any]=13       ,	UpperCamelCase:      List[str]=7       ,	UpperCamelCase:      Dict=True       ,	UpperCamelCase:      Dict=True       ,	UpperCamelCase:      int=False       ,	UpperCamelCase:      Union[str, Any]=True       ,	UpperCamelCase:      int=99       ,	UpperCamelCase:      Optional[Any]=32       ,	UpperCamelCase:      int=5       ,	UpperCamelCase:      Tuple=4       ,	UpperCamelCase:      Any=37       ,	UpperCamelCase:      Optional[Any]="gelu"       ,	UpperCamelCase:      int=0.1       ,	UpperCamelCase:      Union[str, Any]=0.1       ,	UpperCamelCase:      Optional[int]=5_12       ,	UpperCamelCase:      Tuple=16       ,	UpperCamelCase:      List[str]=2       ,	UpperCamelCase:      Optional[int]=0.02       ,	UpperCamelCase:      List[str]=3       ,	UpperCamelCase:      List[str]=4       ,	UpperCamelCase:      List[str]=None       ,	)		->		Any:
											snake_case__									=     parent
											snake_case__									=     batch_size
											snake_case__									=     seq_length
											snake_case__									=     is_training
											snake_case__									=     use_input_mask
											snake_case__									=     use_token_type_ids
											snake_case__									=     use_labels
											snake_case__									=     vocab_size
											snake_case__									=     hidden_size
											snake_case__									=     num_hidden_layers
											snake_case__									=     num_attention_heads
											snake_case__									=     intermediate_size
											snake_case__									=     hidden_act
											snake_case__									=     hidden_dropout_prob
											snake_case__									=     attention_probs_dropout_prob
											snake_case__									=     max_position_embeddings
											snake_case__									=     type_vocab_size
											snake_case__									=     type_sequence_label_size
											snake_case__									=     initializer_range
											snake_case__									=     num_labels
											snake_case__									=     num_choices
											snake_case__									=     scope
							def lowerCAmelCase_ (     self:      List[Any]						)		->		str:
											snake_case__									=     ids_tensor([self.batch_size, self.seq_length]       ,	self.vocab_size						)

											snake_case__									=     None
											if self.use_input_mask:
															snake_case__									=     random_attention_mask([self.batch_size, self.seq_length]						)

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

											snake_case__									=     None
											snake_case__									=     None
											snake_case__									=     None
											if self.use_labels:
															snake_case__									=     ids_tensor([self.batch_size]       ,	self.type_sequence_label_size						)
															snake_case__									=     ids_tensor([self.batch_size, self.seq_length]       ,	self.num_labels						)
															snake_case__									=     ids_tensor([self.batch_size]       ,	self.num_choices						)

											snake_case__									=     self.get_config()

											return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels
							def lowerCAmelCase_ (     self:      int						)		->		Dict:
											return LlamaConfig(
											    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       ,	is_decoder=UpperCamelCase       ,	initializer_range=self.initializer_range       ,	)
							def lowerCAmelCase_ (     self:      Dict       ,	UpperCamelCase:      Tuple       ,	UpperCamelCase:      Tuple       ,	UpperCamelCase:      List[str]       ,	UpperCamelCase:      int       ,	UpperCamelCase:      str       ,	UpperCamelCase:      List[Any]       ,	UpperCamelCase:      int						)		->		Tuple:
											snake_case__									=     LlamaModel(config=UpperCamelCase						)
											model.to(UpperCamelCase						)
											model.eval()
											snake_case__									=     model(UpperCamelCase       ,	attention_mask=UpperCamelCase						)
											snake_case__									=     model(UpperCamelCase						)
											self.parent.assertEqual(result.last_hidden_state.shape       ,	(self.batch_size, self.seq_length, self.hidden_size)						)
							def lowerCAmelCase_ (     self:      int       ,	UpperCamelCase:      str       ,	UpperCamelCase:      Union[str, Any]       ,	UpperCamelCase:      Optional[int]       ,	UpperCamelCase:      Union[str, Any]       ,	UpperCamelCase:      List[str]       ,	UpperCamelCase:      Tuple       ,	UpperCamelCase:      Any       ,	UpperCamelCase:      int       ,	UpperCamelCase:      int       ,	)		->		Dict:
											snake_case__									=     True
											snake_case__									=     LlamaModel(UpperCamelCase						)
											model.to(UpperCamelCase						)
											model.eval()
											snake_case__									=     model(
											    UpperCamelCase       ,	attention_mask=UpperCamelCase       ,	encoder_hidden_states=UpperCamelCase       ,	encoder_attention_mask=UpperCamelCase       ,	)
											snake_case__									=     model(
											    UpperCamelCase       ,	attention_mask=UpperCamelCase       ,	encoder_hidden_states=UpperCamelCase       ,	)
											snake_case__									=     model(UpperCamelCase       ,	attention_mask=UpperCamelCase						)
											self.parent.assertEqual(result.last_hidden_state.shape       ,	(self.batch_size, self.seq_length, self.hidden_size)						)
							def lowerCAmelCase_ (     self:      str       ,	UpperCamelCase:      str       ,	UpperCamelCase:      List[str]       ,	UpperCamelCase:      Optional[int]       ,	UpperCamelCase:      Union[str, Any]       ,	UpperCamelCase:      Any       ,	UpperCamelCase:      Any       ,	UpperCamelCase:      str       ,	UpperCamelCase:      List[str]       ,	UpperCamelCase:      List[str]       ,	)		->		List[str]:
											snake_case__									=     LlamaForCausalLM(config=UpperCamelCase						)
											model.to(UpperCamelCase						)
											model.eval()
											snake_case__									=     model(UpperCamelCase       ,	attention_mask=UpperCamelCase       ,	labels=UpperCamelCase						)
											self.parent.assertEqual(result.logits.shape       ,	(self.batch_size, self.seq_length, self.vocab_size)						)
							def lowerCAmelCase_ (     self:      List[Any]       ,	UpperCamelCase:      List[Any]       ,	UpperCamelCase:      Any       ,	UpperCamelCase:      Union[str, Any]       ,	UpperCamelCase:      Union[str, Any]       ,	UpperCamelCase:      Any       ,	UpperCamelCase:      str       ,	UpperCamelCase:      Optional[Any]       ,	UpperCamelCase:      int       ,	UpperCamelCase:      Optional[Any]       ,	)		->		Dict:
											snake_case__									=     True
											snake_case__									=     True
											snake_case__									=     LlamaForCausalLM(config=UpperCamelCase						)
											model.to(UpperCamelCase						)
											model.eval()

											# first forward pass
											snake_case__									=     model(
											    UpperCamelCase       ,	attention_mask=UpperCamelCase       ,	encoder_hidden_states=UpperCamelCase       ,	encoder_attention_mask=UpperCamelCase       ,	use_cache=UpperCamelCase       ,	)
											snake_case__									=     outputs.past_key_values

											# create hypothetical multiple next token and extent to next_input_ids
											snake_case__									=     ids_tensor((self.batch_size, 3)       ,	config.vocab_size						)
											snake_case__									=     ids_tensor((self.batch_size, 3)       ,	vocab_size=2						)

											# append to next input_ids and
											snake_case__									=     torch.cat([input_ids, next_tokens]       ,	dim=-1						)
											snake_case__									=     torch.cat([input_mask, next_mask]       ,	dim=-1						)

											snake_case__									=     model(
											    UpperCamelCase       ,	attention_mask=UpperCamelCase       ,	encoder_hidden_states=UpperCamelCase       ,	encoder_attention_mask=UpperCamelCase       ,	output_hidden_states=UpperCamelCase       ,	)['hidden_states'][0]
											snake_case__									=     model(
											    UpperCamelCase       ,	attention_mask=UpperCamelCase       ,	encoder_hidden_states=UpperCamelCase       ,	encoder_attention_mask=UpperCamelCase       ,	past_key_values=UpperCamelCase       ,	output_hidden_states=UpperCamelCase       ,	)['hidden_states'][0]

											# select random slice
											snake_case__									=     ids_tensor((1,)       ,	output_from_past.shape[-1]						).item()
											snake_case__									=     output_from_no_past[:, -3:, random_slice_idx].detach()
											snake_case__									=     output_from_past[:, :, random_slice_idx].detach()

											self.parent.assertTrue(output_from_past_slice.shape[1] == next_tokens.shape[1]						)

											# test that outputs are equal for slice
											self.parent.assertTrue(torch.allclose(UpperCamelCase       ,	UpperCamelCase       ,	atol=1e-3						)						)


							def lowerCAmelCase_ (     self:      str						)		->		int:
											snake_case__									=     self.prepare_config_and_inputs()
											(
											    (
											    snake_case__
											)							,						(
											    snake_case__
											)							,						(
											    snake_case__
											)							,						(
											    snake_case__
											)							,						(
											    snake_case__
											)							,						(
											    snake_case__
											)							,						(
											    snake_case__
											)							,						
											)									=     config_and_inputs
											snake_case__									=     {'input_ids': input_ids, 'attention_mask': input_mask}
											return config, inputs_dict


@require_torch
class   __SCREAMING_SNAKE_CASE(	a_    ,  a_    ,  a_    ,  unittest.TestCase	):
							_UpperCAmelCase     =       (LlamaModel, LlamaForCausalLM, LlamaForSequenceClassification) if is_torch_available() else ()
							_UpperCAmelCase     =       (LlamaForCausalLM,) if is_torch_available() else ()
							_UpperCAmelCase     =       (
							    {
							        "feature-extraction": LlamaModel,
							        "text-classification": LlamaForSequenceClassification,
							        "text-generation": LlamaForCausalLM,
							        "zero-shot": LlamaForSequenceClassification,
							    }
							    if is_torch_available()
							    else {}
							)
							_UpperCAmelCase     =       False
							_UpperCAmelCase     =       False
							def lowerCAmelCase_ (     self:      int						)		->		Optional[int]:
											snake_case__									=     LlamaModelTester(self						)
											snake_case__									=     ConfigTester(self       ,	config_class=UpperCamelCase       ,	hidden_size=37						)
							def lowerCAmelCase_ (     self:      Dict						)		->		Any:
											self.config_tester.run_common_tests()
							def lowerCAmelCase_ (     self:      Dict						)		->		str:
											snake_case__									=     self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_model(*UpperCamelCase						)
							def lowerCAmelCase_ (     self:      List[str]						)		->		Optional[int]:
											snake_case__									=     self.model_tester.prepare_config_and_inputs()
											for type in ["absolute", "relative_key", "relative_key_query"]:
															snake_case__									=     type
															self.model_tester.create_and_check_model(*UpperCamelCase						)
							def lowerCAmelCase_ (     self:      List[Any]						)		->		List[Any]:
											snake_case__							,						snake_case__									=     self.model_tester.prepare_config_and_inputs_for_common()
											snake_case__									=     3
											snake_case__									=     input_dict['input_ids']
											snake_case__									=     input_ids.ne(1						).to(UpperCamelCase						)
											snake_case__									=     ids_tensor([self.model_tester.batch_size]       ,	self.model_tester.type_sequence_label_size						)
											snake_case__									=     LlamaForSequenceClassification(UpperCamelCase						)
											model.to(UpperCamelCase						)
											model.eval()
											snake_case__									=     model(UpperCamelCase       ,	attention_mask=UpperCamelCase       ,	labels=UpperCamelCase						)
											self.assertEqual(result.logits.shape       ,	(self.model_tester.batch_size, self.model_tester.num_labels)						)
							def lowerCAmelCase_ (     self:      Optional[Any]						)		->		List[str]:
											snake_case__							,						snake_case__									=     self.model_tester.prepare_config_and_inputs_for_common()
											snake_case__									=     3
											snake_case__									=     'single_label_classification'
											snake_case__									=     input_dict['input_ids']
											snake_case__									=     input_ids.ne(1						).to(UpperCamelCase						)
											snake_case__									=     ids_tensor([self.model_tester.batch_size]       ,	self.model_tester.type_sequence_label_size						)
											snake_case__									=     LlamaForSequenceClassification(UpperCamelCase						)
											model.to(UpperCamelCase						)
											model.eval()
											snake_case__									=     model(UpperCamelCase       ,	attention_mask=UpperCamelCase       ,	labels=UpperCamelCase						)
											self.assertEqual(result.logits.shape       ,	(self.model_tester.batch_size, self.model_tester.num_labels)						)
							def lowerCAmelCase_ (     self:      List[str]						)		->		int:
											snake_case__							,						snake_case__									=     self.model_tester.prepare_config_and_inputs_for_common()
											snake_case__									=     3
											snake_case__									=     'multi_label_classification'
											snake_case__									=     input_dict['input_ids']
											snake_case__									=     input_ids.ne(1						).to(UpperCamelCase						)
											snake_case__									=     ids_tensor(
											    [self.model_tester.batch_size, config.num_labels]       ,	self.model_tester.type_sequence_label_size						).to(torch.float						)
											snake_case__									=     LlamaForSequenceClassification(UpperCamelCase						)
											model.to(UpperCamelCase						)
											model.eval()
											snake_case__									=     model(UpperCamelCase       ,	attention_mask=UpperCamelCase       ,	labels=UpperCamelCase						)
											self.assertEqual(result.logits.shape       ,	(self.model_tester.batch_size, self.model_tester.num_labels)						)
							@unittest.skip('LLaMA buffers include complex numbers, which breaks this test'						)
							def lowerCAmelCase_ (     self:      List[str]						)		->		List[Any]:
											pass


							@parameterized.expand([('linear',), ('dynamic',)]						)
							def lowerCAmelCase_ (     self:      Tuple       ,	UpperCamelCase:      List[str]						)		->		Any:
											snake_case__							,						snake_case__									=     self.model_tester.prepare_config_and_inputs_for_common()
											snake_case__									=     ids_tensor([1, 10]       ,	config.vocab_size						)
											snake_case__									=     ids_tensor([1, int(config.max_position_embeddings * 1.5						)]       ,	config.vocab_size						)

											set_seed(42						)  # Fixed seed at init time so the two models get the same random weights
											snake_case__									=     LlamaModel(UpperCamelCase						)
											original_model.to(UpperCamelCase						)
											original_model.eval()
											snake_case__									=     original_model(UpperCamelCase						).last_hidden_state
											snake_case__									=     original_model(UpperCamelCase						).last_hidden_state

											set_seed(42						)  # Fixed seed at init time so the two models get the same random weights
											snake_case__									=     {'type': scaling_type, 'factor': 10.0}
											snake_case__									=     LlamaModel(UpperCamelCase						)
											scaled_model.to(UpperCamelCase						)
											scaled_model.eval()
											snake_case__									=     scaled_model(UpperCamelCase						).last_hidden_state
											snake_case__									=     scaled_model(UpperCamelCase						).last_hidden_state

											# Dynamic scaling does not change the RoPE embeddings until it receives an input longer than the original
											# maximum sequence length, so the outputs for the short input should match.
											if scaling_type == "dynamic":
															self.assertTrue(torch.allclose(UpperCamelCase       ,	UpperCamelCase       ,	atol=1e-5						)						)
											else:
															self.assertFalse(torch.allclose(UpperCamelCase       ,	UpperCamelCase       ,	atol=1e-5						)						)

											# The output should be different for long inputs
											self.assertFalse(torch.allclose(UpperCamelCase       ,	UpperCamelCase       ,	atol=1e-5						)						)


@require_torch
class   __SCREAMING_SNAKE_CASE(	unittest.TestCase	):
							@unittest.skip('Logits are not exactly the same, once we fix the instabalities somehow, will update!'						)
							@slow
							def lowerCAmelCase_ (     self:      Tuple						)		->		str:
											snake_case__									=     [1, 3_06, 46_58, 2_78, 65_93, 3_10, 28_34, 3_38]
											snake_case__									=     LlamaForCausalLM.from_pretrained('meta-llama/Llama-2-7b-hf'       ,	device_map='auto'						)
											snake_case__									=     model(torch.tensor([input_ids]						)						)
											# Expected mean on dim = -1
											snake_case__									=     torch.tensor([[-6.6_550, -4.1_227, -4.9_859, -3.2_406, 0.8_262, -3.0_033, 1.2_964, -3.3_699]]						)
											torch.testing.assert_close(out.mean(-1						)       ,	UpperCamelCase       ,	atol=1e-2       ,	rtol=1e-2						)
											# slicing logits[0, 0, 0:30]
											# fmt: off
											snake_case__									=     torch.tensor([-12.8_281, -7.4_453, -0.4_639, -8.0_625, -7.2_500, -8.0_000, -6.4_883, -7.7_695, -7.8_438, -7.0_312, -6.2_188, -7.1_328, -1.8_496, 1.9_961, -8.6_250, -6.7_227, -12.8_281, -6.9_492, -7.0_742, -7.7_852, -7.5_820, -7.9_062, -6.9_375, -7.9_805, -8.3_438, -8.1_562, -8.0_469, -7.6_250, -7.7_422, -7.3_398,]						)
											# fmt: on
											torch.testing.assert_close(out[0, 0, :30]       ,	UpperCamelCase       ,	atol=1e-5       ,	rtol=1e-5						)
							@unittest.skip('Logits are not exactly the same, once we fix the instabalities somehow, will update!'						)
							@slow
							def lowerCAmelCase_ (     self:      int						)		->		str:
											snake_case__									=     [1, 3_06, 46_58, 2_78, 65_93, 3_10, 28_34, 3_38]
											snake_case__									=     LlamaForCausalLM.from_pretrained('meta-llama/Llama-2-13b-hf'       ,	device_map='auto'						)
											snake_case__									=     model(torch.tensor(UpperCamelCase						)						)
											# Expected mean on dim = -1
											snake_case__									=     torch.tensor([[-2.0_622, -1.2_794, -1.1_638, -0.9_788, -1.4_603, -1.0_238, -1.7_893, -1.4_411]]						)
											torch.testing.assert_close(out.mean(-1						)       ,	UpperCamelCase       ,	atol=1e-2       ,	rtol=1e-2						)
											# slicing logits[0, 0, 0:30]
											# fmt: off
											snake_case__									=     torch.tensor([-8.1_406, -8.0_547, 2.7_461, -1.2_344, -0.1_448, -1.8_262, -1.0_020, -1.8_154, -1.6_895, -1.8_516, -2.3_574, -0.9_277, 3.7_598, 6.5_742, -1.2_998, -0.1_177, -8.1_406, -2.9_688, -2.9_199, -3.1_699, -3.5_254, -2.3_555, -2.7_988, -3.4_141, -2.8_262, -4.5_195, -3.3_379, -3.3_164, -2.7_832, -3.0_273]						)
											# fmt: on
											torch.testing.assert_close(out[0, 0, :30]       ,	UpperCamelCase       ,	atol=1e-5       ,	rtol=1e-5						)
							@unittest.skip('Logits are not exactly the same, once we fix the instabalities somehow, will update!'						)
							@slow
							def lowerCAmelCase_ (     self:      Union[str, Any]						)		->		int:
											snake_case__									=     [1, 3_06, 46_58, 2_78, 65_93, 3_10, 28_34, 3_38]
											snake_case__									=     LlamaForCausalLM.from_pretrained('meta-llama/Llama-2-13b-chat-hf'       ,	device_map='auto'						)
											snake_case__									=     model(torch.tensor(UpperCamelCase						)						)
											# Expected mean on dim = -1
											snake_case__									=     torch.tensor([[-0.8_562, -1.8_520, -0.7_551, -0.4_162, -1.5_161, -1.2_038, -2.4_823, -2.3_254]]						)
											torch.testing.assert_close(out.mean(-1						)       ,	UpperCamelCase       ,	atol=1e-2       ,	rtol=1e-2						)
											# slicing logits[0, 0, 0:30]
											# fmt: off
											snake_case__									=     torch.tensor([-2.2_227, 4.8_828, 0.9_023, -0.4_578, -0.7_871, -0.1_033, -0.6_221, -0.5_786, -0.7_803, -1.0_674, -1.2_920, -0.1_570, 0.8_008, 2.0_723, -0.9_497, 0.2_771, -2.2_227, -0.7_612, -1.4_346, -1.2_061, -1.6_426, -0.3_000, -0.7_139, -1.1_934, -1.8_691, -1.6_973, -1.5_947, -1.2_705, -0.3_523, -0.5_513]						)
											# fmt: on
											torch.testing.assert_close(out.mean(-1						)       ,	UpperCamelCase       ,	atol=1e-2       ,	rtol=1e-2						)
							@unittest.skip(
							    'Logits are not exactly the same, once we fix the instabalities somehow, will update! Also it is gonna be a `too_slow` test'						)
							@slow
							def lowerCAmelCase_ (     self:      Optional[int]						)		->		Tuple:
											snake_case__									=     [1, 3_06, 46_58, 2_78, 65_93, 3_10, 28_34, 3_38]
											snake_case__									=     LlamaForCausalLM.from_pretrained('meta-llama/Llama-2-70b-hf'       ,	device_map='auto'						)
											snake_case__									=     model(torch.tensor(UpperCamelCase						)						)

											snake_case__									=     torch.tensor(
											    [[-4.2_327, -3.3_360, -4.6_665, -4.7_631, -1.8_180, -3.4_170, -1.4_211, -3.1_810]]       ,	dtype=torch.floataa						)
											torch.testing.assert_close(out.mean(-1						)       ,	UpperCamelCase       ,	atol=1e-2       ,	rtol=1e-2						)
											# fmt: off
											snake_case__									=     torch.tensor([-9.4_922, -3.9_551, 1.7_998, -5.6_758, -5.1_055, -5.8_984, -4.8_320, -6.8_086, -6.5_391, -5.6_172, -5.5_820, -5.5_352, 1.7_881, 3.6_289, -6.5_117, -3.4_785, -9.5_000, -6.0_352, -6.8_125, -6.0_195, -6.6_836, -5.4_727, -6.2_812, -6.0_391, -7.3_398, -7.4_297, -7.4_844, -6.5_820, -5.8_789, -5.5_312]						)
											# fmt: on
											torch.testing.assert_close(out[0, 0, :30]       ,	UpperCamelCase       ,	atol=1e-5       ,	rtol=1e-5						)


							@unittest.skip('Model is curently gated'						)
							@slow
							def lowerCAmelCase_ (     self:      int						)		->		Dict:
											snake_case__									=     'Simply put, the theory of relativity states that 1) the laws of physics are the same everywhere in the universe and 2) the passage of time and the length of objects can vary depending on the observer\'s frame of reference.\n\nThe first part of the theory, that the laws of physics are the same everywhere, is known as the "princi'
											snake_case__									=     'Simply put, the theory of relativity states that '
											snake_case__									=     LlamaTokenizer.from_pretrained('meta-llama/Llama-2-13b-chat-hf'						)
											snake_case__									=     tokenizer.encode(UpperCamelCase       ,	return_tensors='pt'						)
											snake_case__									=     LlamaForCausalLM.from_pretrained(
											    'meta-llama/Llama-2-13b-chat-hf'       ,	device_map='sequential'       ,	use_safetensors=UpperCamelCase						)

											# greedy generation outputs
											snake_case__									=     model.generate(UpperCamelCase       ,	max_new_tokens=64       ,	top_p=UpperCamelCase       ,	temperature=1       ,	do_sample=UpperCamelCase						)
											snake_case__									=     tokenizer.decode(generated_ids[0]       ,	skip_special_tokens=UpperCamelCase						)
											self.assertEqual(UpperCamelCase       ,	UpperCamelCase						)












from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


__UpperCamelCase					:		Any	  =						logging.get_logger(__name__)

__UpperCamelCase					:		int	  =						{
    """junnyu/roformer_chinese_small""": """https://huggingface.co/junnyu/roformer_chinese_small/resolve/main/config.json""",
    """junnyu/roformer_chinese_base""": """https://huggingface.co/junnyu/roformer_chinese_base/resolve/main/config.json""",
    """junnyu/roformer_chinese_char_small""": (
        """https://huggingface.co/junnyu/roformer_chinese_char_small/resolve/main/config.json"""
    ),
    """junnyu/roformer_chinese_char_base""": (
        """https://huggingface.co/junnyu/roformer_chinese_char_base/resolve/main/config.json"""
    ),
    """junnyu/roformer_small_discriminator""": (
        """https://huggingface.co/junnyu/roformer_small_discriminator/resolve/main/config.json"""
    ),
    """junnyu/roformer_small_generator""": (
        """https://huggingface.co/junnyu/roformer_small_generator/resolve/main/config.json"""
    ),
    # See all RoFormer models at https://huggingface.co/models?filter=roformer
}


class   __SCREAMING_SNAKE_CASE(	a_	):
							_UpperCAmelCase     =       "roformer"
							def __init__(     self:      Tuple       ,	UpperCamelCase:      Optional[Any]=5_00_00       ,	UpperCamelCase:      str=None       ,	UpperCamelCase:      Any=7_68       ,	UpperCamelCase:      Dict=12       ,	UpperCamelCase:      List[Any]=12       ,	UpperCamelCase:      List[str]=30_72       ,	UpperCamelCase:      int="gelu"       ,	UpperCamelCase:      str=0.1       ,	UpperCamelCase:      Union[str, Any]=0.1       ,	UpperCamelCase:      Any=15_36       ,	UpperCamelCase:      Dict=2       ,	UpperCamelCase:      Dict=0.02       ,	UpperCamelCase:      List[str]=1e-12       ,	UpperCamelCase:      int=0       ,	UpperCamelCase:      Any=False       ,	UpperCamelCase:      int=True       ,	**UpperCamelCase:      List[Any]       ,	)		->		List[str]:
											super().__init__(pad_token_id=UpperCamelCase       ,	**UpperCamelCase						)

											snake_case__									=     vocab_size
											snake_case__									=     hidden_size if embedding_size is None else embedding_size
											snake_case__									=     hidden_size
											snake_case__									=     num_hidden_layers
											snake_case__									=     num_attention_heads
											snake_case__									=     hidden_act
											snake_case__									=     intermediate_size
											snake_case__									=     hidden_dropout_prob
											snake_case__									=     attention_probs_dropout_prob
											snake_case__									=     max_position_embeddings
											snake_case__									=     type_vocab_size
											snake_case__									=     initializer_range
											snake_case__									=     layer_norm_eps
											snake_case__									=     rotary_value
											snake_case__									=     use_cache


class   __SCREAMING_SNAKE_CASE(	a_	):
							@property
							def lowerCAmelCase_ (     self:      Any						)		->		Mapping[str, Mapping[int, str]]:
											if self.task == "multiple-choice":
															snake_case__									=     {0: 'batch', 1: 'choice', 2: 'sequence'}
											else:
															snake_case__									=     {0: 'batch', 1: 'sequence'}
											snake_case__									=     {0: 'batch', 1: 'sequence'}
											return OrderedDict(
											    [
											        ('input_ids', dynamic_axis),
											        ('attention_mask', dynamic_axis),
											        ('token_type_ids', dynamic_axis),
											    ]						)




