



"""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 				lowerCamelCase  (			_lowerCAmelCase				):






					'''simple docstring'''





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






					def    lowerCAmelCase_				(       self:							List[Any]						)   ->	Optional[int]:
											snake_case_ :Optional[int]						=			ids_tensor([self.batch_size, self.seq_length]						,     self.vocab_size						)

											snake_case_ :Union[str, Any]						=			None
											if self.use_input_mask:
																	snake_case_ :List[Any]						=			ids_tensor([self.batch_size, self.seq_length]						,     vocab_size=2						)

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

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

											snake_case_ :Dict						=			self.get_config()

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






					def    lowerCAmelCase_				(       self:							Optional[Any]						)   ->	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:							List[str]						)   ->	Any:
											snake_case_ :Tuple						=			self.get_config()
											snake_case_ :Tuple						=			300
											return config






					def    lowerCAmelCase_				(       self:							Optional[int]						,     snake_case:							List[str]						)   ->	List[Any]:
											self.parent.assertListEqual(list(result.loss.size()						)						,     []						)






					def    lowerCAmelCase_				(       self:							Dict						,     snake_case:							Any						,     snake_case:							Dict						,     snake_case:							Any						,     snake_case:							Optional[Any]						,     snake_case:							Tuple						,     snake_case:							str						,     snake_case:							str						)   ->	List[str]:
											snake_case_ :Union[str, Any]						=			DebertaModel(config=snake_case						)
											model.to(snake_case						)
											model.eval()
											snake_case_ :Optional[Any]						=			model(snake_case						,     attention_mask=snake_case						,     token_type_ids=snake_case						)[0]
											snake_case_ :List[Any]						=			model(snake_case						,     token_type_ids=snake_case						)[0]
											snake_case_ :int						=			model(snake_case						)[0]

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






					def    lowerCAmelCase_				(       self:							Any						,     snake_case:							Optional[Any]						,     snake_case:							Union[str, Any]						,     snake_case:							Optional[Any]						,     snake_case:							int						,     snake_case:							Dict						,     snake_case:							Dict						,     snake_case:							Dict						)   ->	Tuple:
											snake_case_ :Any						=			DebertaForMaskedLM(config=snake_case						)
											model.to(snake_case						)
											model.eval()
											snake_case_ :Optional[int]						=			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:							int						,     snake_case:							Dict						,     snake_case:							str						,     snake_case:							Any						,     snake_case:							Optional[int]						,     snake_case:							Any						,     snake_case:							Dict						,     snake_case:							Union[str, Any]						)   ->	List[str]:
											snake_case_ :List[Any]						=			self.num_labels
											snake_case_ :str						=			DebertaForSequenceClassification(snake_case						)
											model.to(snake_case						)
											model.eval()
											snake_case_ :str						=			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:							Dict						,     snake_case:							Dict						,     snake_case:							Optional[int]						,     snake_case:							Dict						,     snake_case:							int						,     snake_case:							str						,     snake_case:							Tuple						)   ->	List[Any]:
											snake_case_ :Tuple						=			self.num_labels
											snake_case_ :Union[str, Any]						=			DebertaForTokenClassification(config=snake_case						)
											model.to(snake_case						)
											model.eval()
											snake_case_ :int						=			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:							Optional[int]						,     snake_case:							Optional[int]						,     snake_case:							int						,     snake_case:							List[str]						,     snake_case:							Tuple						,     snake_case:							Dict						,     snake_case:							Optional[int]						,     snake_case:							Tuple						)   ->	List[str]:
											snake_case_ :List[Any]						=			DebertaForQuestionAnswering(config=snake_case						)
											model.to(snake_case						)
											model.eval()
											snake_case_ :List[Any]						=			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:							Tuple						)   ->	int:
											snake_case_ :Optional[Any]						=			self.prepare_config_and_inputs()
											(
											    (
											    snake_case_
											),       (
											    snake_case_
											),       (
											    snake_case_
											),       (
											    snake_case_
											),       (
											    snake_case_
											),       (
											    snake_case_
											),       (
											    snake_case_
											),       
											) :str						=			config_and_inputs
											snake_case_ :List[str]						=			{"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
											return config, inputs_dict

@require_torch
class 				lowerCamelCase  (			_lowerCAmelCase    ,						_lowerCAmelCase    ,						unittest.TestCase				):






					'''simple docstring'''





					_A		:			Optional[int]						=     (
					    (
					        DebertaModel,
					        DebertaForMaskedLM,
					        DebertaForSequenceClassification,
					        DebertaForTokenClassification,
					        DebertaForQuestionAnswering,
					    )
					    if is_torch_available()
					    else ()
					)
					_A		:			str						=     (
					    {
					        """feature-extraction""": DebertaModel,
					        """fill-mask""": DebertaForMaskedLM,
					        """question-answering""": DebertaForQuestionAnswering,
					        """text-classification""": DebertaForSequenceClassification,
					        """token-classification""": DebertaForTokenClassification,
					        """zero-shot""": DebertaForSequenceClassification,
					    }
					    if is_torch_available()
					    else {}
					)

					_A		:			Any						=     True
					_A		:			Dict						=     False
					_A		:			Any						=     False
					_A		:			str						=     False
					_A		:			str						=     False






					def    lowerCAmelCase_				(       self:							Optional[Any]						)   ->	List[str]:
											snake_case_ :Union[str, Any]						=			DebertaModelTester(self						)
											snake_case_ :Union[str, Any]						=			ConfigTester(self						,     config_class=snake_case						,     hidden_size=37						)






					def    lowerCAmelCase_				(       self:							int						)   ->	Dict:
											self.config_tester.run_common_tests()






					def    lowerCAmelCase_				(       self:							Optional[int]						)   ->	List[Any]:
											snake_case_ :Any						=			self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_deberta_model(*snake_case						)






					def    lowerCAmelCase_				(       self:							Tuple						)   ->	Optional[int]:
											snake_case_ :Optional[int]						=			self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_deberta_for_sequence_classification(*snake_case						)






					def    lowerCAmelCase_				(       self:							List[str]						)   ->	str:
											snake_case_ :Optional[Any]						=			self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_deberta_for_masked_lm(*snake_case						)






					def    lowerCAmelCase_				(       self:							Any						)   ->	Any:
											snake_case_ :str						=			self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_deberta_for_question_answering(*snake_case						)






					def    lowerCAmelCase_				(       self:							str						)   ->	int:
											snake_case_ :List[str]						=			self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_deberta_for_token_classification(*snake_case						)






					@slow
					def    lowerCAmelCase_				(       self:							Union[str, Any]						)   ->	Any:
											for model_name in DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																	snake_case_ :Dict						=			DebertaModel.from_pretrained(snake_case						)
																	self.assertIsNotNone(snake_case						)

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






					'''simple docstring'''





					@unittest.skip(reason="""Model not available yet"""						)
					def    lowerCAmelCase_				(       self:							List[str]						)   ->	List[Any]:
											pass






					@slow
					def    lowerCAmelCase_				(       self:							Union[str, Any]						)   ->	Any:
											snake_case_ :Optional[int]						=			DebertaModel.from_pretrained("""microsoft/deberta-base"""						)

											snake_case_ :Tuple						=			torch.tensor([[0, 31_414, 232, 328, 740, 1_140, 12_695, 69, 46_078, 1_588, 2]]						)
											snake_case_ :Optional[Any]						=			torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]						)
											with torch.no_grad():
																	snake_case_ :int						=			model(snake_case						,     attention_mask=snake_case						)[0]
											# compare the actual values for a slice.
											snake_case_ :Union[str, Any]						=			torch.tensor(
											    [[[-0.5_9_8_6, -0.8_0_5_5, -0.8_4_6_2], [1.4_4_8_4, -0.9_3_4_8, -0.8_0_5_9], [0.3_1_2_3, 0.0_0_3_2, -1.4_1_3_1]]]						)
											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

__a      =				10
def    A_  (			_lowercase	):







						'''simple docstring'''


						snake_case_ :Union[str, Any]						=			1
						snake_case_ :List[str]						=			max(_lowercase	)
						while placement <= max_digit:
												# declare and initialize empty buckets
												snake_case_ :list[list]						=			[[] for _ in range(_lowercase	)]
												# split list_of_ints between the buckets
												for i in list_of_ints:
																		snake_case_ :Any						=			int((i / placement) % RADIX	)
																		buckets[tmp].append(_lowercase	)
												# put each buckets' contents into list_of_ints
												snake_case_ :Optional[Any]						=			0
												for b in range(_lowercase	):
																		for i in buckets[b]:
																								snake_case_ :Union[str, Any]						=			i
																								a += 1
        # move to next
												placement *= RADIX
						return list_of_ints


if __name__ == "__main__":
						import doctest

						doctest.testmod()
