



import argparse
import json
import os

import fairseq
import torch
from fairseq.data import Dictionary

from transformers import (
    UniSpeechConfig,
    UniSpeechForCTC,
    UniSpeechForPreTraining,
    WavaVecaFeatureExtractor,
    WavaVecaPhonemeCTCTokenizer,
    WavaVecaProcessor,
    logging,
)


logging.set_verbosity_info()
a_								=       logging.get_logger(__name__)

a_								=       {
    """post_extract_proj""": """feature_projection.projection""",
    """encoder.pos_conv.0""": """encoder.pos_conv_embed.conv""",
    """self_attn.k_proj""": """encoder.layers.*.attention.k_proj""",
    """self_attn.v_proj""": """encoder.layers.*.attention.v_proj""",
    """self_attn.q_proj""": """encoder.layers.*.attention.q_proj""",
    """self_attn.out_proj""": """encoder.layers.*.attention.out_proj""",
    """self_attn_layer_norm""": """encoder.layers.*.layer_norm""",
    """fc1""": """encoder.layers.*.feed_forward.intermediate_dense""",
    """fc2""": """encoder.layers.*.feed_forward.output_dense""",
    """final_layer_norm""": """encoder.layers.*.final_layer_norm""",
    """encoder.layer_norm""": """encoder.layer_norm""",
    """w2v_model.layer_norm""": """feature_projection.layer_norm""",
    """quantizer.weight_proj""": """quantizer.weight_proj""",
    """quantizer.vars""": """quantizer.codevectors""",
    """project_q""": """project_q""",
    """final_proj""": """project_hid""",
    """w2v_encoder.proj""": """ctc_proj""",
    """mask_emb""": """masked_spec_embed""",
}
a_								=       [
    """ctc_proj""",
    """quantizer.weight_proj""",
    """quantizer.codevectors""",
    """project_q""",
    """project_hid""",
]





def 		a__      (		_UpperCamelCase      :			List[Any]			,_UpperCamelCase      :			str			,_UpperCamelCase      :			Tuple			,_UpperCamelCase      :			str			,_UpperCamelCase      :			int			,_UpperCamelCase      :			Optional[Any]				):
   for attribute in key.split('''.'''				):
      if is_finetuned:
         if attribute in ["quantizer", "project_q", "project_hid"]:
            # those layers are only relevant for pretraining and should be dropped
            return

         if attribute == "ctc_proj":
            # we should rename `ctc_proj` to `lm_head` for fine-tuned phoneme models
            __lowerCamelCase    				=     '''lm_head'''

      __lowerCamelCase    				=     getattr(_UpperCamelCase			,_UpperCamelCase				)

   if weight_type is not None:
      __lowerCamelCase    				=     getattr(_UpperCamelCase			,_UpperCamelCase				).shape
   else:
      __lowerCamelCase    				=     hf_pointer.shape

   assert hf_shape == value.shape, (
       F"""Shape of hf {key + "." + weight_type if weight_type is not None else ""} is {hf_shape}, but should be"""
       F""" {value.shape} for {full_name}"""
   )

   if weight_type == "weight":
      __lowerCamelCase    				=     value
   elif weight_type == "weight_g":
      __lowerCamelCase    				=     value
   elif weight_type == "weight_v":
      __lowerCamelCase    				=     value
   elif weight_type == "bias":
      __lowerCamelCase    				=     value
   else:
      __lowerCamelCase    				=     value

   logger.info(F"""{key + "." + weight_type if weight_type is not None else ""} was initialized from {full_name}."""				)





def 		a__      (		_UpperCamelCase      :			Any			,_UpperCamelCase      :			Optional[int]			,_UpperCamelCase      :			Tuple				):
   __lowerCamelCase    				=     []
   __lowerCamelCase    				=     fairseq_model.state_dict()

   __lowerCamelCase    				=     hf_model.unispeech.feature_extractor

   for name, value in fairseq_dict.items():
      __lowerCamelCase    				=     False
      if "conv_layers" in name:
         load_conv_layer(
             _UpperCamelCase			,_UpperCamelCase			,_UpperCamelCase			,_UpperCamelCase			,hf_model.config.feat_extract_norm == '''group'''			,)
         __lowerCamelCase    				=     True
      else:
         for key, mapped_key in MAPPING.items():
            __lowerCamelCase    				=     '''unispeech.''' + mapped_key if mapped_key not in TOP_LEVEL_KEYS else mapped_key
            if key in name or key.split('''w2v_model.'''				)[-1] == name.split('''.'''				)[0]:
               __lowerCamelCase    				=     True
               if "*" in mapped_key:
                  __lowerCamelCase    				=     name.split(_UpperCamelCase				)[0].split('''.'''				)[-2]
                  __lowerCamelCase    				=     mapped_key.replace('''*'''			,_UpperCamelCase				)
               if "weight_g" in name:
                  __lowerCamelCase    				=     '''weight_g'''
               elif "weight_v" in name:
                  __lowerCamelCase    				=     '''weight_v'''
               elif "bias" in name:
                  __lowerCamelCase    				=     '''bias'''
               elif "weight" in name:
                  # TODO: don't match quantizer.weight_proj
                  __lowerCamelCase    				=     '''weight'''
               else:
                  __lowerCamelCase    				=     None
               set_recursively(_UpperCamelCase			,_UpperCamelCase			,_UpperCamelCase			,_UpperCamelCase			,_UpperCamelCase			,_UpperCamelCase				)
            continue
      if not is_used:
         unused_weights.append(_UpperCamelCase				)

   logger.warning(F"""Unused weights: {unused_weights}"""				)





def 		a__      (		_UpperCamelCase      :			List[str]			,_UpperCamelCase      :			Tuple			,_UpperCamelCase      :			Any			,_UpperCamelCase      :			Optional[int]			,_UpperCamelCase      :			Dict				):
   __lowerCamelCase    				=     full_name.split('''conv_layers.'''				)[-1]
   __lowerCamelCase    				=     name.split('''.'''				)
   __lowerCamelCase    				=     int(items[0]				)
   __lowerCamelCase    				=     int(items[1]				)

   if type_id == 0:
      if "bias" in name:
         assert value.shape == feature_extractor.conv_layers[layer_id].conv.bias.data.shape, (
             F"""{full_name} has size {value.shape}, but"""
             F""" {feature_extractor.conv_layers[layer_id].conv.bias.data.shape} was found."""
         )
         __lowerCamelCase    				=     value
         logger.info(F"""Feat extract conv layer {layer_id} was initialized from {full_name}."""				)
      elif "weight" in name:
         assert value.shape == feature_extractor.conv_layers[layer_id].conv.weight.data.shape, (
             F"""{full_name} has size {value.shape}, but"""
             F""" {feature_extractor.conv_layers[layer_id].conv.weight.data.shape} was found."""
         )
         __lowerCamelCase    				=     value
         logger.info(F"""Feat extract conv layer {layer_id} was initialized from {full_name}."""				)
   elif (type_id == 2 and not use_group_norm) or (type_id == 2 and layer_id == 0 and use_group_norm):
      if "bias" in name:
         assert value.shape == feature_extractor.conv_layers[layer_id].layer_norm.bias.data.shape, (
             F"""{full_name} has size {value.shape}, but {feature_extractor[layer_id].layer_norm.bias.data.shape} was"""
             " found."
         )
         __lowerCamelCase    				=     value
         logger.info(F"""Feat extract layer norm weight of layer {layer_id} was initialized from {full_name}."""				)
      elif "weight" in name:
         assert value.shape == feature_extractor.conv_layers[layer_id].layer_norm.weight.data.shape, (
             F"""{full_name} has size {value.shape}, but"""
             F""" {feature_extractor[layer_id].layer_norm.weight.data.shape} was found."""
         )
         __lowerCamelCase    				=     value
         logger.info(F"""Feat extract layer norm weight of layer {layer_id} was initialized from {full_name}."""				)
   else:
      unused_weights.append(_UpperCamelCase				)





@torch.no_grad()
def 		a__      (		_UpperCamelCase      :			List[Any]			,_UpperCamelCase      :			Any			,_UpperCamelCase      :			Any=None			,_UpperCamelCase      :			str=None			,_UpperCamelCase      :			Tuple=True				):
   if config_path is not None:
      __lowerCamelCase    				=     UniSpeechConfig.from_pretrained(_UpperCamelCase				)
   else:
      __lowerCamelCase    				=     UniSpeechConfig()

   if is_finetuned:
      if dict_path:
         __lowerCamelCase    				=     Dictionary.load_from_json(_UpperCamelCase				)

         # important change bos & pad token id since CTC symbol is <pad> and
         # not <s> as in fairseq
         __lowerCamelCase    				=     target_dict.pad_index
         __lowerCamelCase    				=     target_dict.bos_index
         __lowerCamelCase    				=     target_dict.eos_index
         __lowerCamelCase    				=     len(target_dict.symbols				)
         __lowerCamelCase    				=     os.path.join(_UpperCamelCase			,'''vocab.json'''				)
         if not os.path.isdir(_UpperCamelCase				):
            logger.error('''--pytorch_dump_folder_path ({}) should be a directory'''.format(_UpperCamelCase				)				)
            return
         os.makedirs(_UpperCamelCase			,exist_ok=_UpperCamelCase				)
         __lowerCamelCase    				=     target_dict.indices

         # fairseq has the <pad> and <s> switched
         __lowerCamelCase    				=     42
         __lowerCamelCase    				=     43
         with open(_UpperCamelCase			,'''w'''			,encoding='''utf-8'''				) as vocab_handle:
            json.dump(_UpperCamelCase			,_UpperCamelCase				)
         __lowerCamelCase    				=     WavaVecaPhonemeCTCTokenizer(
             _UpperCamelCase			,unk_token=target_dict.unk_word			,pad_token=target_dict.pad_word			,bos_token=target_dict.bos_word			,eos_token=target_dict.eos_word			,word_delimiter_token='''|'''			,do_lower_case=_UpperCamelCase			,)
         __lowerCamelCase    				=     True if config.feat_extract_norm == '''layer''' else False
         __lowerCamelCase    				=     WavaVecaFeatureExtractor(
             feature_size=1			,sampling_rate=1_60_00			,padding_value=0			,do_normalize=_UpperCamelCase			,return_attention_mask=_UpperCamelCase			,)
         __lowerCamelCase    				=     WavaVecaProcessor(feature_extractor=_UpperCamelCase			,tokenizer=_UpperCamelCase				)
         processor.save_pretrained(_UpperCamelCase				)

      __lowerCamelCase    				=     UniSpeechForCTC(_UpperCamelCase				)
   else:
      __lowerCamelCase    				=     UniSpeechForPreTraining(_UpperCamelCase				)

   if is_finetuned:
      __lowerCamelCase				,__lowerCamelCase				,__lowerCamelCase    				=     fairseq.checkpoint_utils.load_model_ensemble_and_task(
          [checkpoint_path]			,arg_overrides={'''data''': '''/'''.join(dict_path.split('''/'''				)[:-1]				), '''w2v_path''': checkpoint_path}				)
   else:
      __lowerCamelCase				,__lowerCamelCase				,__lowerCamelCase    				=     fairseq.checkpoint_utils.load_model_ensemble_and_task([checkpoint_path]				)

   __lowerCamelCase    				=     model[0].eval()

   recursively_load_weights(_UpperCamelCase			,_UpperCamelCase			,_UpperCamelCase				)

   hf_unispeech.save_pretrained(_UpperCamelCase				)


if __name__ == "__main__":
  a_								=       argparse.ArgumentParser()
  parser.add_argument("""--pytorch_dump_folder_path""", default=None, type=str, help="""Path to the output PyTorch model.""")
  parser.add_argument("""--checkpoint_path""", default=None, type=str, help="""Path to fairseq checkpoint""")
  parser.add_argument("""--dict_path""", default=None, type=str, help="""Path to dict of fine-tuned model""")
  parser.add_argument("""--config_path""", default=None, type=str, help="""Path to hf config.json of model to convert""")
  parser.add_argument(
      """--not_finetuned""", action="""store_true""", help="""Whether the model to convert is a fine-tuned model or not"""
  )
  a_								=       parser.parse_args()
  convert_unispeech_checkpoint(
      args.checkpoint_path, args.pytorch_dump_folder_path, args.config_path, args.dict_path, not args.not_finetuned
  )











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




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



    '''simple docstring'''
    __lowerCamelCase    				=     parent
    __lowerCamelCase    				=     batch_size
    __lowerCamelCase    				=     seq_length
    __lowerCamelCase    				=     is_training
    __lowerCamelCase    				=     use_input_mask
    __lowerCamelCase    				=     use_token_type_ids
    __lowerCamelCase    				=     use_labels
    __lowerCamelCase    				=     vocab_size
    __lowerCamelCase    				=     hidden_size
    __lowerCamelCase    				=     num_hidden_layers
    __lowerCamelCase    				=     num_attention_heads
    __lowerCamelCase    				=     intermediate_size
    __lowerCamelCase    				=     hidden_act
    __lowerCamelCase    				=     hidden_dropout_prob
    __lowerCamelCase    				=     attention_probs_dropout_prob
    __lowerCamelCase    				=     max_position_embeddings
    __lowerCamelCase    				=     type_vocab_size
    __lowerCamelCase    				=     type_sequence_label_size
    __lowerCamelCase    				=     initializer_range
    __lowerCamelCase    				=     num_labels
    __lowerCamelCase    				=     num_choices
    __lowerCamelCase    				=     scope
    __lowerCamelCase    				=     q_groups
    __lowerCamelCase    				=     k_groups
    __lowerCamelCase    				=     v_groups
    __lowerCamelCase    				=     post_attention_groups
    __lowerCamelCase    				=     intermediate_groups
    __lowerCamelCase    				=     output_groups




 def 							lowerCamelCase   (    self					):



    '''simple docstring'''
    __lowerCamelCase    				=     ids_tensor([self.batch_size, self.seq_length]						,					self.vocab_size					)

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

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

    __lowerCamelCase    				=     self.get_config()

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




 def 							lowerCamelCase   (    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 							lowerCamelCase   (    self						,					__UpperCAmelCase						,					__UpperCAmelCase						,					__UpperCAmelCase						,					__UpperCAmelCase						,					__UpperCAmelCase						,					__UpperCAmelCase					):



    '''simple docstring'''
    __lowerCamelCase    				=     SqueezeBertModel(config=__UpperCAmelCase					)
    model.to(__UpperCAmelCase					)
    model.eval()
    __lowerCamelCase    				=     model(__UpperCAmelCase						,					__UpperCAmelCase					)
    __lowerCamelCase    				=     model(__UpperCAmelCase					)
    self.parent.assertEqual(result.last_hidden_state.shape						,					(self.batch_size, self.seq_length, self.hidden_size)					)




 def 							lowerCamelCase   (    self						,					__UpperCAmelCase						,					__UpperCAmelCase						,					__UpperCAmelCase						,					__UpperCAmelCase						,					__UpperCAmelCase						,					__UpperCAmelCase					):



    '''simple docstring'''
    __lowerCamelCase    				=     SqueezeBertForMaskedLM(config=__UpperCAmelCase					)
    model.to(__UpperCAmelCase					)
    model.eval()
    __lowerCamelCase    				=     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						,					__UpperCAmelCase						,					__UpperCAmelCase						,					__UpperCAmelCase						,					__UpperCAmelCase						,					__UpperCAmelCase						,					__UpperCAmelCase					):



    '''simple docstring'''
    __lowerCamelCase    				=     SqueezeBertForQuestionAnswering(config=__UpperCAmelCase					)
    model.to(__UpperCAmelCase					)
    model.eval()
    __lowerCamelCase    				=     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						,					__UpperCAmelCase						,					__UpperCAmelCase						,					__UpperCAmelCase						,					__UpperCAmelCase						,					__UpperCAmelCase						,					__UpperCAmelCase					):



    '''simple docstring'''
    __lowerCamelCase    				=     self.num_labels
    __lowerCamelCase    				=     SqueezeBertForSequenceClassification(__UpperCAmelCase					)
    model.to(__UpperCAmelCase					)
    model.eval()
    __lowerCamelCase    				=     model(__UpperCAmelCase						,					attention_mask=__UpperCAmelCase						,					labels=__UpperCAmelCase					)
    self.parent.assertEqual(result.logits.shape						,					(self.batch_size, self.num_labels)					)




 def 							lowerCamelCase   (    self						,					__UpperCAmelCase						,					__UpperCAmelCase						,					__UpperCAmelCase						,					__UpperCAmelCase						,					__UpperCAmelCase						,					__UpperCAmelCase					):



    '''simple docstring'''
    __lowerCamelCase    				=     self.num_labels
    __lowerCamelCase    				=     SqueezeBertForTokenClassification(config=__UpperCAmelCase					)
    model.to(__UpperCAmelCase					)
    model.eval()

    __lowerCamelCase    				=     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						,					__UpperCAmelCase						,					__UpperCAmelCase						,					__UpperCAmelCase						,					__UpperCAmelCase						,					__UpperCAmelCase						,					__UpperCAmelCase					):



    '''simple docstring'''
    __lowerCamelCase    				=     self.num_choices
    __lowerCamelCase    				=     SqueezeBertForMultipleChoice(config=__UpperCAmelCase					)
    model.to(__UpperCAmelCase					)
    model.eval()
    __lowerCamelCase    				=     input_ids.unsqueeze(1					).expand(-1						,					self.num_choices						,					-1					).contiguous()
    __lowerCamelCase    				=     input_mask.unsqueeze(1					).expand(-1						,					self.num_choices						,					-1					).contiguous()
    __lowerCamelCase    				=     model(
        __UpperCAmelCase						,					attention_mask=__UpperCAmelCase						,					labels=__UpperCAmelCase						,					)
    self.parent.assertEqual(result.logits.shape						,					(self.batch_size, self.num_choices)					)




 def 							lowerCamelCase   (    self					):



    '''simple docstring'''
    __lowerCamelCase    				=     self.prepare_config_and_inputs()
    ((__lowerCamelCase)				,(__lowerCamelCase)				,(__lowerCamelCase)				,(__lowerCamelCase)				,(__lowerCamelCase)				,(__lowerCamelCase))    				=     config_and_inputs
    __lowerCamelCase    				=     {'''input_ids''': input_ids, '''attention_mask''': input_mask}
    return config, inputs_dict



@require_torch
class 			__lowerCAmelCase  (						lowerCAmelCase__	,						lowerCAmelCase__	,						unittest.TestCase ):
 lowerCAmelCase__							       =	(
     (
         SqueezeBertModel,
         SqueezeBertForMaskedLM,
         SqueezeBertForMultipleChoice,
         SqueezeBertForQuestionAnswering,
         SqueezeBertForSequenceClassification,
         SqueezeBertForTokenClassification,
     )
     if is_torch_available()
     else None
 )
 lowerCAmelCase__							       =	(
     {
         """feature-extraction""": SqueezeBertModel,
         """fill-mask""": SqueezeBertForMaskedLM,
         """question-answering""": SqueezeBertForQuestionAnswering,
         """text-classification""": SqueezeBertForSequenceClassification,
         """token-classification""": SqueezeBertForTokenClassification,
         """zero-shot""": SqueezeBertForSequenceClassification,
     }
     if is_torch_available()
     else {}
 )
 lowerCAmelCase__							       =	False
 lowerCAmelCase__							       =	True
 lowerCAmelCase__							       =	False




 def 							lowerCamelCase   (    self					):



    '''simple docstring'''
    __lowerCamelCase    				=     SqueezeBertModelTester(self					)
    __lowerCamelCase    				=     ConfigTester(self						,					config_class=__UpperCAmelCase						,					dim=37					)




 def 							lowerCamelCase   (    self					):



    '''simple docstring'''
    self.config_tester.run_common_tests()




 def 							lowerCamelCase   (    self					):



    '''simple docstring'''
    __lowerCamelCase    				=     self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_squeezebert_model(*__UpperCAmelCase					)




 def 							lowerCamelCase   (    self					):



    '''simple docstring'''
    __lowerCamelCase    				=     self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_squeezebert_for_masked_lm(*__UpperCAmelCase					)




 def 							lowerCamelCase   (    self					):



    '''simple docstring'''
    __lowerCamelCase    				=     self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_squeezebert_for_question_answering(*__UpperCAmelCase					)




 def 							lowerCamelCase   (    self					):



    '''simple docstring'''
    __lowerCamelCase    				=     self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_squeezebert_for_sequence_classification(*__UpperCAmelCase					)




 def 							lowerCamelCase   (    self					):



    '''simple docstring'''
    __lowerCamelCase    				=     self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_squeezebert_for_token_classification(*__UpperCAmelCase					)




 def 							lowerCamelCase   (    self					):



    '''simple docstring'''
    __lowerCamelCase    				=     self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_squeezebert_for_multiple_choice(*__UpperCAmelCase					)




 @slow
 def 							lowerCamelCase   (    self					):



    '''simple docstring'''
    for model_name in SQUEEZEBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
       __lowerCamelCase    				=     SqueezeBertModel.from_pretrained(__UpperCAmelCase					)
       self.assertIsNotNone(__UpperCAmelCase					)



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




 @slow
 def 							lowerCamelCase   (    self					):



    '''simple docstring'''
    __lowerCamelCase    				=     SqueezeBertForSequenceClassification.from_pretrained('''squeezebert/squeezebert-mnli'''					)

    __lowerCamelCase    				=     torch.tensor([[1, 29414, 232, 328, 740, 1140, 12695, 69, 13, 1588, 2]]					)
    __lowerCamelCase    				=     model(__UpperCAmelCase					)[0]
    __lowerCamelCase    				=     torch.Size((1, 3)					)
    self.assertEqual(output.shape						,					__UpperCAmelCase					)
    __lowerCamelCase    				=     torch.tensor([[0.6_401, -0.0_349, -0.6_041]]					)
    self.assertTrue(torch.allclose(__UpperCAmelCase						,					__UpperCAmelCase						,					atol=1E-4					)					)






