

"""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       lowerCamelCase  (_UpperCamelCase	):

			def __init__(    self :  Optional[Any]			, __UpperCAmelCase :  List[Any]			, __UpperCAmelCase :  Optional[int]=1_3			, __UpperCAmelCase :  List[str]=7			, __UpperCAmelCase :  Union[str, Any]=True			, __UpperCAmelCase :  Dict=True			, __UpperCAmelCase :  Optional[int]=False			, __UpperCAmelCase :  str=True			, __UpperCAmelCase :  List[str]=9_9			, __UpperCAmelCase :  List[Any]=3_2			, __UpperCAmelCase :  Any=5			, __UpperCAmelCase :  str=4			, __UpperCAmelCase :  List[Any]=6_4			, __UpperCAmelCase :  Dict="gelu"			, __UpperCAmelCase :  int=0.1			, __UpperCAmelCase :  List[str]=0.1			, __UpperCAmelCase :  Union[str, Any]=5_1_2			, __UpperCAmelCase :  List[Any]=1_6			, __UpperCAmelCase :  str=2			, __UpperCAmelCase :  Optional[Any]=0.02			, __UpperCAmelCase :  Optional[int]=3			, __UpperCAmelCase :  List[Any]=4			, __UpperCAmelCase :  Tuple=None			, __UpperCAmelCase :  List[Any]=2			, __UpperCAmelCase :  List[Any]=2			, __UpperCAmelCase :  Optional[Any]=2			, __UpperCAmelCase :  str=2			, __UpperCAmelCase :  Dict=4			, __UpperCAmelCase :  Optional[int]=1			, )      ->			Any:
						SCREAMING_SNAKE_CASE__									=					parent
						SCREAMING_SNAKE_CASE__									=					batch_size
						SCREAMING_SNAKE_CASE__									=					seq_length
						SCREAMING_SNAKE_CASE__									=					is_training
						SCREAMING_SNAKE_CASE__									=					use_input_mask
						SCREAMING_SNAKE_CASE__									=					use_token_type_ids
						SCREAMING_SNAKE_CASE__									=					use_labels
						SCREAMING_SNAKE_CASE__									=					vocab_size
						SCREAMING_SNAKE_CASE__									=					hidden_size
						SCREAMING_SNAKE_CASE__									=					num_hidden_layers
						SCREAMING_SNAKE_CASE__									=					num_attention_heads
						SCREAMING_SNAKE_CASE__									=					intermediate_size
						SCREAMING_SNAKE_CASE__									=					hidden_act
						SCREAMING_SNAKE_CASE__									=					hidden_dropout_prob
						SCREAMING_SNAKE_CASE__									=					attention_probs_dropout_prob
						SCREAMING_SNAKE_CASE__									=					max_position_embeddings
						SCREAMING_SNAKE_CASE__									=					type_vocab_size
						SCREAMING_SNAKE_CASE__									=					type_sequence_label_size
						SCREAMING_SNAKE_CASE__									=					initializer_range
						SCREAMING_SNAKE_CASE__									=					num_labels
						SCREAMING_SNAKE_CASE__									=					num_choices
						SCREAMING_SNAKE_CASE__									=					scope
						SCREAMING_SNAKE_CASE__									=					q_groups
						SCREAMING_SNAKE_CASE__									=					k_groups
						SCREAMING_SNAKE_CASE__									=					v_groups
						SCREAMING_SNAKE_CASE__									=					post_attention_groups
						SCREAMING_SNAKE_CASE__									=					intermediate_groups
						SCREAMING_SNAKE_CASE__									=					output_groups

			def     SCREAMING_SNAKE_CASE (    self :  int				)      ->			Optional[int]:
						SCREAMING_SNAKE_CASE__									=					ids_tensor([self.batch_size, self.seq_length]			, self.vocab_size				)

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

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

						SCREAMING_SNAKE_CASE__									=					self.get_config()

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

			def     SCREAMING_SNAKE_CASE (    self :  Dict				)      ->			Dict:
						return SqueezeBertConfig(
						    embedding_size=self.hidden_size			, vocab_size=self.vocab_size			, hidden_size=self.hidden_size			, num_hidden_layers=self.num_hidden_layers			, num_attention_heads=self.num_attention_heads			, intermediate_size=self.intermediate_size			, hidden_act=self.hidden_act			, attention_probs_dropout_prob=self.hidden_dropout_prob			, attention_dropout=self.attention_probs_dropout_prob			, max_position_embeddings=self.max_position_embeddings			, initializer_range=self.initializer_range			, q_groups=self.q_groups			, k_groups=self.k_groups			, v_groups=self.v_groups			, post_attention_groups=self.post_attention_groups			, intermediate_groups=self.intermediate_groups			, output_groups=self.output_groups			, )

			def     SCREAMING_SNAKE_CASE (    self :  str			, __UpperCAmelCase :  Optional[int]			, __UpperCAmelCase :  List[Any]			, __UpperCAmelCase :  Optional[Any]			, __UpperCAmelCase :  List[Any]			, __UpperCAmelCase :  Union[str, Any]			, __UpperCAmelCase :  Optional[Any]				)      ->			str:
						SCREAMING_SNAKE_CASE__									=					SqueezeBertModel(config=__lowerCamelCase				)
						model.to(__lowerCamelCase				)
						model.eval()
						SCREAMING_SNAKE_CASE__									=					model(__lowerCamelCase			, __lowerCamelCase				)
						SCREAMING_SNAKE_CASE__									=					model(__lowerCamelCase				)
						self.parent.assertEqual(result.last_hidden_state.shape			, (self.batch_size, self.seq_length, self.hidden_size)				)

			def     SCREAMING_SNAKE_CASE (    self :  List[Any]			, __UpperCAmelCase :  Union[str, Any]			, __UpperCAmelCase :  Any			, __UpperCAmelCase :  int			, __UpperCAmelCase :  List[str]			, __UpperCAmelCase :  List[Any]			, __UpperCAmelCase :  List[Any]				)      ->			Dict:
						SCREAMING_SNAKE_CASE__									=					SqueezeBertForMaskedLM(config=__lowerCamelCase				)
						model.to(__lowerCamelCase				)
						model.eval()
						SCREAMING_SNAKE_CASE__									=					model(__lowerCamelCase			, attention_mask=__lowerCamelCase			, labels=__lowerCamelCase				)
						self.parent.assertEqual(result.logits.shape			, (self.batch_size, self.seq_length, self.vocab_size)				)

			def     SCREAMING_SNAKE_CASE (    self :  Optional[Any]			, __UpperCAmelCase :  Union[str, Any]			, __UpperCAmelCase :  Optional[int]			, __UpperCAmelCase :  Optional[Any]			, __UpperCAmelCase :  Dict			, __UpperCAmelCase :  Optional[int]			, __UpperCAmelCase :  str				)      ->			Union[str, Any]:
						SCREAMING_SNAKE_CASE__									=					SqueezeBertForQuestionAnswering(config=__lowerCamelCase				)
						model.to(__lowerCamelCase				)
						model.eval()
						SCREAMING_SNAKE_CASE__									=					model(
						    __lowerCamelCase			, attention_mask=__lowerCamelCase			, start_positions=__lowerCamelCase			, end_positions=__lowerCamelCase				)
						self.parent.assertEqual(result.start_logits.shape			, (self.batch_size, self.seq_length)				)
						self.parent.assertEqual(result.end_logits.shape			, (self.batch_size, self.seq_length)				)

			def     SCREAMING_SNAKE_CASE (    self :  List[str]			, __UpperCAmelCase :  Union[str, Any]			, __UpperCAmelCase :  Tuple			, __UpperCAmelCase :  Any			, __UpperCAmelCase :  Optional[int]			, __UpperCAmelCase :  Any			, __UpperCAmelCase :  str				)      ->			Any:
						SCREAMING_SNAKE_CASE__									=					self.num_labels
						SCREAMING_SNAKE_CASE__									=					SqueezeBertForSequenceClassification(__lowerCamelCase				)
						model.to(__lowerCamelCase				)
						model.eval()
						SCREAMING_SNAKE_CASE__									=					model(__lowerCamelCase			, attention_mask=__lowerCamelCase			, labels=__lowerCamelCase				)
						self.parent.assertEqual(result.logits.shape			, (self.batch_size, self.num_labels)				)

			def     SCREAMING_SNAKE_CASE (    self :  List[Any]			, __UpperCAmelCase :  Tuple			, __UpperCAmelCase :  int			, __UpperCAmelCase :  str			, __UpperCAmelCase :  str			, __UpperCAmelCase :  Optional[Any]			, __UpperCAmelCase :  Tuple				)      ->			Any:
						SCREAMING_SNAKE_CASE__									=					self.num_labels
						SCREAMING_SNAKE_CASE__									=					SqueezeBertForTokenClassification(config=__lowerCamelCase				)
						model.to(__lowerCamelCase				)
						model.eval()

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

			def     SCREAMING_SNAKE_CASE (    self :  Optional[Any]			, __UpperCAmelCase :  str			, __UpperCAmelCase :  int			, __UpperCAmelCase :  Tuple			, __UpperCAmelCase :  List[str]			, __UpperCAmelCase :  Dict			, __UpperCAmelCase :  Tuple				)      ->			Optional[int]:
						SCREAMING_SNAKE_CASE__									=					self.num_choices
						SCREAMING_SNAKE_CASE__									=					SqueezeBertForMultipleChoice(config=__lowerCamelCase				)
						model.to(__lowerCamelCase				)
						model.eval()
						SCREAMING_SNAKE_CASE__									=					input_ids.unsqueeze(1				).expand(-1			, self.num_choices			, -1				).contiguous()
						SCREAMING_SNAKE_CASE__									=					input_mask.unsqueeze(1				).expand(-1			, self.num_choices			, -1				).contiguous()
						SCREAMING_SNAKE_CASE__									=					model(
						    __lowerCamelCase			, attention_mask=__lowerCamelCase			, labels=__lowerCamelCase			, )
						self.parent.assertEqual(result.logits.shape			, (self.batch_size, self.num_choices)				)





			def     SCREAMING_SNAKE_CASE (    self :  Any				)      ->			Optional[int]:
						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  (_UpperCamelCase	,_UpperCamelCase	,unittest.TestCase	):
			lowerCamelCase__      :						int    						=							(
			    (
			        SqueezeBertModel,
			        SqueezeBertForMaskedLM,
			        SqueezeBertForMultipleChoice,
			        SqueezeBertForQuestionAnswering,
			        SqueezeBertForSequenceClassification,
			        SqueezeBertForTokenClassification,
			    )
			    if is_torch_available()
			    else None
			)
			lowerCamelCase__      :						Tuple    						=							(
			    {
			        """feature-extraction""": SqueezeBertModel,
			        """fill-mask""": SqueezeBertForMaskedLM,
			        """question-answering""": SqueezeBertForQuestionAnswering,
			        """text-classification""": SqueezeBertForSequenceClassification,
			        """token-classification""": SqueezeBertForTokenClassification,
			        """zero-shot""": SqueezeBertForSequenceClassification,
			    }
			    if is_torch_available()
			    else {}
			)
			lowerCamelCase__      :						Optional[int]    						=							False
			lowerCamelCase__      :						str    						=							True
			lowerCamelCase__      :						Optional[int]    						=							False

			def     SCREAMING_SNAKE_CASE (    self :  Tuple				)      ->			Any:
						SCREAMING_SNAKE_CASE__									=					SqueezeBertModelTester(self				)
						SCREAMING_SNAKE_CASE__									=					ConfigTester(self			, config_class=__lowerCamelCase			, dim=3_7				)

			def     SCREAMING_SNAKE_CASE (    self :  int				)      ->			int:
						self.config_tester.run_common_tests()

			def     SCREAMING_SNAKE_CASE (    self :  Tuple				)      ->			Dict:
						SCREAMING_SNAKE_CASE__									=					self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_squeezebert_model(*__lowerCamelCase				)

			def     SCREAMING_SNAKE_CASE (    self :  Optional[int]				)      ->			Dict:
						SCREAMING_SNAKE_CASE__									=					self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_squeezebert_for_masked_lm(*__lowerCamelCase				)

			def     SCREAMING_SNAKE_CASE (    self :  Optional[Any]				)      ->			Optional[Any]:
						SCREAMING_SNAKE_CASE__									=					self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_squeezebert_for_question_answering(*__lowerCamelCase				)

			def     SCREAMING_SNAKE_CASE (    self :  Dict				)      ->			Any:
						SCREAMING_SNAKE_CASE__									=					self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_squeezebert_for_sequence_classification(*__lowerCamelCase				)

			def     SCREAMING_SNAKE_CASE (    self :  Union[str, Any]				)      ->			str:
						SCREAMING_SNAKE_CASE__									=					self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_squeezebert_for_token_classification(*__lowerCamelCase				)

			def     SCREAMING_SNAKE_CASE (    self :  Optional[Any]				)      ->			List[Any]:
						SCREAMING_SNAKE_CASE__									=					self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_squeezebert_for_multiple_choice(*__lowerCamelCase				)





			@slow
			def     SCREAMING_SNAKE_CASE (    self :  Any				)      ->			Any:
						for model_name in SQUEEZEBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
									SCREAMING_SNAKE_CASE__									=					SqueezeBertModel.from_pretrained(__lowerCamelCase				)
									self.assertIsNotNone(__lowerCamelCase				)





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

			@slow
			def     SCREAMING_SNAKE_CASE (    self :  str				)      ->			Union[str, Any]:
						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(__lowerCamelCase				)[0]
						SCREAMING_SNAKE_CASE__									=					torch.Size((1, 3)				)
						self.assertEqual(output.shape			, __lowerCamelCase				)
						SCREAMING_SNAKE_CASE__									=					torch.tensor([[0.6_401, -0.0_349, -0.6_041]]				)
						self.assertTrue(torch.allclose(__lowerCamelCase			, __lowerCamelCase			, atol=1e-4				)				)








from . import __version__

# Backward compatibility imports, to make sure all those objects can be found in file_utils
from .utils import (
    CLOUDFRONT_DISTRIB_PREFIX,
    CONFIG_NAME,
    DISABLE_TELEMETRY,
    DUMMY_INPUTS,
    DUMMY_MASK,
    ENV_VARS_TRUE_AND_AUTO_VALUES,
    ENV_VARS_TRUE_VALUES,
    FEATURE_EXTRACTOR_NAME,
    FLAX_WEIGHTS_NAME,
    HF_MODULES_CACHE,
    HUGGINGFACE_CO_PREFIX,
    HUGGINGFACE_CO_RESOLVE_ENDPOINT,
    MODEL_CARD_NAME,
    MULTIPLE_CHOICE_DUMMY_INPUTS,
    PYTORCH_PRETRAINED_BERT_CACHE,
    PYTORCH_TRANSFORMERS_CACHE,
    S3_BUCKET_PREFIX,
    SENTENCEPIECE_UNDERLINE,
    SPIECE_UNDERLINE,
    TF2_WEIGHTS_NAME,
    TF_WEIGHTS_NAME,
    TORCH_FX_REQUIRED_VERSION,
    TRANSFORMERS_CACHE,
    TRANSFORMERS_DYNAMIC_MODULE_NAME,
    USE_JAX,
    USE_TF,
    USE_TORCH,
    WEIGHTS_INDEX_NAME,
    WEIGHTS_NAME,
    ContextManagers,
    DummyObject,
    EntryNotFoundError,
    ExplicitEnum,
    ModelOutput,
    PaddingStrategy,
    PushToHubMixin,
    RepositoryNotFoundError,
    RevisionNotFoundError,
    TensorType,
    _LazyModule,
    add_code_sample_docstrings,
    add_end_docstrings,
    add_start_docstrings,
    add_start_docstrings_to_model_forward,
    cached_property,
    copy_func,
    default_cache_path,
    define_sagemaker_information,
    get_cached_models,
    get_file_from_repo,
    get_full_repo_name,
    get_torch_version,
    has_file,
    http_user_agent,
    is_apex_available,
    is_bsa_available,
    is_coloredlogs_available,
    is_datasets_available,
    is_detectrona_available,
    is_faiss_available,
    is_flax_available,
    is_ftfy_available,
    is_in_notebook,
    is_ipex_available,
    is_librosa_available,
    is_offline_mode,
    is_onnx_available,
    is_pandas_available,
    is_phonemizer_available,
    is_protobuf_available,
    is_psutil_available,
    is_pyanvml_available,
    is_pyctcdecode_available,
    is_pytesseract_available,
    is_pytorch_quantization_available,
    is_rjieba_available,
    is_sagemaker_dp_enabled,
    is_sagemaker_mp_enabled,
    is_scipy_available,
    is_sentencepiece_available,
    is_seqio_available,
    is_sklearn_available,
    is_soundfile_availble,
    is_spacy_available,
    is_speech_available,
    is_tensor,
    is_tensorflow_probability_available,
    is_tfaonnx_available,
    is_tf_available,
    is_timm_available,
    is_tokenizers_available,
    is_torch_available,
    is_torch_bfaa_available,
    is_torch_cuda_available,
    is_torch_fx_available,
    is_torch_fx_proxy,
    is_torch_mps_available,
    is_torch_tfaa_available,
    is_torch_tpu_available,
    is_torchaudio_available,
    is_training_run_on_sagemaker,
    is_vision_available,
    replace_return_docstrings,
    requires_backends,
    to_numpy,
    to_py_obj,
    torch_only_method,
)






