
"""simple docstring"""







import unittest

from transformers import DebertaConfig, is_torch_available
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
  import torch

  from transformers import (
      DebertaForMaskedLM,
      DebertaForQuestionAnswering,
      DebertaForSequenceClassification,
      DebertaForTokenClassification,
      DebertaModel,
  )
  from transformers.models.deberta.modeling_deberta import DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST







class 							__magic_name__     (		lowercase__   ):





     def __init__(				self   :							int							,						snake_case_   :							Union[str, Any]							,						snake_case_   :							Optional[Any]=13							,						snake_case_   :							List[Any]=7							,						snake_case_   :							List[str]=True							,						snake_case_   :							Union[str, Any]=True							,						snake_case_   :							Optional[Any]=True							,						snake_case_   :							Any=True							,						snake_case_   :							int=99							,						snake_case_   :							Union[str, Any]=32							,						snake_case_   :							Optional[int]=5							,						snake_case_   :							Union[str, Any]=4							,						snake_case_   :							Union[str, Any]=37							,						snake_case_   :							List[str]="gelu"							,						snake_case_   :							Optional[int]=0.1							,						snake_case_   :							Union[str, Any]=0.1							,						snake_case_   :							List[str]=512							,						snake_case_   :							Any=16							,						snake_case_   :							List[Any]=2							,						snake_case_   :							Optional[int]=0.02							,						snake_case_   :							str=False							,						snake_case_   :							Union[str, Any]=True							,						snake_case_   :							Dict="None"							,						snake_case_   :							int=3							,						snake_case_   :							Optional[Any]=4							,						snake_case_   :							Union[str, Any]=None							,						):
            __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     			=       relative_attention
            __snake_case     			=       position_biased_input
            __snake_case     			=       pos_att_type
            __snake_case     			=       scope





     def 							lowerCAmelCase      (				self   :							Tuple    ):
            __snake_case     			=       ids_tensor([self.batch_size, self.seq_length]							,						self.vocab_size    )

            __snake_case     			=       None
            if self.use_input_mask:
                   __snake_case     			=       ids_tensor([self.batch_size, self.seq_length]							,						vocab_size=2    )

            __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   :							str    ):
            return DebertaConfig(
                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							,						initializer_range=self.initializer_range							,						relative_attention=self.relative_attention							,						position_biased_input=self.position_biased_input							,						pos_att_type=self.pos_att_type							,						)





     def 							lowerCAmelCase      (				self   :							Optional[Any]    ):
            __snake_case     			=       self.get_config()
            __snake_case     			=       300
            return config





     def 							lowerCAmelCase      (				self   :							Optional[int]							,						snake_case_   :							int    ):
            self.parent.assertListEqual(list(result.loss.size()    )							,						[]    )





     def 							lowerCAmelCase      (				self   :							Optional[int]							,						snake_case_   :							Dict							,						snake_case_   :							Any							,						snake_case_   :							Optional[int]							,						snake_case_   :							int							,						snake_case_   :							List[str]							,						snake_case_   :							List[Any]							,						snake_case_   :							Dict    ):
            __snake_case     			=       DebertaModel(config=snake_case_    )
            model.to(snake_case_    )
            model.eval()
            __snake_case     			=       model(snake_case_							,						attention_mask=snake_case_							,						token_type_ids=snake_case_    )[0]
            __snake_case     			=       model(snake_case_							,						token_type_ids=snake_case_    )[0]
            __snake_case     			=       model(snake_case_    )[0]

            self.parent.assertListEqual(list(sequence_output.size()    )							,						[self.batch_size, self.seq_length, self.hidden_size]    )





     def 							lowerCAmelCase      (				self   :							Dict							,						snake_case_   :							Optional[int]							,						snake_case_   :							Optional[Any]							,						snake_case_   :							Any							,						snake_case_   :							Optional[Any]							,						snake_case_   :							Optional[Any]							,						snake_case_   :							int							,						snake_case_   :							Any    ):
            __snake_case     			=       DebertaForMaskedLM(config=snake_case_    )
            model.to(snake_case_    )
            model.eval()
            __snake_case     			=       model(snake_case_							,						attention_mask=snake_case_							,						token_type_ids=snake_case_							,						labels=snake_case_    )

            self.parent.assertEqual(result.logits.shape							,						(self.batch_size, self.seq_length, self.vocab_size)    )





     def 							lowerCAmelCase      (				self   :							Optional[int]							,						snake_case_   :							Dict							,						snake_case_   :							List[Any]							,						snake_case_   :							Tuple							,						snake_case_   :							List[Any]							,						snake_case_   :							str							,						snake_case_   :							Optional[Any]							,						snake_case_   :							Optional[int]    ):
            __snake_case     			=       self.num_labels
            __snake_case     			=       DebertaForSequenceClassification(snake_case_    )
            model.to(snake_case_    )
            model.eval()
            __snake_case     			=       model(snake_case_							,						attention_mask=snake_case_							,						token_type_ids=snake_case_							,						labels=snake_case_    )
            self.parent.assertListEqual(list(result.logits.size()    )							,						[self.batch_size, self.num_labels]    )
            self.check_loss_output(snake_case_    )





     def 							lowerCAmelCase      (				self   :							Any							,						snake_case_   :							List[str]							,						snake_case_   :							List[str]							,						snake_case_   :							List[str]							,						snake_case_   :							Tuple							,						snake_case_   :							Tuple							,						snake_case_   :							Optional[Any]							,						snake_case_   :							Dict    ):
            __snake_case     			=       self.num_labels
            __snake_case     			=       DebertaForTokenClassification(config=snake_case_    )
            model.to(snake_case_    )
            model.eval()
            __snake_case     			=       model(snake_case_							,						attention_mask=snake_case_							,						token_type_ids=snake_case_							,						labels=snake_case_    )
            self.parent.assertEqual(result.logits.shape							,						(self.batch_size, self.seq_length, self.num_labels)    )





     def 							lowerCAmelCase      (				self   :							List[Any]							,						snake_case_   :							List[str]							,						snake_case_   :							int							,						snake_case_   :							Dict							,						snake_case_   :							Optional[int]							,						snake_case_   :							int							,						snake_case_   :							Union[str, Any]							,						snake_case_   :							List[str]    ):
            __snake_case     			=       DebertaForQuestionAnswering(config=snake_case_    )
            model.to(snake_case_    )
            model.eval()
            __snake_case     			=       model(
                snake_case_							,						attention_mask=snake_case_							,						token_type_ids=snake_case_							,						start_positions=snake_case_							,						end_positions=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   :							Optional[Any]    ):
            __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, "token_type_ids": token_type_ids, "attention_mask": input_mask}
            return config, inputs_dict







@require_torch
class 							__magic_name__     (		lowercase__      ,		lowercase__      ,		unittest.TestCase   ):
     _SCREAMING_SNAKE_CASE       :					str     							=   (
         (
             DebertaModel,
             DebertaForMaskedLM,
             DebertaForSequenceClassification,
             DebertaForTokenClassification,
             DebertaForQuestionAnswering,
         )
         if is_torch_available()
         else ()
     )
     _SCREAMING_SNAKE_CASE       :					Union[str, Any]     							=   (
         {
             'feature-extraction': DebertaModel,
             'fill-mask': DebertaForMaskedLM,
             'question-answering': DebertaForQuestionAnswering,
             'text-classification': DebertaForSequenceClassification,
             'token-classification': DebertaForTokenClassification,
             'zero-shot': DebertaForSequenceClassification,
         }
         if is_torch_available()
         else {}
     )

     _SCREAMING_SNAKE_CASE       :					Tuple     							=   True
     _SCREAMING_SNAKE_CASE       :					Union[str, Any]     							=   False
     _SCREAMING_SNAKE_CASE       :					int     							=   False
     _SCREAMING_SNAKE_CASE       :					Any     							=   False
     _SCREAMING_SNAKE_CASE       :					List[str]     							=   False





     def 							lowerCAmelCase      (				self   :							str    ):
            __snake_case     			=       DebertaModelTester(self    )
            __snake_case     			=       ConfigTester(self							,						config_class=snake_case_							,						hidden_size=37    )





     def 							lowerCAmelCase      (				self   :							List[str]    ):
            self.config_tester.run_common_tests()





     def 							lowerCAmelCase      (				self   :							Any    ):
            __snake_case     			=       self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_deberta_model(*snake_case_    )





     def 							lowerCAmelCase      (				self   :							List[str]    ):
            __snake_case     			=       self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_deberta_for_sequence_classification(*snake_case_    )





     def 							lowerCAmelCase      (				self   :							str    ):
            __snake_case     			=       self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_deberta_for_masked_lm(*snake_case_    )





     def 							lowerCAmelCase      (				self   :							Dict    ):
            __snake_case     			=       self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_deberta_for_question_answering(*snake_case_    )





     def 							lowerCAmelCase      (				self   :							Optional[Any]    ):
            __snake_case     			=       self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_deberta_for_token_classification(*snake_case_    )





     @slow
     def 							lowerCAmelCase      (				self   :							Tuple    ):
            for model_name in DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                   __snake_case     			=       DebertaModel.from_pretrained(snake_case_    )
                   self.assertIsNotNone(snake_case_    )







@require_torch
@require_sentencepiece
@require_tokenizers
class 							__magic_name__     (		unittest.TestCase   ):





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





     @slow
     def 							lowerCAmelCase      (				self   :							List[str]    ):
            __snake_case     			=       DebertaModel.from_pretrained("microsoft/deberta-base"    )

            __snake_case     			=       torch.tensor([[0, 31414, 232, 328, 740, 1140, 12695, 69, 46078, 1588, 2]]    )
            __snake_case     			=       torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]    )
            with torch.no_grad():
                   __snake_case     			=       model(snake_case_							,						attention_mask=snake_case_    )[0]
            # compare the actual values for a slice.
            __snake_case     			=       torch.tensor(
                [[[-0.5986, -0.8055, -0.8462], [1.4484, -0.9348, -0.8059], [0.3123, 0.0032, -1.4131]]]    )
            self.assertTrue(torch.allclose(output[:, 1:4, 1:4]							,						snake_case_							,						atol=1e-4    )							,						F'''{output[:, 1:4, 1:4]}'''    )


"""simple docstring"""







from __future__ import annotations

from collections.abc import Callable
def   __UpperCamelCase   (					SCREAMING_SNAKE_CASE							,    SCREAMING_SNAKE_CASE							,    SCREAMING_SNAKE_CASE							,    SCREAMING_SNAKE_CASE = 1_00							,    )  ->     float:







							"""simple docstring"""


							__snake_case     			=       x_start
							__snake_case     			=       fnc(SCREAMING_SNAKE_CASE )
							__snake_case     			=       0.0
							for _ in range(SCREAMING_SNAKE_CASE ):
														# Approximates small segments of curve as linear and solve
														# for trapezoidal area
														__snake_case     			=       (x_end - x_start) / steps + xa
														__snake_case     			=       fnc(SCREAMING_SNAKE_CASE )
														area += abs(fxa + fxa ) * (xa - xa) / 2
														# Increment step
														__snake_case     			=       xa
														__snake_case     			=       fxa
							return area


if __name__ == "__main__":
		def   __UpperCamelCase   (					SCREAMING_SNAKE_CASE )  ->     List[Any]:







									"""simple docstring"""


									return x**3 + x**2

		print("""f(x) = x^3 + x^2""")
		print("""The area between the curve, x = -5, x = 5 and the x axis is:""")
		_SCREAMING_SNAKE_CASE	       =      10
		while i <= 100_000:
				print(F"""with {i} steps: {trapezoidal_area(f, -5, 5, i)}""")
				i *= 10
