


'''simple docstring'''
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       (     snake_case_					):




 '''simple docstring'''


 def __init__(   self   ,   __lowercase   ,   __lowercase=13   ,   __lowercase=7   ,   __lowercase=True   ,   __lowercase=True   ,   __lowercase=False   ,   __lowercase=True   ,   __lowercase=99   ,   __lowercase=32   ,   __lowercase=5   ,   __lowercase=4   ,   __lowercase=64   ,   __lowercase="gelu"   ,   __lowercase=0.1   ,   __lowercase=0.1   ,   __lowercase=512   ,   __lowercase=16   ,   __lowercase=2   ,   __lowercase=0.0_2   ,   __lowercase=3   ,   __lowercase=4   ,   __lowercase=None   ,   __lowercase=2   ,   __lowercase=2   ,   __lowercase=2   ,   __lowercase=2   ,   __lowercase=4   ,   __lowercase=1   ,   ):

  """simple docstring"""







  __A	:		Dict	  =      parent
  __A	:		Union[str, Any]	  =      batch_size
  __A	:		Optional[int]	  =      seq_length
  __A	:		Dict	  =      is_training
  __A	:		List[str]	  =      use_input_mask
  __A	:		str	  =      use_token_type_ids
  __A	:		Dict	  =      use_labels
  __A	:		str	  =      vocab_size
  __A	:		List[Any]	  =      hidden_size
  __A	:		Optional[int]	  =      num_hidden_layers
  __A	:		List[str]	  =      num_attention_heads
  __A	:		List[str]	  =      intermediate_size
  __A	:		List[str]	  =      hidden_act
  __A	:		Dict	  =      hidden_dropout_prob
  __A	:		List[str]	  =      attention_probs_dropout_prob
  __A	:		Any	  =      max_position_embeddings
  __A	:		List[str]	  =      type_vocab_size
  __A	:		Optional[Any]	  =      type_sequence_label_size
  __A	:		Any	  =      initializer_range
  __A	:		Any	  =      num_labels
  __A	:		Union[str, Any]	  =      num_choices
  __A	:		Optional[int]	  =      scope
  __A	:		Optional[Any]	  =      q_groups
  __A	:		Optional[int]	  =      k_groups
  __A	:		Optional[Any]	  =      v_groups
  __A	:		int	  =      post_attention_groups
  __A	:		Any	  =      intermediate_groups
  __A	:		Dict	  =      output_groups


 def 			snake_case__ (   self    ):

  """simple docstring"""







  __A	:		Optional[Any]	  =      ids_tensor([self.batch_size, self.seq_length]   ,   self.vocab_size    )

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

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

  __A	:		List[str]	  =      self.get_config()

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


 def 			snake_case__ (   self    ):

  """simple docstring"""







  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 			snake_case__ (   self   ,   __lowercase   ,   __lowercase   ,   __lowercase   ,   __lowercase   ,   __lowercase   ,   __lowercase    ):

  """simple docstring"""







  __A	:		Optional[Any]	  =      SqueezeBertModel(config=__lowercase    )
  model.to(__lowercase    )
  model.eval()
  __A	:		Optional[Any]	  =      model(__lowercase   ,   __lowercase    )
  __A	:		Union[str, Any]	  =      model(__lowercase    )
  self.parent.assertEqual(result.last_hidden_state.shape   ,   (self.batch_size, self.seq_length, self.hidden_size)    )


 def 			snake_case__ (   self   ,   __lowercase   ,   __lowercase   ,   __lowercase   ,   __lowercase   ,   __lowercase   ,   __lowercase    ):

  """simple docstring"""







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


 def 			snake_case__ (   self   ,   __lowercase   ,   __lowercase   ,   __lowercase   ,   __lowercase   ,   __lowercase   ,   __lowercase    ):

  """simple docstring"""







  __A	:		List[Any]	  =      SqueezeBertForQuestionAnswering(config=__lowercase    )
  model.to(__lowercase    )
  model.eval()
  __A	:		Any	  =      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 			snake_case__ (   self   ,   __lowercase   ,   __lowercase   ,   __lowercase   ,   __lowercase   ,   __lowercase   ,   __lowercase    ):

  """simple docstring"""







  __A	:		Dict	  =      self.num_labels
  __A	:		Any	  =      SqueezeBertForSequenceClassification(__lowercase    )
  model.to(__lowercase    )
  model.eval()
  __A	:		Tuple	  =      model(__lowercase   ,   attention_mask=__lowercase   ,   labels=__lowercase    )
  self.parent.assertEqual(result.logits.shape   ,   (self.batch_size, self.num_labels)    )


 def 			snake_case__ (   self   ,   __lowercase   ,   __lowercase   ,   __lowercase   ,   __lowercase   ,   __lowercase   ,   __lowercase    ):

  """simple docstring"""







  __A	:		int	  =      self.num_labels
  __A	:		Tuple	  =      SqueezeBertForTokenClassification(config=__lowercase    )
  model.to(__lowercase    )
  model.eval()

  __A	:		Optional[Any]	  =      model(__lowercase   ,   attention_mask=__lowercase   ,   labels=__lowercase    )
  self.parent.assertEqual(result.logits.shape   ,   (self.batch_size, self.seq_length, self.num_labels)    )


 def 			snake_case__ (   self   ,   __lowercase   ,   __lowercase   ,   __lowercase   ,   __lowercase   ,   __lowercase   ,   __lowercase    ):

  """simple docstring"""







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







 def 			snake_case__ (   self    ):

  """simple docstring"""







  __A	:		Optional[int]	  =      self.prepare_config_and_inputs()
  ((__A)  ,(__A)  ,(__A)  ,(__A)  ,(__A)  ,(__A))	:		List[str]	  =      config_and_inputs
  __A	:		Tuple	  =      {'input_ids': input_ids, 'attention_mask': input_mask}
  return config, inputs_dict


@require_torch
class     _lowerCamelCase       (     snake_case_     ,		snake_case_     ,		unittest.TestCase					):




 '''simple docstring'''
 __lowercase					:		Tuple     				=    (
     (
         SqueezeBertModel,
         SqueezeBertForMaskedLM,
         SqueezeBertForMultipleChoice,
         SqueezeBertForQuestionAnswering,
         SqueezeBertForSequenceClassification,
         SqueezeBertForTokenClassification,
     )
     if is_torch_available()
     else None
 )
 __lowercase					:		str     				=    (
     {
         '''feature-extraction''': SqueezeBertModel,
         '''fill-mask''': SqueezeBertForMaskedLM,
         '''question-answering''': SqueezeBertForQuestionAnswering,
         '''text-classification''': SqueezeBertForSequenceClassification,
         '''token-classification''': SqueezeBertForTokenClassification,
         '''zero-shot''': SqueezeBertForSequenceClassification,
     }
     if is_torch_available()
     else {}
 )
 __lowercase					:		List[str]     				=    False
 __lowercase					:		List[Any]     				=    True
 __lowercase					:		List[str]     				=    False


 def 			snake_case__ (   self    ):

  """simple docstring"""







  __A	:		List[str]	  =      SqueezeBertModelTester(self    )
  __A	:		Tuple	  =      ConfigTester(self   ,   config_class=__lowercase   ,   dim=37    )


 def 			snake_case__ (   self    ):

  """simple docstring"""







  self.config_tester.run_common_tests()


 def 			snake_case__ (   self    ):

  """simple docstring"""







  __A	:		int	  =      self.model_tester.prepare_config_and_inputs()
  self.model_tester.create_and_check_squeezebert_model(*__lowercase    )


 def 			snake_case__ (   self    ):

  """simple docstring"""







  __A	:		List[str]	  =      self.model_tester.prepare_config_and_inputs()
  self.model_tester.create_and_check_squeezebert_for_masked_lm(*__lowercase    )


 def 			snake_case__ (   self    ):

  """simple docstring"""







  __A	:		Union[str, Any]	  =      self.model_tester.prepare_config_and_inputs()
  self.model_tester.create_and_check_squeezebert_for_question_answering(*__lowercase    )


 def 			snake_case__ (   self    ):

  """simple docstring"""







  __A	:		Any	  =      self.model_tester.prepare_config_and_inputs()
  self.model_tester.create_and_check_squeezebert_for_sequence_classification(*__lowercase    )


 def 			snake_case__ (   self    ):

  """simple docstring"""







  __A	:		Any	  =      self.model_tester.prepare_config_and_inputs()
  self.model_tester.create_and_check_squeezebert_for_token_classification(*__lowercase    )


 def 			snake_case__ (   self    ):

  """simple docstring"""







  __A	:		Optional[int]	  =      self.model_tester.prepare_config_and_inputs()
  self.model_tester.create_and_check_squeezebert_for_multiple_choice(*__lowercase    )







 @slow
 def 			snake_case__ (   self    ):

  """simple docstring"""







  for model_name in SQUEEZEBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
   __A	:		str	  =      SqueezeBertModel.from_pretrained(__lowercase    )
   self.assertIsNotNone(__lowercase    )


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




 '''simple docstring'''


 @slow
 def 			snake_case__ (   self    ):

  """simple docstring"""







  __A	:		List[Any]	  =      SqueezeBertForSequenceClassification.from_pretrained('squeezebert/squeezebert-mnli'    )

  __A	:		Optional[int]	  =      torch.tensor([[1, 29_414, 232, 328, 740, 1_140, 12_695, 69, 13, 1_588, 2]]    )
  __A	:		int	  =      model(__lowercase    )[0]
  __A	:		Tuple	  =      torch.Size((1, 3)    )
  self.assertEqual(output.shape   ,   __lowercase    )
  __A	:		str	  =      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    )    )










'''simple docstring'''
def       _lowercase							(					UpperCamelCase__							:       int,					UpperCamelCase__							:       int      ):
 return 1 if input_a == input_a else 0


def       _lowercase							(					):
 assert xnor_gate(0,					0      ) == 1
 assert xnor_gate(0,					1      ) == 0
 assert xnor_gate(1,					0      ) == 0
 assert xnor_gate(1,					1      ) == 1


if __name__ == "__main__":
 print(xnor_gate(0, 0))
 print(xnor_gate(0, 1))
 print(xnor_gate(1, 0))
 print(xnor_gate(1, 1))






