






"""simple docstring"""







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					:							Dict    =						logging.get_logger(__name__)

a					:							Tuple    =						{
    """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					:							Tuple    =						[
    """ctc_proj""",
    """quantizer.weight_proj""",
    """quantizer.codevectors""",
    """project_q""",
    """project_hid""",
]





def 		lowercase__(A   ,						A   ,						A   ,						A   ,						A   ,						A		)							->Union[str, Any]:




						"""simple docstring"""



						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
																								lowercase__							: Union[str, Any]=			"lm_head"

												lowercase__							: Any=			getattr(A   ,						A		)

						if weight_type is not None:
												lowercase__							: Optional[int]=			getattr(A   ,						A		).shape
						else:
												lowercase__							: Optional[Any]=			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":
												lowercase__							: Union[str, Any]=			value
						elif weight_type == "weight_g":
												lowercase__							: List[Any]=			value
						elif weight_type == "weight_v":
												lowercase__							: List[str]=			value
						elif weight_type == "bias":
												lowercase__							: Optional[Any]=			value
						else:
												lowercase__							: Union[str, Any]=			value

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





def 		lowercase__(A   ,						A   ,						A		)							->Dict:




						"""simple docstring"""



						lowercase__							: Any=			[]
						lowercase__							: int=			fairseq_model.state_dict()

						lowercase__							: List[str]=			hf_model.unispeech.feature_extractor

						for name, value in fairseq_dict.items():
												lowercase__							: List[str]=			False
												if "conv_layers" in name:
																		load_conv_layer(
																		    A   ,						A   ,						A   ,						A   ,						hf_model.config.feat_extract_norm == "group"   ,						)
																		lowercase__							: List[Any]=			True
												else:
																		for key, mapped_key in MAPPING.items():
																								lowercase__							: List[str]=			"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]:
																														lowercase__							: int=			True
																														if "*" in mapped_key:
																																				lowercase__							: Optional[int]=			name.split(A		)[0].split("."		)[-2]
																																				lowercase__							: List[Any]=			mapped_key.replace("*"   ,						A		)
																														if "weight_g" in name:
																																				lowercase__							: str=			"weight_g"
																														elif "weight_v" in name:
																																				lowercase__							: List[Any]=			"weight_v"
																														elif "bias" in name:
																																				lowercase__							: str=			"bias"
																														elif "weight" in name:
																																				# TODO: don't match quantizer.weight_proj
																																				lowercase__							: List[str]=			"weight"
																														else:
																																				lowercase__							: Tuple=			None
																														set_recursively(A   ,						A   ,						A   ,						A   ,						A   ,						A		)
																								continue
												if not is_used:
																		unused_weights.append(A		)

						logger.warning(f'''Unused weights: {unused_weights}'''		)





def 		lowercase__(A   ,						A   ,						A   ,						A   ,						A		)							->int:




						"""simple docstring"""



						lowercase__							: int=			full_name.split("conv_layers."		)[-1]
						lowercase__							: Optional[int]=			name.split("."		)
						lowercase__							: int=			int(items[0]		)
						lowercase__							: List[Any]=			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.'''
																		)
																		lowercase__							: Tuple=			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.'''
																		)
																		lowercase__							: Tuple=			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."
																		)
																		lowercase__							: Dict=			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.'''
																		)
																		lowercase__							: Union[str, Any]=			value
																		logger.info(f'''Feat extract layer norm weight of layer {layer_id} was initialized from {full_name}.'''		)
						else:
												unused_weights.append(A		)





@torch.no_grad()
def 		lowercase__(A   ,						A   ,						A=None   ,						A=None   ,						A=True		)							->List[Any]:




						"""simple docstring"""



						if config_path is not None:
												lowercase__							: Dict=			UniSpeechConfig.from_pretrained(A		)
						else:
												lowercase__							: Union[str, Any]=			UniSpeechConfig()

						if is_finetuned:
												if dict_path:
																		lowercase__							: Dict=			Dictionary.load_from_json(A		)

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

																		# fairseq has the <pad> and <s> switched
																		lowercase__							: Tuple=			42
																		lowercase__							: Union[str, Any]=			43
																		with open(A   ,						"w"   ,						encoding="utf-8"		) as vocab_handle:
																								json.dump(A   ,						A		)
																		lowercase__							: Optional[Any]=			WavaVecaPhonemeCTCTokenizer(
																		    A   ,						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=A   ,						)
																		lowercase__							: Any=			True if config.feat_extract_norm == "layer" else False
																		lowercase__							: List[Any]=			WavaVecaFeatureExtractor(
																		    feature_size=1   ,						sampling_rate=16_000   ,						padding_value=0   ,						do_normalize=A   ,						return_attention_mask=A   ,						)
																		lowercase__							: Optional[int]=			WavaVecaProcessor(feature_extractor=A   ,						tokenizer=A		)
																		processor.save_pretrained(A		)

												lowercase__							: Dict=			UniSpeechForCTC(A		)
						else:
												lowercase__							: Dict=			UniSpeechForPreTraining(A		)

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

						lowercase__							: Any=			model[0].eval()

						recursively_load_weights(A   ,						A   ,						A		)

						hf_unispeech.save_pretrained(A		)


if __name__ == "__main__":
			a					:							Optional[int]    =						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					:							Dict    =						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      :int   ,     lowercase      :Optional[Any]   ,     lowercase      :Optional[int]=1_3   ,     lowercase      :Any=7   ,     lowercase      :Tuple=True   ,     lowercase      :Optional[int]=True   ,     lowercase      :Any=False   ,     lowercase      :Any=True   ,     lowercase      :Dict=9_9   ,     lowercase      :Dict=3_2   ,     lowercase      :Any=5   ,     lowercase      :Optional[Any]=4   ,     lowercase      :List[str]=6_4   ,     lowercase      :Optional[int]="gelu"   ,     lowercase      :int=0.1   ,     lowercase      :str=0.1   ,     lowercase      :List[str]=5_1_2   ,     lowercase      :int=1_6   ,     lowercase      :Any=2   ,     lowercase      :Union[str, Any]=0.02   ,     lowercase      :Optional[int]=3   ,     lowercase      :Optional[Any]=4   ,     lowercase      :Tuple=None   ,     lowercase      :int=2   ,     lowercase      :Tuple=2   ,     lowercase      :List[Any]=2   ,     lowercase      :Optional[int]=2   ,     lowercase      :Tuple=4   ,     lowercase      :int=1   ,     )		->      Union[str, 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  snake_case__     (     self      :str			)		->      Dict:







				"""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  snake_case__     (     self      :str			)		->      Dict:







				"""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      :Optional[Any]   ,     lowercase      :Optional[Any]   ,     lowercase      :int   ,     lowercase      :Any   ,     lowercase      :List[str]   ,     lowercase      :Optional[Any]   ,     lowercase      :List[str]			)		->      str:







				"""simple docstring"""






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







	def  snake_case__     (     self      :Dict   ,     lowercase      :Dict   ,     lowercase      :List[Any]   ,     lowercase      :str   ,     lowercase      :Union[str, Any]   ,     lowercase      :Dict   ,     lowercase      :List[Any]			)		->      str:







				"""simple docstring"""






				SCREAMING_SNAKE_CASE     						= SqueezeBertForMaskedLM(config=lowercase			)
				model.to(lowercase			)
				model.eval()
				SCREAMING_SNAKE_CASE     						= 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      :List[str]   ,     lowercase      :Optional[Any]   ,     lowercase      :Optional[int]   ,     lowercase      :str   ,     lowercase      :int   ,     lowercase      :Optional[Any]   ,     lowercase      :int			)		->      List[str]:







				"""simple docstring"""






				SCREAMING_SNAKE_CASE     						= SqueezeBertForQuestionAnswering(config=lowercase			)
				model.to(lowercase			)
				model.eval()
				SCREAMING_SNAKE_CASE     						= 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      :Any   ,     lowercase      :Optional[Any]   ,     lowercase      :List[str]   ,     lowercase      :int   ,     lowercase      :Any   ,     lowercase      :Optional[int]   ,     lowercase      :List[str]			)		->      Any:







				"""simple docstring"""






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







	def  snake_case__     (     self      :str   ,     lowercase      :List[Any]   ,     lowercase      :List[str]   ,     lowercase      :Optional[int]   ,     lowercase      :Tuple   ,     lowercase      :Tuple   ,     lowercase      :str			)		->      str:







				"""simple docstring"""






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

				SCREAMING_SNAKE_CASE     						= 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      :int   ,     lowercase      :List[str]   ,     lowercase      :List[Any]   ,     lowercase      :Tuple   ,     lowercase      :str   ,     lowercase      :Optional[Any]   ,     lowercase      :Optional[int]			)		->      Union[str, Any]:







				"""simple docstring"""






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







	def  snake_case__     (     self      :List[str]			)		->      Union[str, Any]:







				"""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     lowerCamelCase      (       __lowerCamelCase ,		__lowerCamelCase ,		unittest.TestCase					):
	UpperCamelCase_  :					int    		=	(
	    (
	        SqueezeBertModel,
	        SqueezeBertForMaskedLM,
	        SqueezeBertForMultipleChoice,
	        SqueezeBertForQuestionAnswering,
	        SqueezeBertForSequenceClassification,
	        SqueezeBertForTokenClassification,
	    )
	    if is_torch_available()
	    else None
	)
	UpperCamelCase_  :					int    		=	(
	    {
	        'feature-extraction': SqueezeBertModel,
	        'fill-mask': SqueezeBertForMaskedLM,
	        'question-answering': SqueezeBertForQuestionAnswering,
	        'text-classification': SqueezeBertForSequenceClassification,
	        'token-classification': SqueezeBertForTokenClassification,
	        'zero-shot': SqueezeBertForSequenceClassification,
	    }
	    if is_torch_available()
	    else {}
	)
	UpperCamelCase_  :					Tuple    		=	False
	UpperCamelCase_  :					int    		=	True
	UpperCamelCase_  :					List[Any]    		=	False







	def  snake_case__     (     self      :Tuple			)		->      int:







				"""simple docstring"""






				SCREAMING_SNAKE_CASE     						= SqueezeBertModelTester(self			)
				SCREAMING_SNAKE_CASE     						= ConfigTester(self   ,     config_class=lowercase   ,     dim=3_7			)







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







				"""simple docstring"""






				self.config_tester.run_common_tests()







	def  snake_case__     (     self      :Union[str, Any]			)		->      int:







				"""simple docstring"""






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







	def  snake_case__     (     self      :Any			)		->      int:







				"""simple docstring"""






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







	def  snake_case__     (     self      :List[str]			)		->      List[str]:







				"""simple docstring"""






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







	def  snake_case__     (     self      :Any			)		->      Union[str, Any]:







				"""simple docstring"""






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







	def  snake_case__     (     self      :Union[str, Any]			)		->      Optional[int]:







				"""simple docstring"""






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







	def  snake_case__     (     self      :Union[str, Any]			)		->      Union[str, Any]:







				"""simple docstring"""






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







	@slow
	def  snake_case__     (     self      :Dict			)		->      str:







				"""simple docstring"""






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





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







	@slow
	def  snake_case__     (     self      :Any			)		->      int:







				"""simple docstring"""






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

				SCREAMING_SNAKE_CASE     						= torch.tensor([[1, 2_9_4_1_4, 2_3_2, 3_2_8, 7_4_0, 1_1_4_0, 1_2_6_9_5, 6_9, 1_3, 1_5_8_8, 2]]			)
				SCREAMING_SNAKE_CASE     						= model(lowercase			)[0]
				SCREAMING_SNAKE_CASE     						= torch.Size((1, 3)			)
				self.assertEqual(output.shape   ,     lowercase			)
				SCREAMING_SNAKE_CASE     						= torch.tensor([[0.64_01, -0.03_49, -0.60_41]]			)
				self.assertTrue(torch.allclose(lowercase   ,     lowercase   ,     atol=1e-4			)			)