


"""simple docstring"""



from __future__ import annotations

import unittest

from transformers import DebertaVaConfig, 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 (
		    TFDebertaVaForMaskedLM,
		    TFDebertaVaForQuestionAnswering,
		    TFDebertaVaForSequenceClassification,
		    TFDebertaVaForTokenClassification,
		    TFDebertaVaModel,
		)







class    __a						:







				def __init__( self      ,	UpperCAmelCase      ,	UpperCAmelCase=13      ,	UpperCAmelCase=7      ,	UpperCAmelCase=True      ,	UpperCAmelCase=True      ,	UpperCAmelCase=True      ,	UpperCAmelCase=True      ,	UpperCAmelCase=99      ,	UpperCAmelCase=32      ,	UpperCAmelCase=2      ,	UpperCAmelCase=4      ,	UpperCAmelCase=37      ,	UpperCAmelCase="gelu"      ,	UpperCAmelCase=0.1      ,	UpperCAmelCase=0.1      ,	UpperCAmelCase=512      ,	UpperCAmelCase=16      ,	UpperCAmelCase=2      ,	UpperCAmelCase=0.0_2      ,	UpperCAmelCase=False      ,	UpperCAmelCase=True      ,	UpperCAmelCase="None"      ,	UpperCAmelCase=3      ,	UpperCAmelCase=4      ,	UpperCAmelCase=None      ,	):

					'''simple docstring'''






					lowerCAmelCase_      							=			parent
					lowerCAmelCase_      							=			batch_size
					lowerCAmelCase_      							=			seq_length
					lowerCAmelCase_      							=			is_training
					lowerCAmelCase_      							=			use_input_mask
					lowerCAmelCase_      							=			use_token_type_ids
					lowerCAmelCase_      							=			use_labels
					lowerCAmelCase_      							=			vocab_size
					lowerCAmelCase_      							=			hidden_size
					lowerCAmelCase_      							=			num_hidden_layers
					lowerCAmelCase_      							=			num_attention_heads
					lowerCAmelCase_      							=			intermediate_size
					lowerCAmelCase_      							=			hidden_act
					lowerCAmelCase_      							=			hidden_dropout_prob
					lowerCAmelCase_      							=			attention_probs_dropout_prob
					lowerCAmelCase_      							=			max_position_embeddings
					lowerCAmelCase_      							=			type_vocab_size
					lowerCAmelCase_      							=			type_sequence_label_size
					lowerCAmelCase_      							=			initializer_range
					lowerCAmelCase_      							=			num_labels
					lowerCAmelCase_      							=			num_choices
					lowerCAmelCase_      							=			relative_attention
					lowerCAmelCase_      							=			position_biased_input
					lowerCAmelCase_      							=			pos_att_type
					lowerCAmelCase_      							=			scope







				def      lowerCamelCase_     ( self   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			ids_tensor([self.batch_size, self.seq_length]      ,	self.vocab_size   )

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

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

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

					lowerCAmelCase_      							=			DebertaVaConfig(
					    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      ,	relative_attention=self.relative_attention      ,	position_biased_input=self.position_biased_input      ,	initializer_range=self.initializer_range      ,	return_dict=UpperCAmelCase      ,	)

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







				def      lowerCamelCase_     ( self      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			TFDebertaVaModel(config=UpperCAmelCase   )
					lowerCAmelCase_      							=			{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}

					lowerCAmelCase_      							=			[input_ids, input_mask]
					lowerCAmelCase_      							=			model(UpperCAmelCase   )

					lowerCAmelCase_      							=			model(UpperCAmelCase   )

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







				def      lowerCamelCase_     ( self      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			TFDebertaVaForMaskedLM(config=UpperCAmelCase   )
					lowerCAmelCase_      							=			{
					    '''input_ids''': input_ids,
					    '''attention_mask''': input_mask,
					    '''token_type_ids''': token_type_ids,
					}
					lowerCAmelCase_      							=			model(UpperCAmelCase   )
					self.parent.assertEqual(result.logits.shape      ,	(self.batch_size, self.seq_length, self.vocab_size)   )







				def      lowerCamelCase_     ( self      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			self.num_labels
					lowerCAmelCase_      							=			TFDebertaVaForSequenceClassification(config=UpperCAmelCase   )
					lowerCAmelCase_      							=			{
					    '''input_ids''': input_ids,
					    '''attention_mask''': input_mask,
					    '''token_type_ids''': token_type_ids,
					}

					lowerCAmelCase_      							=			model(UpperCAmelCase   )
					self.parent.assertEqual(result.logits.shape      ,	(self.batch_size, self.num_labels)   )







				def      lowerCamelCase_     ( self      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			self.num_labels
					lowerCAmelCase_      							=			TFDebertaVaForTokenClassification(config=UpperCAmelCase   )
					lowerCAmelCase_      							=			{
					    '''input_ids''': input_ids,
					    '''attention_mask''': input_mask,
					    '''token_type_ids''': token_type_ids,
					}
					lowerCAmelCase_      							=			model(UpperCAmelCase   )
					self.parent.assertEqual(result.logits.shape      ,	(self.batch_size, self.seq_length, self.num_labels)   )







				def      lowerCamelCase_     ( self      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase      ,	UpperCAmelCase   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			TFDebertaVaForQuestionAnswering(config=UpperCAmelCase   )
					lowerCAmelCase_      							=			{
					    '''input_ids''': input_ids,
					    '''attention_mask''': input_mask,
					    '''token_type_ids''': token_type_ids,
					}

					lowerCAmelCase_      							=			model(UpperCAmelCase   )
					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      lowerCamelCase_     ( self   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			self.prepare_config_and_inputs()
					(
					    (
					    lowerCAmelCase_
					)							,	(
					    lowerCAmelCase_
					)							,	(
					    lowerCAmelCase_
					)							,	(
					    lowerCAmelCase_
					)							,	(
					    lowerCAmelCase_
					)							,	(
					    lowerCAmelCase_
					)							,	(
					    lowerCAmelCase_
					)							,	
					)      							=			config_and_inputs
					lowerCAmelCase_      							=			{'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
					return config, inputs_dict







@require_tf
class    __a						( __snake_case					,			__snake_case					,			unittest.TestCase							):
				lowerCamelCase     :       Any			       =(
				    (
				        TFDebertaVaModel,
				        TFDebertaVaForMaskedLM,
				        TFDebertaVaForQuestionAnswering,
				        TFDebertaVaForSequenceClassification,
				        TFDebertaVaForTokenClassification,
				    )
				    if is_tf_available()
				    else ()
				)
				lowerCamelCase     :       Optional[int]			       =(
				    {
				        'feature-extraction': TFDebertaVaModel,
				        'fill-mask': TFDebertaVaForMaskedLM,
				        'question-answering': TFDebertaVaForQuestionAnswering,
				        'text-classification': TFDebertaVaForSequenceClassification,
				        'token-classification': TFDebertaVaForTokenClassification,
				        'zero-shot': TFDebertaVaForSequenceClassification,
				    }
				    if is_tf_available()
				    else {}
				)

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







				def      lowerCamelCase_     ( self   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			TFDebertaVaModelTester(self   )
					lowerCAmelCase_      							=			ConfigTester(self      ,	config_class=UpperCAmelCase      ,	hidden_size=37   )







				def      lowerCamelCase_     ( self   ):

					'''simple docstring'''






					self.config_tester.run_common_tests()







				def      lowerCamelCase_     ( self   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_model(*UpperCAmelCase   )







				def      lowerCamelCase_     ( self   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_masked_lm(*UpperCAmelCase   )







				def      lowerCamelCase_     ( self   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_question_answering(*UpperCAmelCase   )







				def      lowerCamelCase_     ( self   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_sequence_classification(*UpperCAmelCase   )







				def      lowerCamelCase_     ( self   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_token_classification(*UpperCAmelCase   )







				@slow
				def      lowerCamelCase_     ( self   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			TFDebertaVaModel.from_pretrained('''kamalkraj/deberta-v2-xlarge'''   )
					self.assertIsNotNone(UpperCAmelCase   )







@require_tf
class    __a						( unittest.TestCase							):







				@unittest.skip(reason='''Model not available yet'''   )
				def      lowerCamelCase_     ( self   ):

					'''simple docstring'''






					pass







				@slow
				def      lowerCamelCase_     ( self   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			TFDebertaVaModel.from_pretrained('''kamalkraj/deberta-v2-xlarge'''   )
					lowerCAmelCase_      							=			tf.constant([[0, 3_1414, 232, 328, 740, 1140, 1_2695, 69, 4_6078, 1588, 2]]   )
					lowerCAmelCase_      							=			tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]   )
					lowerCAmelCase_      							=			model(UpperCAmelCase      ,	attention_mask=UpperCAmelCase   )[0]

					lowerCAmelCase_      							=			tf.constant(
					    [[[0.2_3_5_6, 0.1_9_4_8, 0.0_3_6_9], [-0.1_0_6_3, 0.3_5_8_6, -0.5_1_5_2], [-0.6_3_9_9, -0.0_2_5_9, -0.2_5_2_5]]]   )
					tf.debugging.assert_near(output[:, 1:4, 1:4]      ,	UpperCAmelCase      ,	atol=1E-4   )



"""simple docstring"""



from ...configuration_utils import PretrainedConfig
from ...utils import logging


lowercase_							=							logging.get_logger(__name__)

lowercase_							=							{
    's-JoL/Open-Llama-V1': 'https://huggingface.co/s-JoL/Open-Llama-V1/blob/main/config.json',
}







class    __a						( __snake_case							):
				lowerCamelCase     :       Union[str, Any]			       ='open-llama'







				def __init__( self      ,	UpperCAmelCase=10_0000      ,	UpperCAmelCase=4096      ,	UpperCAmelCase=1_1008      ,	UpperCAmelCase=32      ,	UpperCAmelCase=32      ,	UpperCAmelCase="silu"      ,	UpperCAmelCase=2048      ,	UpperCAmelCase=0.0_2      ,	UpperCAmelCase=1E-6      ,	UpperCAmelCase=True      ,	UpperCAmelCase=0      ,	UpperCAmelCase=1      ,	UpperCAmelCase=2      ,	UpperCAmelCase=False      ,	UpperCAmelCase=True      ,	UpperCAmelCase=0.1      ,	UpperCAmelCase=0.1      ,	UpperCAmelCase=True      ,	UpperCAmelCase=True      ,	UpperCAmelCase=None      ,	**UpperCAmelCase      ,	):

					'''simple docstring'''






					lowerCAmelCase_      							=			vocab_size
					lowerCAmelCase_      							=			max_position_embeddings
					lowerCAmelCase_      							=			hidden_size
					lowerCAmelCase_      							=			intermediate_size
					lowerCAmelCase_      							=			num_hidden_layers
					lowerCAmelCase_      							=			num_attention_heads
					lowerCAmelCase_      							=			hidden_act
					lowerCAmelCase_      							=			initializer_range
					lowerCAmelCase_      							=			rms_norm_eps
					lowerCAmelCase_      							=			use_cache
					lowerCAmelCase_      							=			kwargs.pop(
					    '''use_memorry_efficient_attention'''      ,	UpperCAmelCase   )
					lowerCAmelCase_      							=			hidden_dropout_prob
					lowerCAmelCase_      							=			attention_dropout_prob
					lowerCAmelCase_      							=			use_stable_embedding
					lowerCAmelCase_      							=			shared_input_output_embedding
					lowerCAmelCase_      							=			rope_scaling
					self._rope_scaling_validation()

					super().__init__(
					    pad_token_id=UpperCAmelCase      ,	bos_token_id=UpperCAmelCase      ,	eos_token_id=UpperCAmelCase      ,	tie_word_embeddings=UpperCAmelCase      ,	**UpperCAmelCase      ,	)







				def      lowerCamelCase_     ( self   ):

					'''simple docstring'''






					if self.rope_scaling is None:
						return

					if not isinstance(self.rope_scaling      ,	UpperCAmelCase   ) or len(self.rope_scaling   ) != 2:
						raise ValueError(
						    '''`rope_scaling` must be a dictionary with with two fields, `name` and `factor`, '''
						    F"""got {self.rope_scaling}"""   )
					lowerCAmelCase_      							=			self.rope_scaling.get('''type'''      ,	UpperCAmelCase   )
					lowerCAmelCase_      							=			self.rope_scaling.get('''factor'''      ,	UpperCAmelCase   )
					if rope_scaling_type is None or rope_scaling_type not in ["linear", "dynamic"]:
						raise ValueError(
						    F"""`rope_scaling`'s name field must be one of ['linear', 'dynamic'], got {rope_scaling_type}"""   )
					if rope_scaling_factor is None or not isinstance(UpperCAmelCase      ,	UpperCAmelCase   ) or rope_scaling_factor <= 1.0:
						raise ValueError(F"""`rope_scaling`'s factor field must be an float > 1, got {rope_scaling_factor}"""   )