





import argparse
import collections
import os
import re
import tempfile

import pandas as pd
from datasets import Dataset
from huggingface_hub import hf_hub_download, upload_folder

from transformers.utils import direct_transformers_import


# All paths are set with the intent you should run this script from the root of the repo with the command
# python utils/update_metadata.py
_lowerCAmelCase				:   Tuple						       =						"src/transformers"


# This is to make sure the transformers module imported is the one in the repo.
_lowerCAmelCase				:   str						       =						direct_transformers_import(TRANSFORMERS_PATH)


# Regexes that match TF/Flax/PT model names.
_lowerCAmelCase				:   Optional[Any]						       =						re.compile(r'''TF(.*)(?:Model|Encoder|Decoder|ForConditionalGeneration)''')
_lowerCAmelCase				:   int						       =						re.compile(r'''Flax(.*)(?:Model|Encoder|Decoder|ForConditionalGeneration)''')
# Will match any TF or Flax model too so need to be in an else branch afterthe two previous regexes.
_lowerCAmelCase				:   List[str]						       =						re.compile(r'''(.*)(?:Model|Encoder|Decoder|ForConditionalGeneration)''')


# Fill this with tuples (pipeline_tag, model_mapping, auto_model)
_lowerCAmelCase				:   Dict						       =						[
    ("pretraining", "MODEL_FOR_PRETRAINING_MAPPING_NAMES", "AutoModelForPreTraining"),
    ("feature-extraction", "MODEL_MAPPING_NAMES", "AutoModel"),
    ("audio-classification", "MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING_NAMES", "AutoModelForAudioClassification"),
    ("text-generation", "MODEL_FOR_CAUSAL_LM_MAPPING_NAMES", "AutoModelForCausalLM"),
    ("automatic-speech-recognition", "MODEL_FOR_CTC_MAPPING_NAMES", "AutoModelForCTC"),
    ("image-classification", "MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING_NAMES", "AutoModelForImageClassification"),
    ("image-segmentation", "MODEL_FOR_IMAGE_SEGMENTATION_MAPPING_NAMES", "AutoModelForImageSegmentation"),
    ("fill-mask", "MODEL_FOR_MASKED_LM_MAPPING_NAMES", "AutoModelForMaskedLM"),
    ("object-detection", "MODEL_FOR_OBJECT_DETECTION_MAPPING_NAMES", "AutoModelForObjectDetection"),
    (
        "zero-shot-object-detection",
        "MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING_NAMES",
        "AutoModelForZeroShotObjectDetection",
    ),
    ("question-answering", "MODEL_FOR_QUESTION_ANSWERING_MAPPING_NAMES", "AutoModelForQuestionAnswering"),
    ("text2text-generation", "MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES", "AutoModelForSeq2SeqLM"),
    ("text-classification", "MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING_NAMES", "AutoModelForSequenceClassification"),
    ("automatic-speech-recognition", "MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING_NAMES", "AutoModelForSpeechSeq2Seq"),
    (
        "table-question-answering",
        "MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING_NAMES",
        "AutoModelForTableQuestionAnswering",
    ),
    ("token-classification", "MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING_NAMES", "AutoModelForTokenClassification"),
    ("multiple-choice", "MODEL_FOR_MULTIPLE_CHOICE_MAPPING_NAMES", "AutoModelForMultipleChoice"),
    (
        "next-sentence-prediction",
        "MODEL_FOR_NEXT_SENTENCE_PREDICTION_MAPPING_NAMES",
        "AutoModelForNextSentencePrediction",
    ),
    (
        "audio-frame-classification",
        "MODEL_FOR_AUDIO_FRAME_CLASSIFICATION_MAPPING_NAMES",
        "AutoModelForAudioFrameClassification",
    ),
    ("audio-xvector", "MODEL_FOR_AUDIO_XVECTOR_MAPPING_NAMES", "AutoModelForAudioXVector"),
    (
        "document-question-answering",
        "MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING_NAMES",
        "AutoModelForDocumentQuestionAnswering",
    ),
    (
        "visual-question-answering",
        "MODEL_FOR_VISUAL_QUESTION_ANSWERING_MAPPING_NAMES",
        "AutoModelForVisualQuestionAnswering",
    ),
    ("image-to-text", "MODEL_FOR_FOR_VISION_2_SEQ_MAPPING_NAMES", "AutoModelForVision2Seq"),
    (
        "zero-shot-image-classification",
        "MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING_NAMES",
        "AutoModelForZeroShotImageClassification",
    ),
    ("depth-estimation", "MODEL_FOR_DEPTH_ESTIMATION_MAPPING_NAMES", "AutoModelForDepthEstimation"),
    ("video-classification", "MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING_NAMES", "AutoModelForVideoClassification"),
    ("mask-generation", "MODEL_FOR_MASK_GENERATION_MAPPING_NAMES", "AutoModelForMaskGeneration"),
]

def   __snake_case    (       _lowerCAmelCase			:			Optional[int]						)			->    Optional[Any]:
   A_       :					Tuple        =      re.finditer(".+?(?:(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])|$)"					,					__lowercase						)
   return [m.group(0						) for m in matches]

def   __snake_case    (       )			->    Union[str, Any]:
   A_       :					Any        =      transformers_module.models.auto.configuration_auto.CONFIG_MAPPING_NAMES
   A_       :					Optional[int]        =      {
       config.replace("Config"					,					""						): model_type for model_type, config in config_maping_names.items()
   }

   # Dictionaries flagging if each model prefix has a backend in PT/TF/Flax.
   A_       :					List[Any]        =      collections.defaultdict(__lowercase						)
   A_       :					Dict        =      collections.defaultdict(__lowercase						)
   A_       :					Dict        =      collections.defaultdict(__lowercase						)

   # Let's lookup through all transformers object (once) and find if models are supported by a given backend.
   for attr_name in dir(__lowercase						):
      A_       :					List[str]        =      None
      if _re_tf_models.match(__lowercase						) is not None:
         A_       :					int        =      tf_models
         A_       :					str        =      _re_tf_models.match(__lowercase						).groups()[0]
      elif _re_flax_models.match(__lowercase						) is not None:
         A_       :					Dict        =      flax_models
         A_       :					str        =      _re_flax_models.match(__lowercase						).groups()[0]
      elif _re_pt_models.match(__lowercase						) is not None:
         A_       :					Union[str, Any]        =      pt_models
         A_       :					str        =      _re_pt_models.match(__lowercase						).groups()[0]

      if lookup_dict is not None:
         while len(__lowercase						) > 0:
            if attr_name in model_prefix_to_model_type:
               A_       :					Dict        =      True
               break
            # Try again after removing the last word in the name
            A_       :					Optional[Any]        =      "".join(camel_case_split(__lowercase						)[:-1]						)

   A_       :					Optional[Any]        =      set(list(pt_models.keys()						) + list(tf_models.keys()						) + list(flax_models.keys()						)						)
   A_       :					Optional[int]        =      list(__lowercase						)
   all_models.sort()

   A_       :					Optional[Any]        =      {"model_type": all_models}
   A_       :					Any        =      [pt_models[t] for t in all_models]
   A_       :					List[str]        =      [tf_models[t] for t in all_models]
   A_       :					Tuple        =      [flax_models[t] for t in all_models]

   # Now let's use the auto-mapping names to make sure
   A_       :					Dict        =      {}
   for t in all_models:
      if t in transformers_module.models.auto.processing_auto.PROCESSOR_MAPPING_NAMES:
         A_       :					str        =      "AutoProcessor"
      elif t in transformers_module.models.auto.tokenization_auto.TOKENIZER_MAPPING_NAMES:
         A_       :					Any        =      "AutoTokenizer"
      elif t in transformers_module.models.auto.feature_extraction_auto.FEATURE_EXTRACTOR_MAPPING_NAMES:
         A_       :					List[Any]        =      "AutoFeatureExtractor"
      else:
         # Default to AutoTokenizer if a model has nothing, for backward compatibility.
         A_       :					List[Any]        =      "AutoTokenizer"

   A_       :					Dict        =      [processors[t] for t in all_models]

   return pd.DataFrame(__lowercase						)

def   __snake_case    (       _lowerCAmelCase			:			Any						)			->    Union[str, Any]:
   A_       :					Any        =      [
       transformers_module.models.auto.modeling_auto,
       transformers_module.models.auto.modeling_tf_auto,
       transformers_module.models.auto.modeling_flax_auto,
   ]
   for pipeline_tag, model_mapping, auto_class in PIPELINE_TAGS_AND_AUTO_MODELS:
      A_       :					List[Any]        =      [model_mapping, f"TF_{model_mapping}", f"FLAX_{model_mapping}"]
      A_       :					str        =      [auto_class, f"TF_{auto_class}", f"Flax_{auto_class}"]
      # Loop through all three frameworks
      for module, cls, mapping in zip(__lowercase					,					__lowercase					,					__lowercase						):
         # The type of pipeline may not exist in this framework
         if not hasattr(__lowercase					,					__lowercase						):
            continue
         # First extract all model_names
         A_       :					List[Any]        =      []
         for name in getattr(__lowercase					,					__lowercase						).values():
            if isinstance(__lowercase					,					__lowercase						):
               model_names.append(__lowercase						)
            else:
               model_names.extend(list(__lowercase						)						)

            # Add pipeline tag and auto model class for those models
         table.update({model_name: (pipeline_tag, cls) for model_name in model_names}						)

   return table

def   __snake_case    (       _lowerCAmelCase			:			Any					,					_lowerCAmelCase			:			List[Any]						)			->    Dict:
   A_       :					List[Any]        =      get_frameworks_table()
   A_       :					str        =      Dataset.from_pandas(__lowercase						)

   A_       :					Optional[Any]        =      hf_hub_download(
       "huggingface/transformers-metadata"					,					"pipeline_tags.json"					,					repo_type="dataset"					,					token=__lowercase						)
   A_       :					List[Any]        =      Dataset.from_json(__lowercase						)
   A_       :					Optional[Any]        =      {
       tags_dataset[i]["model_class"]: (tags_dataset[i]["pipeline_tag"], tags_dataset[i]["auto_class"])
       for i in range(len(__lowercase						)						)
   }
   A_       :					Optional[int]        =      update_pipeline_and_auto_class_table(__lowercase						)

   # Sort the model classes to avoid some nondeterministic updates to create false update commits.
   A_       :					Union[str, Any]        =      sorted(table.keys()						)
   A_       :					Dict        =      pd.DataFrame(
       {
           "model_class": model_classes,
           "pipeline_tag": [table[m][0] for m in model_classes],
           "auto_class": [table[m][1] for m in model_classes],
       }						)
   A_       :					List[str]        =      Dataset.from_pandas(__lowercase						)

   with tempfile.TemporaryDirectory() as tmp_dir:
      frameworks_dataset.to_json(os.path.join(__lowercase					,					"frameworks.json"						)						)
      tags_dataset.to_json(os.path.join(__lowercase					,					"pipeline_tags.json"						)						)

      if commit_sha is not None:
         A_       :					Tuple        =      (
             f"Update with commit {commit_sha}\n\nSee: "
             f"https://github.com/huggingface/transformers/commit/{commit_sha}"
         )
      else:
         A_       :					List[str]        =      "Update"

      upload_folder(
          repo_id="huggingface/transformers-metadata"					,					folder_path=__lowercase					,					repo_type="dataset"					,					token=__lowercase					,					commit_message=__lowercase					,					)

def   __snake_case    (       )			->    Optional[int]:
   A_       :					Tuple        =      {tag: cls for tag, _, cls in PIPELINE_TAGS_AND_AUTO_MODELS}
   A_       :					Optional[int]        =      transformers_module.pipelines.SUPPORTED_TASKS
   A_       :					Dict        =      []
   for key in pipeline_tasks:
      if key not in in_table:
         A_       :					Optional[int]        =      pipeline_tasks[key]["pt"]
         if isinstance(__lowercase					,					(list, tuple)						):
            A_       :					Union[str, Any]        =      model[0]
         A_       :					int        =      model.__name__
         if model not in in_table.values():
            missing.append(__lowercase						)

   if len(__lowercase						) > 0:
      A_       :					List[Any]        =      ", ".join(__lowercase						)
      raise ValueError(
          "The following pipeline tags are not present in the `PIPELINE_TAGS_AND_AUTO_MODELS` constant inside "
          f"`utils/update_metadata.py`: {msg}. Please add them!"						)


if __name__ == "__main__":
 _lowerCAmelCase				:   Optional[Any]						       =						argparse.ArgumentParser()
 parser.add_argument('''--token''', type=str, help='''The token to use to push to the transformers-metadata dataset.''')
 parser.add_argument('''--commit_sha''', type=str, help='''The sha of the commit going with this update.''')
 parser.add_argument('''--check-only''', action='''store_true''', help='''Activate to just check all pipelines are present.''')
 _lowerCAmelCase				:   List[str]						       =						parser.parse_args()

 if args.check_only:
  check_pipeline_tags()
 else:
  update_metadata(args.token, args.commit_sha)








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   (						lowercase_	):







     '''simple docstring'''




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


         """simple docstring"""



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


         """simple docstring"""



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


         """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 		lowerCAmelCase_  (					self							:      Tuple			,						UpperCamelCase_							:      List[Any]			,						UpperCamelCase_							:      int			,						UpperCamelCase_							:      int			,						UpperCamelCase_							:      List[Any]			,						UpperCamelCase_							:      int			,						UpperCamelCase_							:      Dict					):


         """simple docstring"""



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




     def 		lowerCAmelCase_  (					self							:      List[str]			,						UpperCamelCase_							:      Optional[int]			,						UpperCamelCase_							:      str			,						UpperCamelCase_							:      Optional[int]			,						UpperCamelCase_							:      List[str]			,						UpperCamelCase_							:      Union[str, Any]			,						UpperCamelCase_							:      Optional[int]					):


         """simple docstring"""



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




     def 		lowerCAmelCase_  (					self							:      Optional[int]			,						UpperCamelCase_							:      int			,						UpperCamelCase_							:      Optional[Any]			,						UpperCamelCase_							:      Optional[Any]			,						UpperCamelCase_							:      Optional[Any]			,						UpperCamelCase_							:      Union[str, Any]			,						UpperCamelCase_							:      Optional[Any]					):


         """simple docstring"""



         __A       =						SqueezeBertForQuestionAnswering(config=UpperCamelCase_					)
         model.to(UpperCamelCase_					)
         model.eval()
         __A       =						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 		lowerCAmelCase_  (					self							:      str			,						UpperCamelCase_							:      Tuple			,						UpperCamelCase_							:      List[Any]			,						UpperCamelCase_							:      Optional[int]			,						UpperCamelCase_							:      Any			,						UpperCamelCase_							:      List[Any]			,						UpperCamelCase_							:      Any					):


         """simple docstring"""



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




     def 		lowerCAmelCase_  (					self							:      Any			,						UpperCamelCase_							:      Optional[Any]			,						UpperCamelCase_							:      str			,						UpperCamelCase_							:      Dict			,						UpperCamelCase_							:      List[Any]			,						UpperCamelCase_							:      Dict			,						UpperCamelCase_							:      int					):


         """simple docstring"""



         __A       =						self.num_labels
         __A       =						SqueezeBertForTokenClassification(config=UpperCamelCase_					)
         model.to(UpperCamelCase_					)
         model.eval()

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




     def 		lowerCAmelCase_  (					self							:      Tuple			,						UpperCamelCase_							:      List[str]			,						UpperCamelCase_							:      List[Any]			,						UpperCamelCase_							:      List[Any]			,						UpperCamelCase_							:      Tuple			,						UpperCamelCase_							:      Optional[Any]			,						UpperCamelCase_							:      Dict					):


         """simple docstring"""



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





     def 		lowerCAmelCase_  (					self							:      int					):


         """simple docstring"""



         __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    __lowercase   (						lowercase_      ,   lowercase_      ,   unittest.TestCase	):







     '''simple docstring'''
     SCREAMING_SNAKE_CASE     =					(
         (
             SqueezeBertModel,
             SqueezeBertForMaskedLM,
             SqueezeBertForMultipleChoice,
             SqueezeBertForQuestionAnswering,
             SqueezeBertForSequenceClassification,
             SqueezeBertForTokenClassification,
         )
         if is_torch_available()
         else None
     )
     SCREAMING_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 {}
     )
     SCREAMING_SNAKE_CASE     =					False
     SCREAMING_SNAKE_CASE     =					True
     SCREAMING_SNAKE_CASE     =					False




     def 		lowerCAmelCase_  (					self							:      Tuple					):


         """simple docstring"""



         __A       =						SqueezeBertModelTester(self					)
         __A       =						ConfigTester(self			,						config_class=UpperCamelCase_			,						dim=37					)




     def 		lowerCAmelCase_  (					self							:      Optional[Any]					):


         """simple docstring"""



         self.config_tester.run_common_tests()




     def 		lowerCAmelCase_  (					self							:      str					):


         """simple docstring"""



         __A       =						self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_squeezebert_model(*UpperCamelCase_					)




     def 		lowerCAmelCase_  (					self							:      Union[str, Any]					):


         """simple docstring"""



         __A       =						self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_squeezebert_for_masked_lm(*UpperCamelCase_					)




     def 		lowerCAmelCase_  (					self							:      Union[str, Any]					):


         """simple docstring"""



         __A       =						self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_squeezebert_for_question_answering(*UpperCamelCase_					)




     def 		lowerCAmelCase_  (					self							:      Any					):


         """simple docstring"""



         __A       =						self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_squeezebert_for_sequence_classification(*UpperCamelCase_					)




     def 		lowerCAmelCase_  (					self							:      Union[str, Any]					):


         """simple docstring"""



         __A       =						self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_squeezebert_for_token_classification(*UpperCamelCase_					)




     def 		lowerCAmelCase_  (					self							:      Dict					):


         """simple docstring"""



         __A       =						self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_squeezebert_for_multiple_choice(*UpperCamelCase_					)





     @slow
     def 		lowerCAmelCase_  (					self							:      int					):


         """simple docstring"""



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


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







     '''simple docstring'''




     @slow
     def 		lowerCAmelCase_  (					self							:      Optional[int]					):


         """simple docstring"""



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

         __A       =						torch.tensor([[1, 29_414, 232, 328, 740, 1_140, 12_695, 69, 13, 1_588, 2]]					)
         __A       =						model(UpperCamelCase_					)[0]
         __A       =						torch.Size((1, 3)					)
         self.assertEqual(output.shape			,						UpperCamelCase_					)
         __A       =						torch.tensor([[0.6401, -0.0349, -0.6041]]					)
         self.assertTrue(torch.allclose(UpperCamelCase_			,						UpperCamelCase_			,						atol=1e-4					)					)




