
"""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 ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE=13 ,	_SCREAMING_SNAKE_CASE=7 ,	_SCREAMING_SNAKE_CASE=True ,	_SCREAMING_SNAKE_CASE=True ,	_SCREAMING_SNAKE_CASE=True ,	_SCREAMING_SNAKE_CASE=True ,	_SCREAMING_SNAKE_CASE=99 ,	_SCREAMING_SNAKE_CASE=32 ,	_SCREAMING_SNAKE_CASE=2 ,	_SCREAMING_SNAKE_CASE=4 ,	_SCREAMING_SNAKE_CASE=37 ,	_SCREAMING_SNAKE_CASE="gelu" ,	_SCREAMING_SNAKE_CASE=0.1 ,	_SCREAMING_SNAKE_CASE=0.1 ,	_SCREAMING_SNAKE_CASE=5_12 ,	_SCREAMING_SNAKE_CASE=16 ,	_SCREAMING_SNAKE_CASE=2 ,	_SCREAMING_SNAKE_CASE=0.02 ,	_SCREAMING_SNAKE_CASE=False ,	_SCREAMING_SNAKE_CASE=True ,	_SCREAMING_SNAKE_CASE="None" ,	_SCREAMING_SNAKE_CASE=3 ,	_SCREAMING_SNAKE_CASE=4 ,	_SCREAMING_SNAKE_CASE=None ,	):
			__lowerCAmelCase    :		List[str]		    =   parent
			__lowerCAmelCase    :		str		    =   batch_size
			__lowerCAmelCase    :		Union[str, Any]		    =   seq_length
			__lowerCAmelCase    :		int		    =   is_training
			__lowerCAmelCase    :		List[str]		    =   use_input_mask
			__lowerCAmelCase    :		Any		    =   use_token_type_ids
			__lowerCAmelCase    :		List[str]		    =   use_labels
			__lowerCAmelCase    :		Optional[int]		    =   vocab_size
			__lowerCAmelCase    :		Tuple		    =   hidden_size
			__lowerCAmelCase    :		int		    =   num_hidden_layers
			__lowerCAmelCase    :		str		    =   num_attention_heads
			__lowerCAmelCase    :		Dict		    =   intermediate_size
			__lowerCAmelCase    :		Optional[int]		    =   hidden_act
			__lowerCAmelCase    :		Any		    =   hidden_dropout_prob
			__lowerCAmelCase    :		int		    =   attention_probs_dropout_prob
			__lowerCAmelCase    :		List[str]		    =   max_position_embeddings
			__lowerCAmelCase    :		List[Any]		    =   type_vocab_size
			__lowerCAmelCase    :		Dict		    =   type_sequence_label_size
			__lowerCAmelCase    :		List[Any]		    =   initializer_range
			__lowerCAmelCase    :		Union[str, Any]		    =   num_labels
			__lowerCAmelCase    :		Tuple		    =   num_choices
			__lowerCAmelCase    :		str		    =   relative_attention
			__lowerCAmelCase    :		Dict		    =   position_biased_input
			__lowerCAmelCase    :		List[Any]		    =   pos_att_type
			__lowerCAmelCase    :		Tuple		    =   scope

		def 							__lowerCamelCase							(   self				):
			__lowerCAmelCase    :		Union[str, Any]		    =   ids_tensor([self.batch_size, self.seq_length] ,	self.vocab_size				)

			__lowerCAmelCase    :		Any		    =   None
			if self.use_input_mask:
				__lowerCAmelCase    :		Dict		    =   random_attention_mask([self.batch_size, self.seq_length]				)

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

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

			__lowerCAmelCase    :		List[str]		    =   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=_SCREAMING_SNAKE_CASE ,	)

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

		def 							__lowerCamelCase							(   self ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE				):
			__lowerCAmelCase    :		Any		    =   TFDebertaVaModel(config=_SCREAMING_SNAKE_CASE				)
			__lowerCAmelCase    :		Tuple		    =   {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}

			__lowerCAmelCase    :		Union[str, Any]		    =   [input_ids, input_mask]
			__lowerCAmelCase    :		List[str]		    =   model(_SCREAMING_SNAKE_CASE				)

			__lowerCAmelCase    :		Optional[int]		    =   model(_SCREAMING_SNAKE_CASE				)

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

		def 							__lowerCamelCase							(   self ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE				):
			__lowerCAmelCase    :		List[str]		    =   TFDebertaVaForMaskedLM(config=_SCREAMING_SNAKE_CASE				)
			__lowerCAmelCase    :		Dict		    =   {
			    'input_ids': input_ids,
			    'attention_mask': input_mask,
			    'token_type_ids': token_type_ids,
			}
			__lowerCAmelCase    :		List[str]		    =   model(_SCREAMING_SNAKE_CASE				)
			self.parent.assertEqual(result.logits.shape ,	(self.batch_size, self.seq_length, self.vocab_size)				)

		def 							__lowerCamelCase							(   self ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE				):
			__lowerCAmelCase    :		Any		    =   self.num_labels
			__lowerCAmelCase    :		Any		    =   TFDebertaVaForSequenceClassification(config=_SCREAMING_SNAKE_CASE				)
			__lowerCAmelCase    :		List[str]		    =   {
			    'input_ids': input_ids,
			    'attention_mask': input_mask,
			    'token_type_ids': token_type_ids,
			}

			__lowerCAmelCase    :		int		    =   model(_SCREAMING_SNAKE_CASE				)
			self.parent.assertEqual(result.logits.shape ,	(self.batch_size, self.num_labels)				)

		def 							__lowerCamelCase							(   self ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE				):
			__lowerCAmelCase    :		Union[str, Any]		    =   self.num_labels
			__lowerCAmelCase    :		int		    =   TFDebertaVaForTokenClassification(config=_SCREAMING_SNAKE_CASE				)
			__lowerCAmelCase    :		Tuple		    =   {
			    'input_ids': input_ids,
			    'attention_mask': input_mask,
			    'token_type_ids': token_type_ids,
			}
			__lowerCAmelCase    :		Optional[Any]		    =   model(_SCREAMING_SNAKE_CASE				)
			self.parent.assertEqual(result.logits.shape ,	(self.batch_size, self.seq_length, self.num_labels)				)

		def 							__lowerCamelCase							(   self ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE				):
			__lowerCAmelCase    :		Any		    =   TFDebertaVaForQuestionAnswering(config=_SCREAMING_SNAKE_CASE				)
			__lowerCAmelCase    :		Any		    =   {
			    'input_ids': input_ids,
			    'attention_mask': input_mask,
			    'token_type_ids': token_type_ids,
			}

			__lowerCAmelCase    :		Tuple		    =   model(_SCREAMING_SNAKE_CASE				)
			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				):
			__lowerCAmelCase    :		Optional[int]		    =   self.prepare_config_and_inputs()
			(
			    (
			    __lowerCAmelCase
			)    ,     (
			    __lowerCAmelCase
			)    ,     (
			    __lowerCAmelCase
			)    ,     (
			    __lowerCAmelCase
			)    ,     (
			    __lowerCAmelCase
			)    ,     (
			    __lowerCAmelCase
			)    ,     (
			    __lowerCAmelCase
			)    ,     
			)    :		List[str]		    =   config_and_inputs
			__lowerCAmelCase    :		str		    =   {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
			return config, inputs_dict




@require_tf
class 				A__ (			_lowerCamelCase ,  _lowerCamelCase ,  unittest.TestCase):
		A_		: Union[str, Any]            =			(
		    (
		        TFDebertaVaModel,
		        TFDebertaVaForMaskedLM,
		        TFDebertaVaForQuestionAnswering,
		        TFDebertaVaForSequenceClassification,
		        TFDebertaVaForTokenClassification,
		    )
		    if is_tf_available()
		    else ()
		)
		A_		: 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_		: int            =			False
		A_		: Optional[int]            =			False

		def 							__lowerCamelCase							(   self				):
			__lowerCAmelCase    :		List[Any]		    =   TFDebertaVaModelTester(self				)
			__lowerCAmelCase    :		Dict		    =   ConfigTester(self ,	config_class=_SCREAMING_SNAKE_CASE ,	hidden_size=37				)

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

		def 							__lowerCamelCase							(   self				):
			__lowerCAmelCase    :		List[Any]		    =   self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_model(*_SCREAMING_SNAKE_CASE				)

		def 							__lowerCamelCase							(   self				):
			__lowerCAmelCase    :		Optional[int]		    =   self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_for_masked_lm(*_SCREAMING_SNAKE_CASE				)

		def 							__lowerCamelCase							(   self				):
			__lowerCAmelCase    :		Any		    =   self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_for_question_answering(*_SCREAMING_SNAKE_CASE				)

		def 							__lowerCamelCase							(   self				):
			__lowerCAmelCase    :		Any		    =   self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_for_sequence_classification(*_SCREAMING_SNAKE_CASE				)

		def 							__lowerCamelCase							(   self				):
			__lowerCAmelCase    :		Optional[Any]		    =   self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_for_token_classification(*_SCREAMING_SNAKE_CASE				)







		@slow
		def 							__lowerCamelCase							(   self				):
			__lowerCAmelCase    :		Dict		    =   TFDebertaVaModel.from_pretrained('kamalkraj/deberta-v2-xlarge'				)
			self.assertIsNotNone(_SCREAMING_SNAKE_CASE				)




@require_tf
class 				A__ (			unittest.TestCase):

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







		@slow
		def 							__lowerCamelCase							(   self				):
			__lowerCAmelCase    :		Tuple		    =   TFDebertaVaModel.from_pretrained('kamalkraj/deberta-v2-xlarge'				)
			__lowerCAmelCase    :		Any		    =   tf.constant([[0, 3_14_14, 2_32, 3_28, 7_40, 11_40, 1_26_95, 69, 4_60_78, 15_88, 2]]				)
			__lowerCAmelCase    :		str		    =   tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]				)
			__lowerCAmelCase    :		Tuple		    =   model(_SCREAMING_SNAKE_CASE ,	attention_mask=_SCREAMING_SNAKE_CASE				)[0]

			__lowerCAmelCase    :		str		    =   tf.constant(
			    [[[0.2356, 0.1948, 0.0369], [-0.1063, 0.3586, -0.5152], [-0.6399, -0.0259, -0.2525]]]				)
			tf.debugging.assert_near(output[:, 1:4, 1:4] ,	_SCREAMING_SNAKE_CASE ,	atol=1E-4				)

"""simple docstring"""







import unittest

import numpy as np

from transformers import RobertaConfig, is_flax_available
from transformers.testing_utils import require_flax, slow

from ...test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask


if is_flax_available():
							from transformers.models.roberta.modeling_flax_roberta import (
							    FlaxRobertaForCausalLM,
							    FlaxRobertaForMaskedLM,
							    FlaxRobertaForMultipleChoice,
							    FlaxRobertaForQuestionAnswering,
							    FlaxRobertaForSequenceClassification,
							    FlaxRobertaForTokenClassification,
							    FlaxRobertaModel,
							)




class 				A__ (			unittest.TestCase):

		def __init__(   self ,	_SCREAMING_SNAKE_CASE ,	_SCREAMING_SNAKE_CASE=13 ,	_SCREAMING_SNAKE_CASE=7 ,	_SCREAMING_SNAKE_CASE=True ,	_SCREAMING_SNAKE_CASE=True ,	_SCREAMING_SNAKE_CASE=True ,	_SCREAMING_SNAKE_CASE=True ,	_SCREAMING_SNAKE_CASE=99 ,	_SCREAMING_SNAKE_CASE=32 ,	_SCREAMING_SNAKE_CASE=5 ,	_SCREAMING_SNAKE_CASE=4 ,	_SCREAMING_SNAKE_CASE=37 ,	_SCREAMING_SNAKE_CASE="gelu" ,	_SCREAMING_SNAKE_CASE=0.1 ,	_SCREAMING_SNAKE_CASE=0.1 ,	_SCREAMING_SNAKE_CASE=5_12 ,	_SCREAMING_SNAKE_CASE=16 ,	_SCREAMING_SNAKE_CASE=2 ,	_SCREAMING_SNAKE_CASE=0.02 ,	_SCREAMING_SNAKE_CASE=4 ,	):
			__lowerCAmelCase    :		List[Any]		    =   parent
			__lowerCAmelCase    :		int		    =   batch_size
			__lowerCAmelCase    :		List[str]		    =   seq_length
			__lowerCAmelCase    :		str		    =   is_training
			__lowerCAmelCase    :		Optional[Any]		    =   use_attention_mask
			__lowerCAmelCase    :		Union[str, Any]		    =   use_token_type_ids
			__lowerCAmelCase    :		Dict		    =   use_labels
			__lowerCAmelCase    :		Union[str, Any]		    =   vocab_size
			__lowerCAmelCase    :		List[str]		    =   hidden_size
			__lowerCAmelCase    :		List[str]		    =   num_hidden_layers
			__lowerCAmelCase    :		Optional[int]		    =   num_attention_heads
			__lowerCAmelCase    :		Dict		    =   intermediate_size
			__lowerCAmelCase    :		Dict		    =   hidden_act
			__lowerCAmelCase    :		Optional[int]		    =   hidden_dropout_prob
			__lowerCAmelCase    :		Dict		    =   attention_probs_dropout_prob
			__lowerCAmelCase    :		Union[str, Any]		    =   max_position_embeddings
			__lowerCAmelCase    :		Any		    =   type_vocab_size
			__lowerCAmelCase    :		Tuple		    =   type_sequence_label_size
			__lowerCAmelCase    :		Union[str, Any]		    =   initializer_range
			__lowerCAmelCase    :		int		    =   num_choices

		def 							__lowerCamelCase							(   self				):
			__lowerCAmelCase    :		Union[str, Any]		    =   ids_tensor([self.batch_size, self.seq_length] ,	self.vocab_size				)

			__lowerCAmelCase    :		List[str]		    =   None
			if self.use_attention_mask:
				__lowerCAmelCase    :		str		    =   random_attention_mask([self.batch_size, self.seq_length]				)

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

			__lowerCAmelCase    :		str		    =   RobertaConfig(
			    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=_SCREAMING_SNAKE_CASE ,	initializer_range=self.initializer_range ,	)

			return config, input_ids, token_type_ids, attention_mask

		def 							__lowerCamelCase							(   self				):
			__lowerCAmelCase    :		Dict		    =   self.prepare_config_and_inputs()
			__lowerCAmelCase    ,     __lowerCAmelCase    ,     __lowerCAmelCase    ,     __lowerCAmelCase    :		List[Any]		    =   config_and_inputs
			__lowerCAmelCase    :		List[Any]		    =   {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': attention_mask}
			return config, inputs_dict







		def 							__lowerCamelCase							(   self				):
			__lowerCAmelCase    :		Optional[int]		    =   self.prepare_config_and_inputs()
			__lowerCAmelCase    ,     __lowerCAmelCase    ,     __lowerCAmelCase    ,     __lowerCAmelCase    :		Any		    =   config_and_inputs

			__lowerCAmelCase    :		int		    =   True
			__lowerCAmelCase    :		Any		    =   floats_tensor([self.batch_size, self.seq_length, self.hidden_size]				)
			__lowerCAmelCase    :		int		    =   ids_tensor([self.batch_size, self.seq_length] ,	vocab_size=2				)

			return (
			    config,
			    input_ids,
			    token_type_ids,
			    encoder_hidden_states,
			    encoder_attention_mask,
			)




@require_flax
class 				A__ (			_lowerCamelCase ,  unittest.TestCase):
		A_		: List[Any]            =			True

		A_		: Optional[Any]            =			(
		    (
		        FlaxRobertaModel,
		        FlaxRobertaForCausalLM,
		        FlaxRobertaForMaskedLM,
		        FlaxRobertaForSequenceClassification,
		        FlaxRobertaForTokenClassification,
		        FlaxRobertaForMultipleChoice,
		        FlaxRobertaForQuestionAnswering,
		    )
		    if is_flax_available()
		    else ()
		)

		def 							__lowerCamelCase							(   self				):
			__lowerCAmelCase    :		Tuple		    =   FlaxRobertaModelTester(self				)







		@slow
		def 							__lowerCamelCase							(   self				):
			for model_class_name in self.all_model_classes:
				__lowerCAmelCase    :		str		    =   model_class_name.from_pretrained('roberta-base' ,	from_pt=_SCREAMING_SNAKE_CASE				)
				__lowerCAmelCase    :		Optional[int]		    =   model(np.ones((1, 1)				)				)
				self.assertIsNotNone(_SCREAMING_SNAKE_CASE				)