




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


UpperCamelCase__					    =    logging.get_logger(__name__)

UpperCamelCase__					    =    {
    """s-JoL/Open-Llama-V1""": """https://huggingface.co/s-JoL/Open-Llama-V1/blob/main/config.json""",
}
class     a__					(      snake_case__   ):
						_a							:					Tuple      =					"""open-llama"""






						def __init__(     self	,    _A=1_0_0_0_0_0	,    _A=4_0_9_6	,    _A=1_1_0_0_8	,    _A=3_2	,    _A=3_2	,    _A="silu"	,    _A=2_0_4_8	,    _A=0.02	,    _A=1E-6	,    _A=True	,    _A=0	,    _A=1	,    _A=2	,    _A=False	,    _A=True	,    _A=0.1	,    _A=0.1	,    _A=True	,    _A=True	,    _A=None	,    **_A	,    ):




											"""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"	,    _A    )
											__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=_A	,    bos_token_id=_A	,    eos_token_id=_A	,    tie_word_embeddings=_A	,    **_A	,    )






						def        __SCREAMING_SNAKE_CASE(     self    ):




											"""simple docstring"""



											if self.rope_scaling is None:
																return

											if not isinstance(self.rope_scaling	,    _A    ) 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"	,    _A    )
											__lowerCAmelCase            = self.rope_scaling.get("factor"	,    _A    )
											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(_A	,    _A    ) or rope_scaling_factor <= 1.0:
																raise ValueError(f"""`rope_scaling`'s factor field must be an float > 1, got {rope_scaling_factor}"""    )










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	,    _A	,    _A=1_3	,    _A=7	,    _A=True	,    _A=True	,    _A=True	,    _A=True	,    _A=9_9	,    _A=3_2	,    _A=2	,    _A=4	,    _A=3_7	,    _A="gelu"	,    _A=0.1	,    _A=0.1	,    _A=5_1_2	,    _A=1_6	,    _A=2	,    _A=0.02	,    _A=False	,    _A=True	,    _A="None"	,    _A=3	,    _A=4	,    _A=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        __SCREAMING_SNAKE_CASE(     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=_A	,    )

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






						def        __SCREAMING_SNAKE_CASE(     self	,    _A	,    _A	,    _A	,    _A	,    _A	,    _A	,    _A    ):




											"""simple docstring"""



											__lowerCAmelCase            = TFDebertaVaModel(config=_A    )
											__lowerCAmelCase            = {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}

											__lowerCAmelCase            = [input_ids, input_mask]
											__lowerCAmelCase            = model(_A    )

											__lowerCAmelCase            = model(_A    )

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






						def        __SCREAMING_SNAKE_CASE(     self	,    _A	,    _A	,    _A	,    _A	,    _A	,    _A	,    _A    ):




											"""simple docstring"""



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






						def        __SCREAMING_SNAKE_CASE(     self	,    _A	,    _A	,    _A	,    _A	,    _A	,    _A	,    _A    ):




											"""simple docstring"""



											__lowerCAmelCase            = self.num_labels
											__lowerCAmelCase            = TFDebertaVaForSequenceClassification(config=_A    )
											__lowerCAmelCase            = {
											    "input_ids": input_ids,
											    "attention_mask": input_mask,
											    "token_type_ids": token_type_ids,
											}

											__lowerCAmelCase            = model(_A    )
											self.parent.assertEqual(result.logits.shape	,    (self.batch_size, self.num_labels)    )






						def        __SCREAMING_SNAKE_CASE(     self	,    _A	,    _A	,    _A	,    _A	,    _A	,    _A	,    _A    ):




											"""simple docstring"""



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






						def        __SCREAMING_SNAKE_CASE(     self	,    _A	,    _A	,    _A	,    _A	,    _A	,    _A	,    _A    ):




											"""simple docstring"""



											__lowerCAmelCase            = TFDebertaVaForQuestionAnswering(config=_A    )
											__lowerCAmelCase            = {
											    "input_ids": input_ids,
											    "attention_mask": input_mask,
											    "token_type_ids": token_type_ids,
											}

											__lowerCAmelCase            = model(_A    )
											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        __SCREAMING_SNAKE_CASE(     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   ):
						_a							:					Optional[Any]      =					(
						    (
						        TFDebertaVaModel,
						        TFDebertaVaForMaskedLM,
						        TFDebertaVaForQuestionAnswering,
						        TFDebertaVaForSequenceClassification,
						        TFDebertaVaForTokenClassification,
						    )
						    if is_tf_available()
						    else ()
						)
						_a							:					Union[str, Any]      =					(
						    {
						        """feature-extraction""": TFDebertaVaModel,
						        """fill-mask""": TFDebertaVaForMaskedLM,
						        """question-answering""": TFDebertaVaForQuestionAnswering,
						        """text-classification""": TFDebertaVaForSequenceClassification,
						        """token-classification""": TFDebertaVaForTokenClassification,
						        """zero-shot""": TFDebertaVaForSequenceClassification,
						    }
						    if is_tf_available()
						    else {}
						)

						_a							:					str      =					False
						_a							:					List[str]      =					False






						def        __SCREAMING_SNAKE_CASE(     self    ):




											"""simple docstring"""



											__lowerCAmelCase            = TFDebertaVaModelTester(self    )
											__lowerCAmelCase            = ConfigTester(self	,    config_class=_A	,    hidden_size=3_7    )






						def        __SCREAMING_SNAKE_CASE(     self    ):




											"""simple docstring"""



											self.config_tester.run_common_tests()






						def        __SCREAMING_SNAKE_CASE(     self    ):




											"""simple docstring"""



											__lowerCAmelCase            = self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_model(*_A    )






						def        __SCREAMING_SNAKE_CASE(     self    ):




											"""simple docstring"""



											__lowerCAmelCase            = self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_masked_lm(*_A    )






						def        __SCREAMING_SNAKE_CASE(     self    ):




											"""simple docstring"""



											__lowerCAmelCase            = self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_question_answering(*_A    )






						def        __SCREAMING_SNAKE_CASE(     self    ):




											"""simple docstring"""



											__lowerCAmelCase            = self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_sequence_classification(*_A    )






						def        __SCREAMING_SNAKE_CASE(     self    ):




											"""simple docstring"""



											__lowerCAmelCase            = self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_for_token_classification(*_A    )






						@slow
						def        __SCREAMING_SNAKE_CASE(     self    ):




											"""simple docstring"""



											__lowerCAmelCase            = TFDebertaVaModel.from_pretrained("kamalkraj/deberta-v2-xlarge"    )
											self.assertIsNotNone(_A    )






@require_tf
class     a__					(      unittest.TestCase   ):






						@unittest.skip(reason="Model not available yet"    )
						def        __SCREAMING_SNAKE_CASE(     self    ):




											"""simple docstring"""



											pass






						@slow
						def        __SCREAMING_SNAKE_CASE(     self    ):




											"""simple docstring"""



											__lowerCAmelCase            = TFDebertaVaModel.from_pretrained("kamalkraj/deberta-v2-xlarge"    )
											__lowerCAmelCase            = tf.constant([[0, 3_1_4_1_4, 2_3_2, 3_2_8, 7_4_0, 1_1_4_0, 1_2_6_9_5, 6_9, 4_6_0_7_8, 1_5_8_8, 2]]    )
											__lowerCAmelCase            = tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]    )
											__lowerCAmelCase            = model(_A	,    attention_mask=_A    )[0]

											__lowerCAmelCase            = tf.constant(
											    [[[0.23_56, 0.19_48, 0.03_69], [-0.10_63, 0.35_86, -0.51_52], [-0.63_99, -0.02_59, -0.25_25]]]    )
											tf.debugging.assert_near(output[:, 1:4, 1:4]	,    _A	,    atol=1E-4    )




