



import numpy as np





def 							A     (					_UpperCAmelCase    :       int							,       _UpperCAmelCase    :       Dict							,       _UpperCAmelCase    :       Optional[int]							,       _UpperCAmelCase    :       Dict							,       _UpperCAmelCase    :       Optional[Any]   )    ->			Optional[int]:







			'''simple docstring'''
			_UpperCAmelCase			=       int(np.ceil((x_end - xa) / h   )   )
			_UpperCAmelCase			=       np.zeros((n + 1,)   )
			_UpperCAmelCase			=       ya
			_UpperCAmelCase			=       xa

			for k in range(_UpperCAmelCase   ):
						_UpperCAmelCase			=       f(_UpperCAmelCase							,       y[k]   )
						_UpperCAmelCase			=       f(x + 0.5 * h							,       y[k] + 0.5 * h * ka   )
						_UpperCAmelCase			=       f(x + 0.5 * h							,       y[k] + 0.5 * h * ka   )
						_UpperCAmelCase			=       f(x + h							,       y[k] + h * ka   )
						_UpperCAmelCase			=       y[k] + (1 / 6) * h * (ka + 2 * ka + 2 * ka + ka)
						x += h

			return y


if __name__ == "__main__":
							import doctest

							doctest.testmod()





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       __lowerCAmelCase   :



			def __init__(						self       :  str			,		A       :  str			,		A       :  Dict=13			,		A       :  int=7			,		A       :  Tuple=True			,		A       :  Union[str, Any]=True			,		A       :  Any=True			,		A       :  Dict=True			,		A       :  Dict=99			,		A       :  Tuple=32			,		A       :  Any=2			,		A       :  Any=4			,		A       :  Any=37			,		A       :  Optional[Any]="gelu"			,		A       :  List[Any]=0.1			,		A       :  Tuple=0.1			,		A       :  Optional[Any]=5_12			,		A       :  Tuple=16			,		A       :  int=2			,		A       :  List[str]=0.0_2			,		A       :  int=False			,		A       :  List[Any]=True			,		A       :  Optional[Any]="None"			,		A       :  Union[str, Any]=3			,		A       :  List[str]=4			,		A       :  List[Any]=None			,		)       ->   int:



						"""simple docstring"""






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



			def    _lowerCamelCase	(						self       :  Any)       ->   Union[str, Any]:



						"""simple docstring"""






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

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

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

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

						_UpperCAmelCase			=       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    _lowerCamelCase	(						self       :  Union[str, Any]			,		A       :  Optional[int]			,		A       :  Tuple			,		A       :  int			,		A       :  Any			,		A       :  List[str]			,		A       :  List[str]			,		A       :  int)       ->   Tuple:



						"""simple docstring"""






						_UpperCAmelCase			=       TFDebertaVaModel(config=A)
						_UpperCAmelCase			=       {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}

						_UpperCAmelCase			=       [input_ids, input_mask]
						_UpperCAmelCase			=       model(A)

						_UpperCAmelCase			=       model(A)

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



			def    _lowerCamelCase	(						self       :  str			,		A       :  Tuple			,		A       :  Tuple			,		A       :  Optional[int]			,		A       :  List[str]			,		A       :  Any			,		A       :  List[str]			,		A       :  List[str])       ->   Optional[int]:



						"""simple docstring"""






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



			def    _lowerCamelCase	(						self       :  List[Any]			,		A       :  Tuple			,		A       :  Tuple			,		A       :  Optional[int]			,		A       :  Optional[int]			,		A       :  List[Any]			,		A       :  Any			,		A       :  Optional[int])       ->   Union[str, Any]:



						"""simple docstring"""






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

						_UpperCAmelCase			=       model(A)
						self.parent.assertEqual(result.logits.shape			,		(self.batch_size, self.num_labels))



			def    _lowerCamelCase	(						self       :  Union[str, Any]			,		A       :  List[Any]			,		A       :  List[Any]			,		A       :  List[str]			,		A       :  Optional[Any]			,		A       :  int			,		A       :  Any			,		A       :  int)       ->   Union[str, Any]:



						"""simple docstring"""






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



			def    _lowerCamelCase	(						self       :  List[Any]			,		A       :  List[Any]			,		A       :  List[str]			,		A       :  Dict			,		A       :  Dict			,		A       :  Any			,		A       :  Tuple			,		A       :  List[Any])       ->   List[str]:



						"""simple docstring"""






						_UpperCAmelCase			=       TFDebertaVaForQuestionAnswering(config=A)
						_UpperCAmelCase			=       {
						    'input_ids': input_ids,
						    'attention_mask': input_mask,
						    'token_type_ids': token_type_ids,
						}

						_UpperCAmelCase			=       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    _lowerCamelCase	(						self       :  Union[str, Any])       ->   List[Any]:



						"""simple docstring"""






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







@require_tf
class       __lowerCAmelCase   (      A    ,						A    ,						unittest.TestCase						):
			UpperCamelCase        =					(
			    (
			        TFDebertaVaModel,
			        TFDebertaVaForMaskedLM,
			        TFDebertaVaForQuestionAnswering,
			        TFDebertaVaForSequenceClassification,
			        TFDebertaVaForTokenClassification,
			    )
			    if is_tf_available()
			    else ()
			)
			UpperCamelCase        =					(
			    {
			        '''feature-extraction''': TFDebertaVaModel,
			        '''fill-mask''': TFDebertaVaForMaskedLM,
			        '''question-answering''': TFDebertaVaForQuestionAnswering,
			        '''text-classification''': TFDebertaVaForSequenceClassification,
			        '''token-classification''': TFDebertaVaForTokenClassification,
			        '''zero-shot''': TFDebertaVaForSequenceClassification,
			    }
			    if is_tf_available()
			    else {}
			)

			UpperCamelCase        =					False
			UpperCamelCase        =					False



			def    _lowerCamelCase	(						self       :  int)       ->   Optional[int]:



						"""simple docstring"""






						_UpperCAmelCase			=       TFDebertaVaModelTester(self)
						_UpperCAmelCase			=       ConfigTester(self			,		config_class=A			,		hidden_size=37)



			def    _lowerCamelCase	(						self       :  Optional[int])       ->   List[str]:



						"""simple docstring"""






						self.config_tester.run_common_tests()



			def    _lowerCamelCase	(						self       :  Tuple)       ->   Optional[int]:



						"""simple docstring"""






						_UpperCAmelCase			=       self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_model(*A)



			def    _lowerCamelCase	(						self       :  Tuple)       ->   Optional[Any]:



						"""simple docstring"""






						_UpperCAmelCase			=       self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_masked_lm(*A)



			def    _lowerCamelCase	(						self       :  Tuple)       ->   str:



						"""simple docstring"""






						_UpperCAmelCase			=       self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_question_answering(*A)



			def    _lowerCamelCase	(						self       :  int)       ->   List[Any]:



						"""simple docstring"""






						_UpperCAmelCase			=       self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_sequence_classification(*A)



			def    _lowerCamelCase	(						self       :  Dict)       ->   Union[str, Any]:



						"""simple docstring"""






						_UpperCAmelCase			=       self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_token_classification(*A)



			@slow
			def    _lowerCamelCase	(						self       :  List[Any])       ->   Union[str, Any]:



						"""simple docstring"""






						_UpperCAmelCase			=       TFDebertaVaModel.from_pretrained('kamalkraj/deberta-v2-xlarge')
						self.assertIsNotNone(A)







@require_tf
class       __lowerCAmelCase   (      unittest.TestCase						):



			@unittest.skip(reason='Model not available yet')
			def    _lowerCamelCase	(						self       :  Optional[int])       ->   Dict:



						"""simple docstring"""






						pass



			@slow
			def    _lowerCamelCase	(						self       :  List[str])       ->   Optional[int]:



						"""simple docstring"""






						_UpperCAmelCase			=       TFDebertaVaModel.from_pretrained('kamalkraj/deberta-v2-xlarge')
						_UpperCAmelCase			=       tf.constant([[0, 3_14_14, 2_32, 3_28, 7_40, 11_40, 1_26_95, 69, 4_60_78, 15_88, 2]])
						_UpperCAmelCase			=       tf.constant([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]])
						_UpperCAmelCase			=       model(A			,		attention_mask=A)[0]

						_UpperCAmelCase			=       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]			,		A			,		atol=1E-4)
