
import unittest

from transformers import SqueezeBertConfig, 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, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
			import torch

			from transformers import (
			    SQUEEZEBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
			    SqueezeBertForMaskedLM,
			    SqueezeBertForMultipleChoice,
			    SqueezeBertForQuestionAnswering,
			    SqueezeBertForSequenceClassification,
			    SqueezeBertForTokenClassification,
			    SqueezeBertModel,
			)






class  __magic_name__						(  __lowerCAmelCase):
				'''simple docstring'''







				def __init__(							self:   Any		,					_lowerCamelCase:   Any		,					_lowerCamelCase:   str=13		,					_lowerCamelCase:   Any=7		,					_lowerCamelCase:   Optional[Any]=True		,					_lowerCamelCase:   Any=True		,					_lowerCamelCase:   Any=False		,					_lowerCamelCase:   Dict=True		,					_lowerCamelCase:   List[str]=99		,					_lowerCamelCase:   str=32		,					_lowerCamelCase:   Optional[Any]=5		,					_lowerCamelCase:   str=4		,					_lowerCamelCase:   Optional[Any]=64		,					_lowerCamelCase:   Dict="gelu"		,					_lowerCamelCase:   List[Any]=0.1		,					_lowerCamelCase:   List[str]=0.1		,					_lowerCamelCase:   str=5_12		,					_lowerCamelCase:   Tuple=16		,					_lowerCamelCase:   Any=2		,					_lowerCamelCase:   Tuple=0.02		,					_lowerCamelCase:   List[Any]=3		,					_lowerCamelCase:   List[Any]=4		,					_lowerCamelCase:   Tuple=None		,					_lowerCamelCase:   Any=2		,					_lowerCamelCase:   Optional[Any]=2		,					_lowerCamelCase:   int=2		,					_lowerCamelCase:   Tuple=2		,					_lowerCamelCase:   str=4		,					_lowerCamelCase:   List[str]=1		,					):
											SCREAMING_SNAKE_CASE_   	=    parent
											SCREAMING_SNAKE_CASE_   	=    batch_size
											SCREAMING_SNAKE_CASE_   	=    seq_length
											SCREAMING_SNAKE_CASE_   	=    is_training
											SCREAMING_SNAKE_CASE_   	=    use_input_mask
											SCREAMING_SNAKE_CASE_   	=    use_token_type_ids
											SCREAMING_SNAKE_CASE_   	=    use_labels
											SCREAMING_SNAKE_CASE_   	=    vocab_size
											SCREAMING_SNAKE_CASE_   	=    hidden_size
											SCREAMING_SNAKE_CASE_   	=    num_hidden_layers
											SCREAMING_SNAKE_CASE_   	=    num_attention_heads
											SCREAMING_SNAKE_CASE_   	=    intermediate_size
											SCREAMING_SNAKE_CASE_   	=    hidden_act
											SCREAMING_SNAKE_CASE_   	=    hidden_dropout_prob
											SCREAMING_SNAKE_CASE_   	=    attention_probs_dropout_prob
											SCREAMING_SNAKE_CASE_   	=    max_position_embeddings
											SCREAMING_SNAKE_CASE_   	=    type_vocab_size
											SCREAMING_SNAKE_CASE_   	=    type_sequence_label_size
											SCREAMING_SNAKE_CASE_   	=    initializer_range
											SCREAMING_SNAKE_CASE_   	=    num_labels
											SCREAMING_SNAKE_CASE_   	=    num_choices
											SCREAMING_SNAKE_CASE_   	=    scope
											SCREAMING_SNAKE_CASE_   	=    q_groups
											SCREAMING_SNAKE_CASE_   	=    k_groups
											SCREAMING_SNAKE_CASE_   	=    v_groups
											SCREAMING_SNAKE_CASE_   	=    post_attention_groups
											SCREAMING_SNAKE_CASE_   	=    intermediate_groups
											SCREAMING_SNAKE_CASE_   	=    output_groups


				def     _A							(							self:   List[str]		):
											SCREAMING_SNAKE_CASE_   	=    ids_tensor([self.batch_size, self.seq_length]		,					self.vocab_size		)

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

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

											SCREAMING_SNAKE_CASE_   	=    self.get_config()

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


				def     _A							(							self:   int		):
											return SqueezeBertConfig(
											    embedding_size=self.hidden_size		,					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		,					attention_probs_dropout_prob=self.hidden_dropout_prob		,					attention_dropout=self.attention_probs_dropout_prob		,					max_position_embeddings=self.max_position_embeddings		,					initializer_range=self.initializer_range		,					q_groups=self.q_groups		,					k_groups=self.k_groups		,					v_groups=self.v_groups		,					post_attention_groups=self.post_attention_groups		,					intermediate_groups=self.intermediate_groups		,					output_groups=self.output_groups		,					)


				def     _A							(							self:   Optional[int]		,					_lowerCamelCase:   Any		,					_lowerCamelCase:   Union[str, Any]		,					_lowerCamelCase:   int		,					_lowerCamelCase:   Dict		,					_lowerCamelCase:   Tuple		,					_lowerCamelCase:   Union[str, Any]		):
											SCREAMING_SNAKE_CASE_   	=    SqueezeBertModel(config=_UpperCamelCase		)
											model.to(_UpperCamelCase		)
											model.eval()
											SCREAMING_SNAKE_CASE_   	=    model(_UpperCamelCase		,					_UpperCamelCase		)
											SCREAMING_SNAKE_CASE_   	=    model(_UpperCamelCase		)
											self.parent.assertEqual(result.last_hidden_state.shape		,					(self.batch_size, self.seq_length, self.hidden_size)		)


				def     _A							(							self:   int		,					_lowerCamelCase:   List[str]		,					_lowerCamelCase:   List[str]		,					_lowerCamelCase:   Dict		,					_lowerCamelCase:   Dict		,					_lowerCamelCase:   Union[str, Any]		,					_lowerCamelCase:   Tuple		):
											SCREAMING_SNAKE_CASE_   	=    SqueezeBertForMaskedLM(config=_UpperCamelCase		)
											model.to(_UpperCamelCase		)
											model.eval()
											SCREAMING_SNAKE_CASE_   	=    model(_UpperCamelCase		,					attention_mask=_UpperCamelCase		,					labels=_UpperCamelCase		)
											self.parent.assertEqual(result.logits.shape		,					(self.batch_size, self.seq_length, self.vocab_size)		)


				def     _A							(							self:   Tuple		,					_lowerCamelCase:   Tuple		,					_lowerCamelCase:   Tuple		,					_lowerCamelCase:   Tuple		,					_lowerCamelCase:   Optional[Any]		,					_lowerCamelCase:   List[str]		,					_lowerCamelCase:   Any		):
											SCREAMING_SNAKE_CASE_   	=    SqueezeBertForQuestionAnswering(config=_UpperCamelCase		)
											model.to(_UpperCamelCase		)
											model.eval()
											SCREAMING_SNAKE_CASE_   	=    model(
											    _UpperCamelCase		,					attention_mask=_UpperCamelCase		,					start_positions=_UpperCamelCase		,					end_positions=_UpperCamelCase		)
											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     _A							(							self:   Any		,					_lowerCamelCase:   Tuple		,					_lowerCamelCase:   List[str]		,					_lowerCamelCase:   Optional[Any]		,					_lowerCamelCase:   Dict		,					_lowerCamelCase:   Union[str, Any]		,					_lowerCamelCase:   Union[str, Any]		):
											SCREAMING_SNAKE_CASE_   	=    self.num_labels
											SCREAMING_SNAKE_CASE_   	=    SqueezeBertForSequenceClassification(_UpperCamelCase		)
											model.to(_UpperCamelCase		)
											model.eval()
											SCREAMING_SNAKE_CASE_   	=    model(_UpperCamelCase		,					attention_mask=_UpperCamelCase		,					labels=_UpperCamelCase		)
											self.parent.assertEqual(result.logits.shape		,					(self.batch_size, self.num_labels)		)


				def     _A							(							self:   Any		,					_lowerCamelCase:   Any		,					_lowerCamelCase:   Dict		,					_lowerCamelCase:   str		,					_lowerCamelCase:   Dict		,					_lowerCamelCase:   str		,					_lowerCamelCase:   List[str]		):
											SCREAMING_SNAKE_CASE_   	=    self.num_labels
											SCREAMING_SNAKE_CASE_   	=    SqueezeBertForTokenClassification(config=_UpperCamelCase		)
											model.to(_UpperCamelCase		)
											model.eval()

											SCREAMING_SNAKE_CASE_   	=    model(_UpperCamelCase		,					attention_mask=_UpperCamelCase		,					labels=_UpperCamelCase		)
											self.parent.assertEqual(result.logits.shape		,					(self.batch_size, self.seq_length, self.num_labels)		)


				def     _A							(							self:   Optional[Any]		,					_lowerCamelCase:   int		,					_lowerCamelCase:   str		,					_lowerCamelCase:   List[str]		,					_lowerCamelCase:   Dict		,					_lowerCamelCase:   Union[str, Any]		,					_lowerCamelCase:   Union[str, Any]		):
											SCREAMING_SNAKE_CASE_   	=    self.num_choices
											SCREAMING_SNAKE_CASE_   	=    SqueezeBertForMultipleChoice(config=_UpperCamelCase		)
											model.to(_UpperCamelCase		)
											model.eval()
											SCREAMING_SNAKE_CASE_   	=    input_ids.unsqueeze(1		).expand(-1		,					self.num_choices		,					-1		).contiguous()
											SCREAMING_SNAKE_CASE_   	=    input_mask.unsqueeze(1		).expand(-1		,					self.num_choices		,					-1		).contiguous()
											SCREAMING_SNAKE_CASE_   	=    model(
											    _UpperCamelCase		,					attention_mask=_UpperCamelCase		,					labels=_UpperCamelCase		,					)
											self.parent.assertEqual(result.logits.shape		,					(self.batch_size, self.num_choices)		)





				def     _A							(							self:   Any		):
											SCREAMING_SNAKE_CASE_   	=    self.prepare_config_and_inputs()
											(SCREAMING_SNAKE_CASE_)   	=    config_and_inputs
											SCREAMING_SNAKE_CASE_   	=    {"""input_ids""": input_ids, """attention_mask""": input_mask}
											return config, inputs_dict






@require_torch
class  __magic_name__						(  __lowerCAmelCase    ,  __lowerCAmelCase    ,  unittest.TestCase):
				'''simple docstring'''







				SCREAMING_SNAKE_CASE__					:							str	      =					(
				    (
				        SqueezeBertModel,
				        SqueezeBertForMaskedLM,
				        SqueezeBertForMultipleChoice,
				        SqueezeBertForQuestionAnswering,
				        SqueezeBertForSequenceClassification,
				        SqueezeBertForTokenClassification,
				    )
				    if is_torch_available()
				    else None
				)
				SCREAMING_SNAKE_CASE__					:							Any	      =					(
				    {
				        "feature-extraction": SqueezeBertModel,
				        "fill-mask": SqueezeBertForMaskedLM,
				        "question-answering": SqueezeBertForQuestionAnswering,
				        "text-classification": SqueezeBertForSequenceClassification,
				        "token-classification": SqueezeBertForTokenClassification,
				        "zero-shot": SqueezeBertForSequenceClassification,
				    }
				    if is_torch_available()
				    else {}
				)
				SCREAMING_SNAKE_CASE__					:							Dict	      =					False
				SCREAMING_SNAKE_CASE__					:							List[Any]	      =					True
				SCREAMING_SNAKE_CASE__					:							Optional[int]	      =					False


				def     _A							(							self:   int		):
											SCREAMING_SNAKE_CASE_   	=    SqueezeBertModelTester(self		)
											SCREAMING_SNAKE_CASE_   	=    ConfigTester(self		,					config_class=_UpperCamelCase		,					dim=37		)


				def     _A							(							self:   str		):
											self.config_tester.run_common_tests()


				def     _A							(							self:   str		):
											SCREAMING_SNAKE_CASE_   	=    self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_squeezebert_model(*_UpperCamelCase		)


				def     _A							(							self:   Tuple		):
											SCREAMING_SNAKE_CASE_   	=    self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_squeezebert_for_masked_lm(*_UpperCamelCase		)


				def     _A							(							self:   int		):
											SCREAMING_SNAKE_CASE_   	=    self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_squeezebert_for_question_answering(*_UpperCamelCase		)


				def     _A							(							self:   str		):
											SCREAMING_SNAKE_CASE_   	=    self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_squeezebert_for_sequence_classification(*_UpperCamelCase		)


				def     _A							(							self:   List[str]		):
											SCREAMING_SNAKE_CASE_   	=    self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_squeezebert_for_token_classification(*_UpperCamelCase		)


				def     _A							(							self:   Optional[Any]		):
											SCREAMING_SNAKE_CASE_   	=    self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_squeezebert_for_multiple_choice(*_UpperCamelCase		)





				@slow
				def     _A							(							self:   Dict		):


											for model_name in SQUEEZEBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																		SCREAMING_SNAKE_CASE_   	=    SqueezeBertModel.from_pretrained(_UpperCamelCase		)
																		self.assertIsNotNone(_UpperCamelCase		)






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







				@slow
				def     _A							(							self:   Union[str, Any]		):
											SCREAMING_SNAKE_CASE_   	=    SqueezeBertForSequenceClassification.from_pretrained('''squeezebert/squeezebert-mnli'''		)

											SCREAMING_SNAKE_CASE_   	=    torch.tensor([[1, 2_94_14, 2_32, 3_28, 7_40, 11_40, 1_26_95, 69, 13, 15_88, 2]]		)
											SCREAMING_SNAKE_CASE_   	=    model(_UpperCamelCase		)[0]
											SCREAMING_SNAKE_CASE_   	=    torch.Size((1, 3)		)
											self.assertEqual(output.shape		,					_UpperCamelCase		)
											SCREAMING_SNAKE_CASE_   	=    torch.tensor([[0.64_01, -0.03_49, -0.60_41]]		)
											self.assertTrue(torch.allclose(_UpperCamelCase		,					_UpperCamelCase		,					atol=1E-4		)		)








from typing import Any

def 			a   (_lowerCAmelCase     ):
							if not input_list:
														return []
							SCREAMING_SNAKE_CASE_   	=    [input_list.count(_lowerCAmelCase     ) for value in input_list]
							SCREAMING_SNAKE_CASE_   	=    max(_lowerCAmelCase     )  # Gets the maximum count in the input list.
							# Gets values of modes
							return sorted({input_list[i] for i, value in enumerate(_lowerCAmelCase     ) if value == y}     )


if __name__ == "__main__":
			import doctest

			doctest.testmod()


