



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 		lowercase						(			snake_case__):






	"""simple docstring"""


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




	def   _SCREAMING_SNAKE_CASE		(     self     :						Union[str, Any]					)      ->			List[Any]:
							UpperCAmelCase_=       ids_tensor([self.batch_size, self.seq_length]						,  self.vocab_size					)

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

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

							UpperCAmelCase_=       self.get_config()

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




	def   _SCREAMING_SNAKE_CASE		(     self     :						Any					)      ->			Optional[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     :						Tuple						,  __UpperCAmelCase     :						Optional[int]						,  __UpperCAmelCase     :						List[Any]						,  __UpperCAmelCase     :						Tuple						,  __UpperCAmelCase     :						List[Any]						,  __UpperCAmelCase     :						Tuple						,  __UpperCAmelCase     :						Tuple					)      ->			List[Any]:
							UpperCAmelCase_=       SqueezeBertModel(config=__UpperCAmelCase					)
							model.to(__UpperCAmelCase					)
							model.eval()
							UpperCAmelCase_=       model(__UpperCAmelCase						,  __UpperCAmelCase					)
							UpperCAmelCase_=       model(__UpperCAmelCase					)
							self.parent.assertEqual(result.last_hidden_state.shape						,  (self.batch_size, self.seq_length, self.hidden_size)					)




	def   _SCREAMING_SNAKE_CASE		(     self     :						List[Any]						,  __UpperCAmelCase     :						Optional[Any]						,  __UpperCAmelCase     :						Union[str, Any]						,  __UpperCAmelCase     :						Dict						,  __UpperCAmelCase     :						List[Any]						,  __UpperCAmelCase     :						Union[str, Any]						,  __UpperCAmelCase     :						int					)      ->			int:
							UpperCAmelCase_=       SqueezeBertForMaskedLM(config=__UpperCAmelCase					)
							model.to(__UpperCAmelCase					)
							model.eval()
							UpperCAmelCase_=       model(__UpperCAmelCase						,  attention_mask=__UpperCAmelCase						,  labels=__UpperCAmelCase					)
							self.parent.assertEqual(result.logits.shape						,  (self.batch_size, self.seq_length, self.vocab_size)					)




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




	def   _SCREAMING_SNAKE_CASE		(     self     :						Any						,  __UpperCAmelCase     :						List[Any]						,  __UpperCAmelCase     :						str						,  __UpperCAmelCase     :						Optional[Any]						,  __UpperCAmelCase     :						List[str]						,  __UpperCAmelCase     :						Any						,  __UpperCAmelCase     :						Dict					)      ->			Dict:
							UpperCAmelCase_=       self.num_labels
							UpperCAmelCase_=       SqueezeBertForTokenClassification(config=__UpperCAmelCase					)
							model.to(__UpperCAmelCase					)
							model.eval()

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




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




	def   _SCREAMING_SNAKE_CASE		(     self     :						Dict					)      ->			Optional[Any]:
							UpperCAmelCase_=       self.prepare_config_and_inputs()
							((UpperCAmelCase_),       (UpperCAmelCase_),       (UpperCAmelCase_),       (UpperCAmelCase_),       (UpperCAmelCase_),       (UpperCAmelCase_))=       config_and_inputs
							UpperCAmelCase_=       {"""input_ids""": input_ids, """attention_mask""": input_mask}
							return config, inputs_dict






@require_torch
class 		lowercase						(			snake_case__			,   snake_case__			,   unittest.TestCase):






	"""simple docstring"""


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




	def   _SCREAMING_SNAKE_CASE		(     self     :						Union[str, Any]					)      ->			int:
							UpperCAmelCase_=       SqueezeBertModelTester(self					)
							UpperCAmelCase_=       ConfigTester(self						,  config_class=__UpperCAmelCase						,  dim=37					)




	def   _SCREAMING_SNAKE_CASE		(     self     :						Optional[int]					)      ->			Any:
							self.config_tester.run_common_tests()




	def   _SCREAMING_SNAKE_CASE		(     self     :						Optional[int]					)      ->			Tuple:
							UpperCAmelCase_=       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_squeezebert_model(*__UpperCAmelCase					)




	def   _SCREAMING_SNAKE_CASE		(     self     :						Union[str, Any]					)      ->			Any:
							UpperCAmelCase_=       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_squeezebert_for_masked_lm(*__UpperCAmelCase					)




	def   _SCREAMING_SNAKE_CASE		(     self     :						Tuple					)      ->			str:
							UpperCAmelCase_=       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_squeezebert_for_question_answering(*__UpperCAmelCase					)




	def   _SCREAMING_SNAKE_CASE		(     self     :						List[str]					)      ->			int:
							UpperCAmelCase_=       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_squeezebert_for_sequence_classification(*__UpperCAmelCase					)




	def   _SCREAMING_SNAKE_CASE		(     self     :						Dict					)      ->			List[Any]:
							UpperCAmelCase_=       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_squeezebert_for_token_classification(*__UpperCAmelCase					)




	def   _SCREAMING_SNAKE_CASE		(     self     :						int					)      ->			List[Any]:
							UpperCAmelCase_=       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_squeezebert_for_multiple_choice(*__UpperCAmelCase					)




	@slow
	def   _SCREAMING_SNAKE_CASE		(     self     :						Optional[int]					)      ->			Dict:
							for model_name in SQUEEZEBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
													UpperCAmelCase_=       SqueezeBertModel.from_pretrained(__UpperCAmelCase					)
													self.assertIsNotNone(__UpperCAmelCase					)






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






	"""simple docstring"""


	@slow
	def   _SCREAMING_SNAKE_CASE		(     self     :						Optional[int]					)      ->			int:
							UpperCAmelCase_=       SqueezeBertForSequenceClassification.from_pretrained("""squeezebert/squeezebert-mnli"""					)

							UpperCAmelCase_=       torch.tensor([[1, 29_414, 232, 328, 740, 1_140, 12_695, 69, 13, 1_588, 2]]					)
							UpperCAmelCase_=       model(__UpperCAmelCase					)[0]
							UpperCAmelCase_=       torch.Size((1, 3)					)
							self.assertEqual(output.shape						,  __UpperCAmelCase					)
							UpperCAmelCase_=       torch.tensor([[0.6_401, -0.0_349, -0.6_041]]					)
							self.assertTrue(torch.allclose(__UpperCAmelCase						,  __UpperCAmelCase						,  atol=1E-4					)					)









import warnings
from functools import wraps
from typing import Callable



def 	__a					(   lowerCAmelCase_       : Callable    )				->			Callable:






						'''simple docstring'''



						@wraps(lowerCAmelCase_    )
						def _inner_fn(*lowerCAmelCase_       : List[Any]      ,**lowerCAmelCase_       : Tuple    ):
												warnings.warn(
												    (F"""'{fn.__name__}' is experimental and might be subject to breaking changes in the future.""")      ,lowerCAmelCase_      ,)
												return fn(*lowerCAmelCase_      ,**lowerCAmelCase_    )

						return _inner_fn




