





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__   (				lowerCAmelCase_       ):



     '''simple docstring'''

     def __init__(							self						:   Any						,lowerCamelCase__						:   Optional[int]						,lowerCamelCase__						:   List[Any]=13						,lowerCamelCase__						:   List[Any]=7						,lowerCamelCase__						:   Any=True						,lowerCamelCase__						:   Any=True						,lowerCamelCase__						:   str=False						,lowerCamelCase__						:   int=True						,lowerCamelCase__						:   List[str]=99						,lowerCamelCase__						:   str=32						,lowerCamelCase__						:   List[Any]=5						,lowerCamelCase__						:   Union[str, Any]=4						,lowerCamelCase__						:   Optional[int]=64						,lowerCamelCase__						:   Tuple="gelu"						,lowerCamelCase__						:   str=0.1						,lowerCamelCase__						:   Union[str, Any]=0.1						,lowerCamelCase__						:   Union[str, Any]=512						,lowerCamelCase__						:   Optional[int]=16						,lowerCamelCase__						:   Dict=2						,lowerCamelCase__						:   str=0.02						,lowerCamelCase__						:   Any=3						,lowerCamelCase__						:   Dict=4						,lowerCamelCase__						:   Any=None						,lowerCamelCase__						:   Union[str, Any]=2						,lowerCamelCase__						:   str=2						,lowerCamelCase__						:   Optional[int]=2						,lowerCamelCase__						:   Any=2						,lowerCamelCase__						:   Any=4						,lowerCamelCase__						:   int=1						,)					->		Optional[Any]:




           '''simple docstring'''


           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     SCREAMING_SNAKE_CASE__  (							self						:   str	)					->		List[str]:




           '''simple docstring'''


           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     SCREAMING_SNAKE_CASE__  (							self						:   List[Any]	)					->		Tuple:




           '''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     SCREAMING_SNAKE_CASE__  (							self						:   Dict						,lowerCamelCase__						:   Any						,lowerCamelCase__						:   Optional[Any]						,lowerCamelCase__						:   str						,lowerCamelCase__						:   str						,lowerCamelCase__						:   int						,lowerCamelCase__						:   str	)					->		Union[str, Any]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						SqueezeBertModel(config=lowerCamelCase__	)
           model.to(lowerCamelCase__	)
           model.eval()
           SCREAMING_SNAKE_CASE		=						model(lowerCamelCase__						,lowerCamelCase__	)
           SCREAMING_SNAKE_CASE		=						model(lowerCamelCase__	)
           self.parent.assertEqual(result.last_hidden_state.shape						,(self.batch_size, self.seq_length, self.hidden_size)	)






     def     SCREAMING_SNAKE_CASE__  (							self						:   Union[str, Any]						,lowerCamelCase__						:   Optional[Any]						,lowerCamelCase__						:   Optional[Any]						,lowerCamelCase__						:   List[Any]						,lowerCamelCase__						:   Optional[Any]						,lowerCamelCase__						:   Optional[Any]						,lowerCamelCase__						:   Any	)					->		Dict:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						SqueezeBertForMaskedLM(config=lowerCamelCase__	)
           model.to(lowerCamelCase__	)
           model.eval()
           SCREAMING_SNAKE_CASE		=						model(lowerCamelCase__						,attention_mask=lowerCamelCase__						,labels=lowerCamelCase__	)
           self.parent.assertEqual(result.logits.shape						,(self.batch_size, self.seq_length, self.vocab_size)	)






     def     SCREAMING_SNAKE_CASE__  (							self						:   Tuple						,lowerCamelCase__						:   List[str]						,lowerCamelCase__						:   str						,lowerCamelCase__						:   Union[str, Any]						,lowerCamelCase__						:   List[str]						,lowerCamelCase__						:   Dict						,lowerCamelCase__						:   Optional[Any]	)					->		Optional[int]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						SqueezeBertForQuestionAnswering(config=lowerCamelCase__	)
           model.to(lowerCamelCase__	)
           model.eval()
           SCREAMING_SNAKE_CASE		=						model(
               lowerCamelCase__						,attention_mask=lowerCamelCase__						,start_positions=lowerCamelCase__						,end_positions=lowerCamelCase__	)
           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						:   str						,lowerCamelCase__						:   Union[str, Any]						,lowerCamelCase__						:   Dict						,lowerCamelCase__						:   Union[str, Any]						,lowerCamelCase__						:   Any						,lowerCamelCase__						:   Union[str, Any]						,lowerCamelCase__						:   Union[str, Any]	)					->		Tuple:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						self.num_labels
           SCREAMING_SNAKE_CASE		=						SqueezeBertForSequenceClassification(lowerCamelCase__	)
           model.to(lowerCamelCase__	)
           model.eval()
           SCREAMING_SNAKE_CASE		=						model(lowerCamelCase__						,attention_mask=lowerCamelCase__						,labels=lowerCamelCase__	)
           self.parent.assertEqual(result.logits.shape						,(self.batch_size, self.num_labels)	)






     def     SCREAMING_SNAKE_CASE__  (							self						:   Optional[int]						,lowerCamelCase__						:   Optional[int]						,lowerCamelCase__						:   Dict						,lowerCamelCase__						:   List[Any]						,lowerCamelCase__						:   Any						,lowerCamelCase__						:   Dict						,lowerCamelCase__						:   Optional[int]	)					->		Any:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						self.num_labels
           SCREAMING_SNAKE_CASE		=						SqueezeBertForTokenClassification(config=lowerCamelCase__	)
           model.to(lowerCamelCase__	)
           model.eval()

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






     def     SCREAMING_SNAKE_CASE__  (							self						:   str						,lowerCamelCase__						:   Optional[Any]						,lowerCamelCase__						:   int						,lowerCamelCase__						:   List[Any]						,lowerCamelCase__						:   int						,lowerCamelCase__						:   str						,lowerCamelCase__						:   Optional[int]	)					->		List[str]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						self.num_choices
           SCREAMING_SNAKE_CASE		=						SqueezeBertForMultipleChoice(config=lowerCamelCase__	)
           model.to(lowerCamelCase__	)
           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(
               lowerCamelCase__						,attention_mask=lowerCamelCase__						,labels=lowerCamelCase__						,)
           self.parent.assertEqual(result.logits.shape						,(self.batch_size, self.num_choices)	)






     def     SCREAMING_SNAKE_CASE__  (							self						:   List[str]	)					->		int:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						self.prepare_config_and_inputs()
           ((SCREAMING_SNAKE_CASE), (SCREAMING_SNAKE_CASE), (SCREAMING_SNAKE_CASE), (SCREAMING_SNAKE_CASE), (SCREAMING_SNAKE_CASE), (SCREAMING_SNAKE_CASE))		=						config_and_inputs
           SCREAMING_SNAKE_CASE		=						{"""input_ids""": input_ids, """attention_mask""": input_mask}
           return config, inputs_dict

@require_torch
class 		UpperCamelCase__   (				lowerCAmelCase_							,				lowerCAmelCase_							,				unittest.TestCase       ):



     '''simple docstring'''

     __snake_case   :     str		     =      (
         (
             SqueezeBertModel,
             SqueezeBertForMaskedLM,
             SqueezeBertForMultipleChoice,
             SqueezeBertForQuestionAnswering,
             SqueezeBertForSequenceClassification,
             SqueezeBertForTokenClassification,
         )
         if is_torch_available()
         else None
     )
     __snake_case   :     List[str]		     =      (
         {
             "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   :     Dict		     =      False
     __snake_case   :     List[Any]		     =      True
     __snake_case   :     Union[str, Any]		     =      False






     def     SCREAMING_SNAKE_CASE__  (							self						:   Dict	)					->		int:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						SqueezeBertModelTester(self	)
           SCREAMING_SNAKE_CASE		=						ConfigTester(self						,config_class=lowerCamelCase__						,dim=37	)






     def     SCREAMING_SNAKE_CASE__  (							self						:   Optional[Any]	)					->		Optional[int]:




           '''simple docstring'''


           self.config_tester.run_common_tests()






     def     SCREAMING_SNAKE_CASE__  (							self						:   str	)					->		Dict:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_squeezebert_model(*lowerCamelCase__	)






     def     SCREAMING_SNAKE_CASE__  (							self						:   Optional[Any]	)					->		Dict:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_squeezebert_for_masked_lm(*lowerCamelCase__	)






     def     SCREAMING_SNAKE_CASE__  (							self						:   Optional[int]	)					->		List[str]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_squeezebert_for_question_answering(*lowerCamelCase__	)






     def     SCREAMING_SNAKE_CASE__  (							self						:   str	)					->		Tuple:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_squeezebert_for_sequence_classification(*lowerCamelCase__	)






     def     SCREAMING_SNAKE_CASE__  (							self						:   int	)					->		Optional[Any]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_squeezebert_for_token_classification(*lowerCamelCase__	)






     def     SCREAMING_SNAKE_CASE__  (							self						:   Optional[int]	)					->		Dict:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_squeezebert_for_multiple_choice(*lowerCamelCase__	)






     @slow
     def     SCREAMING_SNAKE_CASE__  (							self						:   Dict	)					->		Optional[int]:




           '''simple docstring'''


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

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



     '''simple docstring'''

     @slow
     def     SCREAMING_SNAKE_CASE__  (							self						:   List[str]	)					->		Tuple:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						SqueezeBertForSequenceClassification.from_pretrained("""squeezebert/squeezebert-mnli"""	)

           SCREAMING_SNAKE_CASE		=						torch.tensor([[1, 29414, 232, 328, 740, 1140, 12695, 69, 13, 1588, 2]]	)
           SCREAMING_SNAKE_CASE		=						model(lowerCamelCase__	)[0]
           SCREAMING_SNAKE_CASE		=						torch.Size((1, 3)	)
           self.assertEqual(output.shape						,lowerCamelCase__	)
           SCREAMING_SNAKE_CASE		=						torch.tensor([[0.6401, -0.0349, -0.6041]]	)
           self.assertTrue(torch.allclose(lowerCamelCase__						,lowerCamelCase__						,atol=1e-4	)	)









from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tokenizers_available, is_torch_available


SCREAMING_SNAKE_CASE_						       =	{
    """configuration_mvp""": ["""MVP_PRETRAINED_CONFIG_ARCHIVE_MAP""", """MvpConfig""", """MvpOnnxConfig"""],
    """tokenization_mvp""": ["""MvpTokenizer"""],
}

try:
      if not is_tokenizers_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      SCREAMING_SNAKE_CASE_						       =	["""MvpTokenizerFast"""]

try:
      if not is_torch_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      SCREAMING_SNAKE_CASE_						       =	[
          """MVP_PRETRAINED_MODEL_ARCHIVE_LIST""",
          """MvpForCausalLM""",
          """MvpForConditionalGeneration""",
          """MvpForQuestionAnswering""",
          """MvpForSequenceClassification""",
          """MvpModel""",
          """MvpPreTrainedModel""",
      ]

if TYPE_CHECKING:
      from .configuration_mvp import MVP_PRETRAINED_CONFIG_ARCHIVE_MAP, MvpConfig, MvpOnnxConfig
      from .tokenization_mvp import MvpTokenizer

      try:
            if not is_tokenizers_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .tokenization_mvp_fast import MvpTokenizerFast

      try:
            if not is_torch_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_mvp import (
                MVP_PRETRAINED_MODEL_ARCHIVE_LIST,
                MvpForCausalLM,
                MvpForConditionalGeneration,
                MvpForQuestionAnswering,
                MvpForSequenceClassification,
                MvpModel,
                MvpPreTrainedModel,
            )

else:
      import sys

      SCREAMING_SNAKE_CASE_						       =	_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)


