




"""simple docstring"""
from math import factorial





def 						UpperCAmelCase				(			A__:    int							,				A__:    int							,				A__:    float     )  ->     float:
			if successes > trials:
						raise ValueError('successes must be lower or equal to trials'     )
			if trials < 0 or successes < 0:
						raise ValueError('the function is defined for non-negative integers'     )
			if not isinstance(A__							,				A__     ) or not isinstance(A__							,				A__     ):
						raise ValueError('the function is defined for non-negative integers'     )
			if not 0 < prob < 1:
						raise ValueError('prob has to be in range of 1 - 0'     )
			__lowerCamelCase					:	Union[str, Any]	       =				(prob**successes) * ((1 - prob) ** (trials - successes))
			# Calculate the binomial coefficient: n! / k!(n-k)!
			__lowerCamelCase					:	Optional[Any]	       =				float(factorial(A__     )     )
			coefficient /= factorial(A__     ) * factorial(trials - successes     )
			return probability * coefficient


if __name__ == "__main__":
					from doctest import testmod

					testmod()
					print('''Probability of 2 successes out of 4 trails''')
					print('''with probability of 0.75 is:''', end=''' ''')
					print(binomial_distribution(2, 4, 0.7_5))









"""simple docstring"""
import unittest

from transformers import DebertaVaConfig, 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 (
					    DebertaVaForMaskedLM,
					    DebertaVaForMultipleChoice,
					    DebertaVaForQuestionAnswering,
					    DebertaVaForSequenceClassification,
					    DebertaVaForTokenClassification,
					    DebertaVaModel,
					)
					from transformers.models.deberta_va.modeling_deberta_va import DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST

class __lowercase(      lowercase__				):




					'''simple docstring'''


					def __init__(    self						,	__a						,	__a=13						,	__a=7						,	__a=True						,	__a=True						,	__a=True						,	__a=True						,	__a=99						,	__a=32						,	__a=5						,	__a=4						,	__a=37						,	__a="gelu"						,	__a=0.1						,	__a=0.1						,	__a=512						,	__a=16						,	__a=2						,	__a=0.02						,	__a=False						,	__a=True						,	__a="None"						,	__a=3						,	__a=4						,	__a=None						,	):
								__lowerCamelCase					:	List[str]	       =				parent
								__lowerCamelCase					:	Dict	       =				batch_size
								__lowerCamelCase					:	str	       =				seq_length
								__lowerCamelCase					:	Optional[int]	       =				is_training
								__lowerCamelCase					:	Dict	       =				use_input_mask
								__lowerCamelCase					:	Dict	       =				use_token_type_ids
								__lowerCamelCase					:	Dict	       =				use_labels
								__lowerCamelCase					:	Optional[Any]	       =				vocab_size
								__lowerCamelCase					:	Any	       =				hidden_size
								__lowerCamelCase					:	List[Any]	       =				num_hidden_layers
								__lowerCamelCase					:	Tuple	       =				num_attention_heads
								__lowerCamelCase					:	Any	       =				intermediate_size
								__lowerCamelCase					:	Optional[Any]	       =				hidden_act
								__lowerCamelCase					:	Any	       =				hidden_dropout_prob
								__lowerCamelCase					:	Optional[Any]	       =				attention_probs_dropout_prob
								__lowerCamelCase					:	List[Any]	       =				max_position_embeddings
								__lowerCamelCase					:	Optional[Any]	       =				type_vocab_size
								__lowerCamelCase					:	Dict	       =				type_sequence_label_size
								__lowerCamelCase					:	Any	       =				initializer_range
								__lowerCamelCase					:	Union[str, Any]	       =				num_labels
								__lowerCamelCase					:	Tuple	       =				num_choices
								__lowerCamelCase					:	str	       =				relative_attention
								__lowerCamelCase					:	Optional[int]	       =				position_biased_input
								__lowerCamelCase					:	int	       =				pos_att_type
								__lowerCamelCase					:	str	       =				scope
					def     snake_case_				(    self     ):
								__lowerCamelCase					:	Union[str, Any]	       =				ids_tensor([self.batch_size, self.seq_length]						,	self.vocab_size     )

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

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

								__lowerCamelCase					:	Optional[Any]	       =				None
								__lowerCamelCase					:	Optional[Any]	       =				None
								__lowerCamelCase					:	int	       =				None
								if self.use_labels:
											__lowerCamelCase					:	Optional[int]	       =				ids_tensor([self.batch_size]						,	self.type_sequence_label_size     )
											__lowerCamelCase					:	Optional[int]	       =				ids_tensor([self.batch_size, self.seq_length]						,	self.num_labels     )
											__lowerCamelCase					:	List[Any]	       =				ids_tensor([self.batch_size]						,	self.num_choices     )

								__lowerCamelCase					:	Optional[Any]	       =				self.get_config()

								return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels
					def     snake_case_				(    self     ):
								return 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						,	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     snake_case_				(    self						,	__a     ):
								self.parent.assertListEqual(list(result.loss.size()     )						,	[]     )
					def     snake_case_				(    self						,	__a						,	__a						,	__a						,	__a						,	__a						,	__a						,	__a     ):
								__lowerCamelCase					:	int	       =				DebertaVaModel(config=__a     )
								model.to(__a     )
								model.eval()
								__lowerCamelCase					:	str	       =				model(__a						,	attention_mask=__a						,	token_type_ids=__a     )[0]
								__lowerCamelCase					:	str	       =				model(__a						,	token_type_ids=__a     )[0]
								__lowerCamelCase					:	Optional[Any]	       =				model(__a     )[0]

								self.parent.assertListEqual(list(sequence_output.size()     )						,	[self.batch_size, self.seq_length, self.hidden_size]     )
					def     snake_case_				(    self						,	__a						,	__a						,	__a						,	__a						,	__a						,	__a						,	__a     ):
								__lowerCamelCase					:	List[str]	       =				DebertaVaForMaskedLM(config=__a     )
								model.to(__a     )
								model.eval()
								__lowerCamelCase					:	Union[str, Any]	       =				model(__a						,	attention_mask=__a						,	token_type_ids=__a						,	labels=__a     )

								self.parent.assertEqual(result.logits.shape						,	(self.batch_size, self.seq_length, self.vocab_size)     )
					def     snake_case_				(    self						,	__a						,	__a						,	__a						,	__a						,	__a						,	__a						,	__a     ):
								__lowerCamelCase					:	Optional[int]	       =				self.num_labels
								__lowerCamelCase					:	List[Any]	       =				DebertaVaForSequenceClassification(__a     )
								model.to(__a     )
								model.eval()
								__lowerCamelCase					:	Optional[Any]	       =				model(__a						,	attention_mask=__a						,	token_type_ids=__a						,	labels=__a     )
								self.parent.assertListEqual(list(result.logits.size()     )						,	[self.batch_size, self.num_labels]     )
								self.check_loss_output(__a     )
					def     snake_case_				(    self						,	__a						,	__a						,	__a						,	__a						,	__a						,	__a						,	__a     ):
								__lowerCamelCase					:	int	       =				self.num_labels
								__lowerCamelCase					:	Dict	       =				DebertaVaForTokenClassification(config=__a     )
								model.to(__a     )
								model.eval()
								__lowerCamelCase					:	int	       =				model(__a						,	attention_mask=__a						,	token_type_ids=__a						,	labels=__a     )
								self.parent.assertEqual(result.logits.shape						,	(self.batch_size, self.seq_length, self.num_labels)     )
					def     snake_case_				(    self						,	__a						,	__a						,	__a						,	__a						,	__a						,	__a						,	__a     ):
								__lowerCamelCase					:	Optional[Any]	       =				DebertaVaForQuestionAnswering(config=__a     )
								model.to(__a     )
								model.eval()
								__lowerCamelCase					:	Any	       =				model(
								    __a						,	attention_mask=__a						,	token_type_ids=__a						,	start_positions=__a						,	end_positions=__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     snake_case_				(    self						,	__a						,	__a						,	__a						,	__a						,	__a						,	__a						,	__a     ):
								__lowerCamelCase					:	Any	       =				DebertaVaForMultipleChoice(config=__a     )
								model.to(__a     )
								model.eval()
								__lowerCamelCase					:	Union[str, Any]	       =				input_ids.unsqueeze(1     ).expand(-1						,	self.num_choices						,	-1     ).contiguous()
								__lowerCamelCase					:	Optional[int]	       =				token_type_ids.unsqueeze(1     ).expand(-1						,	self.num_choices						,	-1     ).contiguous()
								__lowerCamelCase					:	int	       =				input_mask.unsqueeze(1     ).expand(-1						,	self.num_choices						,	-1     ).contiguous()
								__lowerCamelCase					:	List[Any]	       =				model(
								    __a						,	attention_mask=__a						,	token_type_ids=__a						,	labels=__a						,	)
								self.parent.assertEqual(result.logits.shape						,	(self.batch_size, self.num_choices)     )





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



@require_torch
class __lowercase(      lowercase__	,	lowercase__	,	unittest.TestCase				):




					'''simple docstring'''


					__a						:						Dict     		= (
					    (
					        DebertaVaModel,
					        DebertaVaForMaskedLM,
					        DebertaVaForSequenceClassification,
					        DebertaVaForTokenClassification,
					        DebertaVaForQuestionAnswering,
					        DebertaVaForMultipleChoice,
					    )
					    if is_torch_available()
					    else ()
					)
					__a						:						Tuple     		= (
					    {
					        'feature-extraction': DebertaVaModel,
					        'fill-mask': DebertaVaForMaskedLM,
					        'question-answering': DebertaVaForQuestionAnswering,
					        'text-classification': DebertaVaForSequenceClassification,
					        'token-classification': DebertaVaForTokenClassification,
					        'zero-shot': DebertaVaForSequenceClassification,
					    }
					    if is_torch_available()
					    else {}
					)

					__a						:						str     		= True
					__a						:						Dict     		= False
					__a						:						Tuple     		= False
					__a						:						Optional[Any]     		= False
					__a						:						List[Any]     		= False
					def     snake_case_				(    self     ):
								__lowerCamelCase					:	List[str]	       =				DebertaVaModelTester(self     )
								__lowerCamelCase					:	Tuple	       =				ConfigTester(self						,	config_class=__a						,	hidden_size=37     )
					def     snake_case_				(    self     ):
								self.config_tester.run_common_tests()
					def     snake_case_				(    self     ):
								__lowerCamelCase					:	int	       =				self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_deberta_model(*__a     )
					def     snake_case_				(    self     ):
								__lowerCamelCase					:	Tuple	       =				self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_deberta_for_sequence_classification(*__a     )
					def     snake_case_				(    self     ):
								__lowerCamelCase					:	List[Any]	       =				self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_deberta_for_masked_lm(*__a     )
					def     snake_case_				(    self     ):
								__lowerCamelCase					:	str	       =				self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_deberta_for_question_answering(*__a     )
					def     snake_case_				(    self     ):
								__lowerCamelCase					:	List[Any]	       =				self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_deberta_for_token_classification(*__a     )
					def     snake_case_				(    self     ):
								__lowerCamelCase					:	Any	       =				self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_deberta_for_multiple_choice(*__a     )





					@slow
					def     snake_case_				(    self     ):
								for model_name in DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
											__lowerCamelCase					:	Tuple	       =				DebertaVaModel.from_pretrained(__a     )
											self.assertIsNotNone(__a     )



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




					'''simple docstring'''


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





					@slow
					def     snake_case_				(    self     ):
								__lowerCamelCase					:	Any	       =				DebertaVaModel.from_pretrained('microsoft/deberta-v2-xlarge'     )

								__lowerCamelCase					:	Any	       =				torch.tensor([[0, 31414, 232, 328, 740, 1140, 12695, 69, 46078, 1588, 2]]     )
								__lowerCamelCase					:	Any	       =				torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]     )
								with torch.no_grad():
											__lowerCamelCase					:	Union[str, Any]	       =				model(__a						,	attention_mask=__a     )[0]
								# compare the actual values for a slice.
								__lowerCamelCase					:	str	       =				torch.tensor(
								    [[[0.2_356, 0.1_948, 0.0_369], [-0.1_063, 0.3_586, -0.5_152], [-0.6_399, -0.0_259, -0.2_525]]]     )
								self.assertTrue(torch.allclose(output[:, 1:4, 1:4]						,	__a						,	atol=1E-4     )						,	f'''{output[:, 1:4, 1:4]}'''     )



