


"""simple docstring"""
import unittest

from transformers import SqueezeBertConfig, is_torch_available
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
				import torch

				from transformers import (
				    SQUEEZEBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
				    SqueezeBertForMaskedLM,
				    SqueezeBertForMultipleChoice,
				    SqueezeBertForQuestionAnswering,
				    SqueezeBertForSequenceClassification,
				    SqueezeBertForTokenClassification,
				    SqueezeBertModel,
				)





class        __A       (snake_case__):





				'''simple docstring'''

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



											"""simple docstring"""



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



				def 						lowerCAmelCase    (			self							: Any    )   ->Dict:



											"""simple docstring"""



											snake_case_          =						ids_tensor([self.batch_size, self.seq_length]						,    self.vocab_size    )

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

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

											snake_case_          =						self.get_config()

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



				def 						lowerCAmelCase    (			self							: int    )   ->int:



											"""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							: str						,    UpperCAmelCase_							: Dict						,    UpperCAmelCase_							: Union[str, Any]						,    UpperCAmelCase_							: Dict						,    UpperCAmelCase_							: Any						,    UpperCAmelCase_							: Tuple						,    UpperCAmelCase_							: Dict    )   ->Union[str, Any]:



											"""simple docstring"""



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



				def 						lowerCAmelCase    (			self							: Dict						,    UpperCAmelCase_							: List[Any]						,    UpperCAmelCase_							: Dict						,    UpperCAmelCase_							: int						,    UpperCAmelCase_							: Union[str, Any]						,    UpperCAmelCase_							: Union[str, Any]						,    UpperCAmelCase_							: List[Any]    )   ->Dict:



											"""simple docstring"""



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



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



											"""simple docstring"""



											snake_case_          =						SqueezeBertForQuestionAnswering(config=_SCREAMING_SNAKE_CASE    )
											model.to(_SCREAMING_SNAKE_CASE    )
											model.eval()
											snake_case_          =						model(
											    _SCREAMING_SNAKE_CASE						,    attention_mask=_SCREAMING_SNAKE_CASE						,    start_positions=_SCREAMING_SNAKE_CASE						,    end_positions=_SCREAMING_SNAKE_CASE    )
											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							: Tuple						,    UpperCAmelCase_							: int						,    UpperCAmelCase_							: str						,    UpperCAmelCase_							: int						,    UpperCAmelCase_							: str						,    UpperCAmelCase_							: Dict						,    UpperCAmelCase_							: int    )   ->Optional[Any]:



											"""simple docstring"""



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



				def 						lowerCAmelCase    (			self							: List[Any]						,    UpperCAmelCase_							: Union[str, Any]						,    UpperCAmelCase_							: str						,    UpperCAmelCase_							: Union[str, Any]						,    UpperCAmelCase_							: Union[str, Any]						,    UpperCAmelCase_							: Union[str, Any]						,    UpperCAmelCase_							: str    )   ->Dict:



											"""simple docstring"""



											snake_case_          =						self.num_labels
											snake_case_          =						SqueezeBertForTokenClassification(config=_SCREAMING_SNAKE_CASE    )
											model.to(_SCREAMING_SNAKE_CASE    )
											model.eval()

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



				def 						lowerCAmelCase    (			self							: str						,    UpperCAmelCase_							: Dict						,    UpperCAmelCase_							: Union[str, Any]						,    UpperCAmelCase_							: Any						,    UpperCAmelCase_							: Union[str, Any]						,    UpperCAmelCase_							: Union[str, Any]						,    UpperCAmelCase_							: Union[str, Any]    )   ->Dict:



											"""simple docstring"""



											snake_case_          =						self.num_choices
											snake_case_          =						SqueezeBertForMultipleChoice(config=_SCREAMING_SNAKE_CASE    )
											model.to(_SCREAMING_SNAKE_CASE    )
											model.eval()
											snake_case_          =						input_ids.unsqueeze(1    ).expand(-1						,    self.num_choices						,    -1    ).contiguous()
											snake_case_          =						input_mask.unsqueeze(1    ).expand(-1						,    self.num_choices						,    -1    ).contiguous()
											snake_case_          =						model(
											    _SCREAMING_SNAKE_CASE						,    attention_mask=_SCREAMING_SNAKE_CASE						,    labels=_SCREAMING_SNAKE_CASE						,    )
											self.parent.assertEqual(result.logits.shape						,    (self.batch_size, self.num_choices)    )



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



											"""simple docstring"""



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





@require_torch
class        __A       (snake_case__  ,						snake_case__  ,						unittest.TestCase):





				'''simple docstring'''

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



				def 						lowerCAmelCase    (			self							: Optional[Any]    )   ->List[str]:



											"""simple docstring"""



											snake_case_          =						SqueezeBertModelTester(self    )
											snake_case_          =						ConfigTester(self						,    config_class=_SCREAMING_SNAKE_CASE						,    dim=37    )



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



											"""simple docstring"""



											self.config_tester.run_common_tests()



				def 						lowerCAmelCase    (			self							: str    )   ->Any:



											"""simple docstring"""



											snake_case_          =						self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_squeezebert_model(*_SCREAMING_SNAKE_CASE    )



				def 						lowerCAmelCase    (			self							: Any    )   ->Any:



											"""simple docstring"""



											snake_case_          =						self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_squeezebert_for_masked_lm(*_SCREAMING_SNAKE_CASE    )



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



											"""simple docstring"""



											snake_case_          =						self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_squeezebert_for_question_answering(*_SCREAMING_SNAKE_CASE    )



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



											"""simple docstring"""



											snake_case_          =						self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_squeezebert_for_sequence_classification(*_SCREAMING_SNAKE_CASE    )



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



											"""simple docstring"""



											snake_case_          =						self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_squeezebert_for_token_classification(*_SCREAMING_SNAKE_CASE    )



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



											"""simple docstring"""



											snake_case_          =						self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_squeezebert_for_multiple_choice(*_SCREAMING_SNAKE_CASE    )



				@slow
				def 						lowerCAmelCase    (			self							: List[str]    )   ->Optional[int]:



											"""simple docstring"""



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





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





				'''simple docstring'''

				@slow
				def 						lowerCAmelCase    (			self							: Optional[Any]    )   ->List[Any]:



											"""simple docstring"""



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

											snake_case_          =						torch.tensor([[1, 29_414, 232, 328, 740, 1_140, 12_695, 69, 13, 1_588, 2]]    )
											snake_case_          =						model(_SCREAMING_SNAKE_CASE    )[0]
											snake_case_          =						torch.Size((1, 3)    )
											self.assertEqual(output.shape						,    _SCREAMING_SNAKE_CASE    )
											snake_case_          =						torch.tensor([[0.6_401, -0.0_349, -0.6_041]]    )
											self.assertTrue(torch.allclose(_SCREAMING_SNAKE_CASE						,    _SCREAMING_SNAKE_CASE						,    atol=1E-4    )    )







"""simple docstring"""
from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


__SCREAMING_SNAKE_CASE							:      Dict						=      logging.get_logger(__name__)

__SCREAMING_SNAKE_CASE							:      Tuple						=      {
    'google/mobilenet_v1_1.0_224': 'https://huggingface.co/google/mobilenet_v1_1.0_224/resolve/main/config.json',
    'google/mobilenet_v1_0.75_192': 'https://huggingface.co/google/mobilenet_v1_0.75_192/resolve/main/config.json',
    # See all MobileNetV1 models at https://huggingface.co/models?filter=mobilenet_v1
}





class        __A       (snake_case__):





							'''simple docstring'''

							__lowercase:						List[Any]							 =      """mobilenet_v1"""



							def __init__(			self							: Union[str, Any]						,    UpperCAmelCase_							: str=3						,    UpperCAmelCase_							: List[Any]=224						,    UpperCAmelCase_							: List[Any]=1.0						,    UpperCAmelCase_							: Any=8						,    UpperCAmelCase_							: int="relu6"						,    UpperCAmelCase_							: str=True						,    UpperCAmelCase_							: List[str]=0.999						,    UpperCAmelCase_							: Optional[Any]=0.02						,    UpperCAmelCase_							: List[Any]=0.001						,    **UpperCAmelCase_							: Any						,    )   ->Union[str, Any]:



														"""simple docstring"""



														super().__init__(**UpperCAmelCase_    )

														if depth_multiplier <= 0:
																					raise ValueError("""depth_multiplier must be greater than zero."""    )

														snake_case_          =						num_channels
														snake_case_          =						image_size
														snake_case_          =						depth_multiplier
														snake_case_          =						min_depth
														snake_case_          =						hidden_act
														snake_case_          =						tf_padding
														snake_case_          =						classifier_dropout_prob
														snake_case_          =						initializer_range
														snake_case_          =						layer_norm_eps





class        __A       (snake_case__):





							'''simple docstring'''

							__lowercase:						int							 =      version.parse("""1.11""")



							@property
							def 						lowerCAmelCase    (			self							: Union[str, Any]    )   ->Mapping[str, Mapping[int, str]]:



														"""simple docstring"""



														return OrderedDict([("""pixel_values""", {0: """batch"""})]    )



							@property
							def 						lowerCAmelCase    (			self							: int    )   ->Mapping[str, Mapping[int, str]]:



														"""simple docstring"""



														if self.task == "image-classification":
																					return OrderedDict([("""logits""", {0: """batch"""})]    )
														else:
																					return OrderedDict([("""last_hidden_state""", {0: """batch"""}), ("""pooler_output""", {0: """batch"""})]    )



							@property
							def 						lowerCAmelCase    (			self							: int    )   ->float:



														"""simple docstring"""



														return 1E-4



