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        lowerCamelCase__				(   UpperCAmelCase				):





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





			def   SCREAMING_SNAKE_CASE__     (       self	:	Any						):
										_lowerCAmelCase							=							ids_tensor([self.batch_size, self.seq_length]  ,  self.vocab_size						)

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

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

										_lowerCAmelCase							=							self.get_config()

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





			def   SCREAMING_SNAKE_CASE__     (       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   SCREAMING_SNAKE_CASE__     (       self	:	int  ,  lowercase__	:	Dict  ,  lowercase__	:	Any  ,  lowercase__	:	str  ,  lowercase__	:	Optional[Any]  ,  lowercase__	:	Any  ,  lowercase__	:	Tuple						):
										_lowerCAmelCase							=							SqueezeBertModel(config=lowercase__						)
										model.to(lowercase__						)
										model.eval()
										_lowerCAmelCase							=							model(lowercase__  ,  lowercase__						)
										_lowerCAmelCase							=							model(lowercase__						)
										self.parent.assertEqual(result.last_hidden_state.shape  ,  (self.batch_size, self.seq_length, self.hidden_size)						)





			def   SCREAMING_SNAKE_CASE__     (       self	:	List[Any]  ,  lowercase__	:	Union[str, Any]  ,  lowercase__	:	Union[str, Any]  ,  lowercase__	:	int  ,  lowercase__	:	List[Any]  ,  lowercase__	:	Dict  ,  lowercase__	:	Union[str, Any]						):
										_lowerCAmelCase							=							SqueezeBertForMaskedLM(config=lowercase__						)
										model.to(lowercase__						)
										model.eval()
										_lowerCAmelCase							=							model(lowercase__  ,  attention_mask=lowercase__  ,  labels=lowercase__						)
										self.parent.assertEqual(result.logits.shape  ,  (self.batch_size, self.seq_length, self.vocab_size)						)





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





			def   SCREAMING_SNAKE_CASE__     (       self	:	Optional[Any]  ,  lowercase__	:	Union[str, Any]  ,  lowercase__	:	str  ,  lowercase__	:	Dict  ,  lowercase__	:	Tuple  ,  lowercase__	:	Any  ,  lowercase__	:	Optional[int]						):
										_lowerCAmelCase							=							self.num_labels
										_lowerCAmelCase							=							SqueezeBertForTokenClassification(config=lowercase__						)
										model.to(lowercase__						)
										model.eval()

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





			def   SCREAMING_SNAKE_CASE__     (       self	:	List[str]  ,  lowercase__	:	Optional[int]  ,  lowercase__	:	Tuple  ,  lowercase__	:	List[Any]  ,  lowercase__	:	Optional[int]  ,  lowercase__	:	Tuple  ,  lowercase__	:	Any						):
										_lowerCAmelCase							=							self.num_choices
										_lowerCAmelCase							=							SqueezeBertForMultipleChoice(config=lowercase__						)
										model.to(lowercase__						)
										model.eval()
										_lowerCAmelCase							=							input_ids.unsqueeze(1						).expand(-1  ,  self.num_choices  ,  -1						).contiguous()
										_lowerCAmelCase							=							input_mask.unsqueeze(1						).expand(-1  ,  self.num_choices  ,  -1						).contiguous()
										_lowerCAmelCase							=							model(
										    lowercase__  ,  attention_mask=lowercase__  ,  labels=lowercase__  ,  )
										self.parent.assertEqual(result.logits.shape  ,  (self.batch_size, self.num_choices)						)





			def   SCREAMING_SNAKE_CASE__     (       self	:	List[Any]						):
										_lowerCAmelCase							=							self.prepare_config_and_inputs()
										((_lowerCAmelCase)			,		(_lowerCAmelCase)			,		(_lowerCAmelCase)			,		(_lowerCAmelCase)			,		(_lowerCAmelCase)			,		(_lowerCAmelCase))							=							config_and_inputs
										_lowerCAmelCase							=							{'input_ids': input_ids, 'attention_mask': input_mask}
										return config, inputs_dict







@require_torch
class        lowerCamelCase__				(   UpperCAmelCase       ,UpperCAmelCase       ,unittest.TestCase				):
			UpperCamelCase__    							=(
			    (
			        SqueezeBertModel,
			        SqueezeBertForMaskedLM,
			        SqueezeBertForMultipleChoice,
			        SqueezeBertForQuestionAnswering,
			        SqueezeBertForSequenceClassification,
			        SqueezeBertForTokenClassification,
			    )
			    if is_torch_available()
			    else None
			)
			UpperCamelCase__    							=(
			    {
			        "feature-extraction": SqueezeBertModel,
			        "fill-mask": SqueezeBertForMaskedLM,
			        "question-answering": SqueezeBertForQuestionAnswering,
			        "text-classification": SqueezeBertForSequenceClassification,
			        "token-classification": SqueezeBertForTokenClassification,
			        "zero-shot": SqueezeBertForSequenceClassification,
			    }
			    if is_torch_available()
			    else {}
			)
			UpperCamelCase__    							=False
			UpperCamelCase__    							=True
			UpperCamelCase__    							=False





			def   SCREAMING_SNAKE_CASE__     (       self	:	List[Any]						):
										_lowerCAmelCase							=							SqueezeBertModelTester(self						)
										_lowerCAmelCase							=							ConfigTester(self  ,  config_class=lowercase__  ,  dim=37						)





			def   SCREAMING_SNAKE_CASE__     (       self	:	Optional[Any]						):
										self.config_tester.run_common_tests()





			def   SCREAMING_SNAKE_CASE__     (       self	:	Dict						):
										_lowerCAmelCase							=							self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_squeezebert_model(*lowercase__						)





			def   SCREAMING_SNAKE_CASE__     (       self	:	Tuple						):
										_lowerCAmelCase							=							self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_squeezebert_for_masked_lm(*lowercase__						)





			def   SCREAMING_SNAKE_CASE__     (       self	:	List[str]						):
										_lowerCAmelCase							=							self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_squeezebert_for_question_answering(*lowercase__						)





			def   SCREAMING_SNAKE_CASE__     (       self	:	Any						):
										_lowerCAmelCase							=							self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_squeezebert_for_sequence_classification(*lowercase__						)





			def   SCREAMING_SNAKE_CASE__     (       self	:	Any						):
										_lowerCAmelCase							=							self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_squeezebert_for_token_classification(*lowercase__						)





			def   SCREAMING_SNAKE_CASE__     (       self	:	Dict						):
										_lowerCAmelCase							=							self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_squeezebert_for_multiple_choice(*lowercase__						)





			@slow
			def   SCREAMING_SNAKE_CASE__     (       self	:	int						):
										for model_name in SQUEEZEBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																	_lowerCAmelCase							=							SqueezeBertModel.from_pretrained(lowercase__						)
																	self.assertIsNotNone(lowercase__						)







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





			@slow
			def   SCREAMING_SNAKE_CASE__     (       self	:	Dict						):
										_lowerCAmelCase							=							SqueezeBertForSequenceClassification.from_pretrained('squeezebert/squeezebert-mnli'						)

										_lowerCAmelCase							=							torch.tensor([[1, 2_94_14, 2_32, 3_28, 7_40, 11_40, 1_26_95, 69, 13, 15_88, 2]]						)
										_lowerCAmelCase							=							model(lowercase__						)[0]
										_lowerCAmelCase							=							torch.Size((1, 3)						)
										self.assertEqual(output.shape  ,  lowercase__						)
										_lowerCAmelCase							=							torch.tensor([[0.6_4_0_1, -0.0_3_4_9, -0.6_0_4_1]]						)
										self.assertTrue(torch.allclose(lowercase__  ,  lowercase__  ,  atol=1e-4						)						)







def _lowerCamelCase  (		snake_case = 10  ):
							if not isinstance(snake_case     , snake_case  ) or n < 0:
														raise ValueError('Invalid input'  )
							_lowerCAmelCase							=							10**n
							_lowerCAmelCase							=							28_433 * (pow(2     , 7_830_457     , snake_case  )) + 1
							return str(number % modulus  )


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

				testmod()
				print(f"""{solution(1_0) = }""")






