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




	'''simple docstring'''





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






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

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

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

					__A   			= self.get_config()

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






	def 				UpperCamelCase_  (       self					: str ):
					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 				UpperCamelCase_  (       self					: int							,A					: List[str]							,A					: Any							,A					: int							,A					: str							,A					: int							,A					: str ):
					__A   			= SqueezeBertModel(config=A )
					model.to(A )
					model.eval()
					__A   			= model(A							,A )
					__A   			= model(A )
					self.parent.assertEqual(result.last_hidden_state.shape							,(self.batch_size, self.seq_length, self.hidden_size) )






	def 				UpperCamelCase_  (       self					: str							,A					: Any							,A					: Any							,A					: Optional[int]							,A					: int							,A					: int							,A					: Union[str, Any] ):
					__A   			= SqueezeBertForMaskedLM(config=A )
					model.to(A )
					model.eval()
					__A   			= model(A							,attention_mask=A							,labels=A )
					self.parent.assertEqual(result.logits.shape							,(self.batch_size, self.seq_length, self.vocab_size) )






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






	def 				UpperCamelCase_  (       self					: Dict							,A					: Tuple							,A					: int							,A					: Any							,A					: Union[str, Any]							,A					: Union[str, Any]							,A					: Any ):
					__A   			= self.num_labels
					__A   			= SqueezeBertForTokenClassification(config=A )
					model.to(A )
					model.eval()

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






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







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





@require_torch
class 							UpperCAmelCase      (  __SCREAMING_SNAKE_CASE			,			__SCREAMING_SNAKE_CASE			,			unittest.TestCase  ):




	'''simple docstring'''





	snake_case_					    =     (
	    (
	        SqueezeBertModel,
	        SqueezeBertForMaskedLM,
	        SqueezeBertForMultipleChoice,
	        SqueezeBertForQuestionAnswering,
	        SqueezeBertForSequenceClassification,
	        SqueezeBertForTokenClassification,
	    )
	    if is_torch_available()
	    else None
	)
	snake_case_					    =     (
	    {
	        "feature-extraction": SqueezeBertModel,
	        "fill-mask": SqueezeBertForMaskedLM,
	        "question-answering": SqueezeBertForQuestionAnswering,
	        "text-classification": SqueezeBertForSequenceClassification,
	        "token-classification": SqueezeBertForTokenClassification,
	        "zero-shot": SqueezeBertForSequenceClassification,
	    }
	    if is_torch_available()
	    else {}
	)
	snake_case_					    =     False
	snake_case_					    =     True
	snake_case_					    =     False






	def 				UpperCamelCase_  (       self					: str ):
					__A   			= SqueezeBertModelTester(self )
					__A   			= ConfigTester(self							,config_class=A							,dim=37 )






	def 				UpperCamelCase_  (       self					: Union[str, Any] ):
					self.config_tester.run_common_tests()






	def 				UpperCamelCase_  (       self					: Dict ):
					__A   			= self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_squeezebert_model(*A )






	def 				UpperCamelCase_  (       self					: Optional[Any] ):
					__A   			= self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_squeezebert_for_masked_lm(*A )






	def 				UpperCamelCase_  (       self					: int ):
					__A   			= self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_squeezebert_for_question_answering(*A )






	def 				UpperCamelCase_  (       self					: Dict ):
					__A   			= self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_squeezebert_for_sequence_classification(*A )






	def 				UpperCamelCase_  (       self					: Optional[int] ):
					__A   			= self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_squeezebert_for_token_classification(*A )






	def 				UpperCamelCase_  (       self					: List[str] ):
					__A   			= self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_squeezebert_for_multiple_choice(*A )







	@slow
	def 				UpperCamelCase_  (       self					: List[str] ):
					for model_name in SQUEEZEBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
									__A   			= SqueezeBertModel.from_pretrained(A )
									self.assertIsNotNone(A )





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




	'''simple docstring'''





	@slow
	def 				UpperCamelCase_  (       self					: int ):
					__A   			= SqueezeBertForSequenceClassification.from_pretrained("squeezebert/squeezebert-mnli" )

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


def 						UpperCAmelCase			(	a_						)		->	list:







				"""simple docstring"""



				if len(a_						) <= 1:
								return [tuple(a_						)]

				__A   			= []

				def generate(a_		,   a_						):
								if k == 1:
												res.append(tuple(arr[:]						)						)
												return

								generate(k - 1		,   a_						)

								for i in range(k - 1						):
												if k % 2 == 0:  # k is even
																__A			,							__A   			= arr[k - 1], arr[i]
												else:  # k is odd
																__A			,							__A   			= arr[k - 1], arr[0]
												generate(k - 1		,   a_						)

				generate(len(a_						)		,   a_						)
				return res


if __name__ == "__main__":
					SCREAMING_SNAKE_CASE							:int							 =				input('Enter numbers separated by a comma:\n').strip()
					SCREAMING_SNAKE_CASE							:Dict							 =				[int(item) for item in user_input.split(',')]
					print(heaps(arr))
