"""simple docstring"""







from __future__ import annotations

import unittest

from transformers import MobileBertConfig, is_tf_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
	import tensorflow as tf

	from transformers import (
	    TF_MODEL_FOR_PRETRAINING_MAPPING,
	    TFMobileBertForMaskedLM,
	    TFMobileBertForMultipleChoice,
	    TFMobileBertForNextSentencePrediction,
	    TFMobileBertForPreTraining,
	    TFMobileBertForQuestionAnswering,
	    TFMobileBertForSequenceClassification,
	    TFMobileBertForTokenClassification,
	    TFMobileBertModel,
	)

@require_tf
class 	UpperCamelCase    (					lowercase   ,			lowercase   ,			unittest.TestCase		):
				UpperCAmelCase       :   Tuple					=	(
				    (
				        TFMobileBertModel,
				        TFMobileBertForMaskedLM,
				        TFMobileBertForNextSentencePrediction,
				        TFMobileBertForPreTraining,
				        TFMobileBertForQuestionAnswering,
				        TFMobileBertForSequenceClassification,
				        TFMobileBertForTokenClassification,
				        TFMobileBertForMultipleChoice,
				    )
				    if is_tf_available()
				    else ()
				)
				UpperCAmelCase       :   List[Any]					=	(
				    {
				        """feature-extraction""": TFMobileBertModel,
				        """fill-mask""": TFMobileBertForMaskedLM,
				        """question-answering""": TFMobileBertForQuestionAnswering,
				        """text-classification""": TFMobileBertForSequenceClassification,
				        """token-classification""": TFMobileBertForTokenClassification,
				        """zero-shot""": TFMobileBertForSequenceClassification,
				    }
				    if is_tf_available()
				    else {}
				)
				UpperCAmelCase       :   List[str]					=	False
				UpperCAmelCase       :   Optional[Any]					=	False



				def       _lowercase  (self       :   Optional[Any]			,						_A       :   List[Any]			,						_A       :   str			,						_A       :   Any=False)					->			str:
					__snake_case    :							int   	=				super()._prepare_for_class(_A			,						_A			,						return_labels=_A)

					if return_labels:
						if model_class in get_values(_A):
							__snake_case    :							Optional[Any]   	=				tf.zeros(self.model_tester.batch_size			,						dtype=tf.intaa)

					return inputs_dict

				class 	UpperCamelCase    (					lowercase		):



								def __init__(self       :   List[Any]			,						_A       :   Optional[Any]			,						_A       :   Optional[Any]=13			,						_A       :   Any=7			,						_A       :   Optional[int]=True			,						_A       :   Optional[int]=True			,						_A       :   str=True			,						_A       :   Optional[int]=True			,						_A       :   Optional[int]=99			,						_A       :   Optional[Any]=32			,						_A       :   str=32			,						_A       :   Optional[int]=2			,						_A       :   int=4			,						_A       :   List[str]=37			,						_A       :   Any="gelu"			,						_A       :   List[Any]=0.1			,						_A       :   Tuple=0.1			,						_A       :   int=5_12			,						_A       :   Optional[int]=16			,						_A       :   List[str]=2			,						_A       :   Dict=0.02			,						_A       :   List[Any]=3			,						_A       :   Dict=4			,						_A       :   Optional[Any]=None			,						)					->			List[str]:
									__snake_case    :							Optional[Any]   	=				parent
									__snake_case    :							Union[str, Any]   	=				batch_size
									__snake_case    :							Optional[int]   	=				seq_length
									__snake_case    :							List[Any]   	=				is_training
									__snake_case    :							Optional[Any]   	=				use_input_mask
									__snake_case    :							Any   	=				use_token_type_ids
									__snake_case    :							int   	=				use_labels
									__snake_case    :							Optional[Any]   	=				vocab_size
									__snake_case    :							str   	=				hidden_size
									__snake_case    :							Any   	=				num_hidden_layers
									__snake_case    :							Dict   	=				num_attention_heads
									__snake_case    :							Any   	=				intermediate_size
									__snake_case    :							List[Any]   	=				hidden_act
									__snake_case    :							Any   	=				hidden_dropout_prob
									__snake_case    :							Tuple   	=				attention_probs_dropout_prob
									__snake_case    :							str   	=				max_position_embeddings
									__snake_case    :							Optional[int]   	=				type_vocab_size
									__snake_case    :							List[Any]   	=				type_sequence_label_size
									__snake_case    :							Optional[Any]   	=				initializer_range
									__snake_case    :							List[Any]   	=				num_labels
									__snake_case    :							List[str]   	=				num_choices
									__snake_case    :							int   	=				scope
									__snake_case    :							Dict   	=				embedding_size



								def       _lowercase  (self       :   Union[str, Any])					->			Any:
									__snake_case    :							Any   	=				ids_tensor([self.batch_size, self.seq_length]			,						self.vocab_size)

									__snake_case    :							List[Any]   	=				None
									if self.use_input_mask:
										__snake_case    :							List[Any]   	=				random_attention_mask([self.batch_size, self.seq_length])

									__snake_case    :							Dict   	=				None
									if self.use_token_type_ids:
										__snake_case    :							Union[str, Any]   	=				ids_tensor([self.batch_size, self.seq_length]			,						self.type_vocab_size)

									__snake_case    :							Dict   	=				None
									__snake_case    :							Any   	=				None
									__snake_case    :							str   	=				None
									if self.use_labels:
										__snake_case    :							Tuple   	=				ids_tensor([self.batch_size]			,						self.type_sequence_label_size)
										__snake_case    :							Any   	=				ids_tensor([self.batch_size, self.seq_length]			,						self.num_labels)
										__snake_case    :							Dict   	=				ids_tensor([self.batch_size]			,						self.num_choices)

									__snake_case    :							List[str]   	=				MobileBertConfig(
									    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			,						hidden_dropout_prob=self.hidden_dropout_prob			,						attention_probs_dropout_prob=self.attention_probs_dropout_prob			,						max_position_embeddings=self.max_position_embeddings			,						type_vocab_size=self.type_vocab_size			,						initializer_range=self.initializer_range			,						embedding_size=self.embedding_size			,						)

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



								def       _lowercase  (self       :   List[Any]			,						_A       :   List[str]			,						_A       :   Tuple			,						_A       :   Optional[int]			,						_A       :   Optional[Any]			,						_A       :   List[str]			,						_A       :   Union[str, Any]			,						_A       :   Any)					->			Dict:
									__snake_case    :							int   	=				TFMobileBertModel(config=_A)
									__snake_case    :							Union[str, Any]   	=				{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
									__snake_case    :							Union[str, Any]   	=				model(_A)

									__snake_case    :							List[Any]   	=				[input_ids, input_mask]
									__snake_case    :							Union[str, Any]   	=				model(_A)

									__snake_case    :							List[Any]   	=				model(_A)

									self.parent.assertEqual(
									    result.last_hidden_state.shape			,						(self.batch_size, self.seq_length, self.hidden_size))
									self.parent.assertEqual(result.pooler_output.shape			,						(self.batch_size, self.hidden_size))



								def       _lowercase  (self       :   Optional[int]			,						_A       :   int			,						_A       :   Dict			,						_A       :   Optional[Any]			,						_A       :   int			,						_A       :   Union[str, Any]			,						_A       :   Union[str, Any]			,						_A       :   List[str])					->			int:
									__snake_case    :							Optional[int]   	=				TFMobileBertForMaskedLM(config=_A)
									__snake_case    :							List[Any]   	=				{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
									__snake_case    :							Any   	=				model(_A)
									self.parent.assertEqual(result.logits.shape			,						(self.batch_size, self.seq_length, self.vocab_size))



								def       _lowercase  (self       :   Union[str, Any]			,						_A       :   str			,						_A       :   Optional[int]			,						_A       :   Optional[int]			,						_A       :   Tuple			,						_A       :   List[Any]			,						_A       :   List[str]			,						_A       :   int)					->			str:
									__snake_case    :							Dict   	=				TFMobileBertForNextSentencePrediction(config=_A)
									__snake_case    :							Dict   	=				{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
									__snake_case    :							Optional[int]   	=				model(_A)
									self.parent.assertEqual(result.logits.shape			,						(self.batch_size, 2))



								def       _lowercase  (self       :   List[Any]			,						_A       :   int			,						_A       :   List[Any]			,						_A       :   Optional[Any]			,						_A       :   Tuple			,						_A       :   Dict			,						_A       :   List[Any]			,						_A       :   Union[str, Any])					->			int:
									__snake_case    :							Optional[Any]   	=				TFMobileBertForPreTraining(config=_A)
									__snake_case    :							List[Any]   	=				{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
									__snake_case    :							List[Any]   	=				model(_A)
									self.parent.assertEqual(
									    result.prediction_logits.shape			,						(self.batch_size, self.seq_length, self.vocab_size))
									self.parent.assertEqual(result.seq_relationship_logits.shape			,						(self.batch_size, 2))



								def       _lowercase  (self       :   Dict			,						_A       :   str			,						_A       :   Optional[Any]			,						_A       :   List[Any]			,						_A       :   Optional[int]			,						_A       :   List[str]			,						_A       :   Optional[Any]			,						_A       :   List[Any])					->			Union[str, Any]:
									__snake_case    :							Tuple   	=				self.num_labels
									__snake_case    :							List[str]   	=				TFMobileBertForSequenceClassification(config=_A)
									__snake_case    :							List[Any]   	=				{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
									__snake_case    :							Tuple   	=				model(_A)
									self.parent.assertEqual(result.logits.shape			,						(self.batch_size, self.num_labels))



								def       _lowercase  (self       :   Union[str, Any]			,						_A       :   Any			,						_A       :   int			,						_A       :   Any			,						_A       :   Dict			,						_A       :   Tuple			,						_A       :   Optional[int]			,						_A       :   int)					->			str:
									__snake_case    :							List[str]   	=				self.num_choices
									__snake_case    :							List[Any]   	=				TFMobileBertForMultipleChoice(config=_A)
									__snake_case    :							Optional[Any]   	=				tf.tile(tf.expand_dims(_A			,						1)			,						(1, self.num_choices, 1))
									__snake_case    :							List[str]   	=				tf.tile(tf.expand_dims(_A			,						1)			,						(1, self.num_choices, 1))
									__snake_case    :							Optional[Any]   	=				tf.tile(tf.expand_dims(_A			,						1)			,						(1, self.num_choices, 1))
									__snake_case    :							List[Any]   	=				{
									    'input_ids': multiple_choice_inputs_ids,
									    'attention_mask': multiple_choice_input_mask,
									    'token_type_ids': multiple_choice_token_type_ids,
									}
									__snake_case    :							List[str]   	=				model(_A)
									self.parent.assertEqual(result.logits.shape			,						(self.batch_size, self.num_choices))



								def       _lowercase  (self       :   Dict			,						_A       :   str			,						_A       :   Any			,						_A       :   Any			,						_A       :   Dict			,						_A       :   Optional[int]			,						_A       :   Any			,						_A       :   Optional[int])					->			int:
									__snake_case    :							int   	=				self.num_labels
									__snake_case    :							List[str]   	=				TFMobileBertForTokenClassification(config=_A)
									__snake_case    :							Optional[Any]   	=				{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
									__snake_case    :							str   	=				model(_A)
									self.parent.assertEqual(result.logits.shape			,						(self.batch_size, self.seq_length, self.num_labels))



								def       _lowercase  (self       :   List[str]			,						_A       :   Tuple			,						_A       :   Dict			,						_A       :   List[str]			,						_A       :   Optional[Any]			,						_A       :   Any			,						_A       :   List[str]			,						_A       :   str)					->			str:
									__snake_case    :							Optional[Any]   	=				TFMobileBertForQuestionAnswering(config=_A)
									__snake_case    :							Optional[Any]   	=				{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
									__snake_case    :							Dict   	=				model(_A)
									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       _lowercase  (self       :   Union[str, Any])					->			Optional[int]:
									__snake_case    :							Optional[int]   	=				self.prepare_config_and_inputs()
									(
									    (
									    __snake_case
									)	,       (
									    __snake_case
									)	,       (
									    __snake_case
									)	,       (
									    __snake_case
									)	,       (
									    __snake_case
									)	,       (
									    __snake_case
									)	,       (
									    __snake_case
									)	,       
									)    :							Optional[int]   	=				config_and_inputs
									__snake_case    :							List[Any]   	=				{'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
									return config, inputs_dict







				def       _lowercase  (self       :   int)					->			Optional[Any]:
					__snake_case    :							Any   	=				TFMobileBertModelTest.TFMobileBertModelTester(self)
					__snake_case    :							Union[str, Any]   	=				ConfigTester(self			,						config_class=_A			,						hidden_size=37)



				def       _lowercase  (self       :   Any)					->			Tuple:
					self.config_tester.run_common_tests()



				def       _lowercase  (self       :   Optional[Any])					->			Union[str, Any]:
					__snake_case    :							Any   	=				self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_mobilebert_model(*_A)



				def       _lowercase  (self       :   Optional[Any])					->			List[Any]:
					__snake_case    :							int   	=				self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_mobilebert_for_masked_lm(*_A)



				def       _lowercase  (self       :   Union[str, Any])					->			str:
					__snake_case    :							Any   	=				self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_mobilebert_for_multiple_choice(*_A)



				def       _lowercase  (self       :   List[Any])					->			List[str]:
					__snake_case    :							Any   	=				self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_mobilebert_for_next_sequence_prediction(*_A)



				def       _lowercase  (self       :   Union[str, Any])					->			Any:
					__snake_case    :							Tuple   	=				self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_mobilebert_for_pretraining(*_A)



				def       _lowercase  (self       :   List[str])					->			List[str]:
					__snake_case    :							Tuple   	=				self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_mobilebert_for_question_answering(*_A)



				def       _lowercase  (self       :   Union[str, Any])					->			int:
					__snake_case    :							Union[str, Any]   	=				self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_mobilebert_for_sequence_classification(*_A)



				def       _lowercase  (self       :   Dict)					->			Optional[Any]:
					__snake_case    :							Union[str, Any]   	=				self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_mobilebert_for_token_classification(*_A)






				@slow
				def       _lowercase  (self       :   List[Any])					->			Optional[int]:
					# for model_name in TF_MOBILEBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
					for model_name in ["google/mobilebert-uncased"]:
						__snake_case    :							Dict   	=				TFMobileBertModel.from_pretrained(_A)
						self.assertIsNotNone(_A)







@require_tf
class 	UpperCamelCase    (					unittest.TestCase		):



				@slow
				def       _lowercase  (self       :   Dict)					->			List[str]:
					__snake_case    :							Dict   	=				TFMobileBertForPreTraining.from_pretrained('google/mobilebert-uncased')
					__snake_case    :							List[str]   	=				tf.constant([[0, 1, 2, 3, 4, 5]])
					__snake_case    :							Optional[int]   	=				model(_A)[0]

					__snake_case    :							Optional[Any]   	=				[1, 6, 3_05_22]
					self.assertEqual(output.shape			,						_A)

					__snake_case    :							List[Any]   	=				tf.constant(
					    [
					        [
					            [-4.5_919_547, -9.248_295, -9.645_256],
					            [-6.7_306_175, -6.440_284, -6.6_052_837],
					            [-7.2_743_506, -6.7_847_915, -6.024_673],
					        ]
					    ])
					tf.debugging.assert_near(output[:, :3, :3]			,						_A			,						atol=1E-4)






"""simple docstring"""







from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_torch_available,
)


_a  :  Optional[Any]=				{
    "configuration_wav2vec2": ["WAV_2_VEC_2_PRETRAINED_CONFIG_ARCHIVE_MAP", "Wav2Vec2Config"],
    "feature_extraction_wav2vec2": ["Wav2Vec2FeatureExtractor"],
    "processing_wav2vec2": ["Wav2Vec2Processor"],
    "tokenization_wav2vec2": ["Wav2Vec2CTCTokenizer", "Wav2Vec2Tokenizer"],
}


try:
	if not is_torch_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	_a  :  Optional[Any]=				[
	    "WAV_2_VEC_2_PRETRAINED_MODEL_ARCHIVE_LIST",
	    "Wav2Vec2ForAudioFrameClassification",
	    "Wav2Vec2ForCTC",
	    "Wav2Vec2ForMaskedLM",
	    "Wav2Vec2ForPreTraining",
	    "Wav2Vec2ForSequenceClassification",
	    "Wav2Vec2ForXVector",
	    "Wav2Vec2Model",
	    "Wav2Vec2PreTrainedModel",
	]

try:
	if not is_tf_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	_a  :  List[str]=				[
	    "TF_WAV_2_VEC_2_PRETRAINED_MODEL_ARCHIVE_LIST",
	    "TFWav2Vec2ForCTC",
	    "TFWav2Vec2Model",
	    "TFWav2Vec2PreTrainedModel",
	    "TFWav2Vec2ForSequenceClassification",
	]

try:
	if not is_flax_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	_a  :  List[Any]=				[
	    "FlaxWav2Vec2ForCTC",
	    "FlaxWav2Vec2ForPreTraining",
	    "FlaxWav2Vec2Model",
	    "FlaxWav2Vec2PreTrainedModel",
	]


if TYPE_CHECKING:
	from .configuration_wavaveca import WAV_2_VEC_2_PRETRAINED_CONFIG_ARCHIVE_MAP, WavaVecaConfig
	from .feature_extraction_wavaveca import WavaVecaFeatureExtractor
	from .processing_wavaveca import WavaVecaProcessor
	from .tokenization_wavaveca import WavaVecaCTCTokenizer, WavaVecaTokenizer

	try:
		if not is_torch_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_wavaveca import (
		    WAV_2_VEC_2_PRETRAINED_MODEL_ARCHIVE_LIST,
		    WavaVecaForAudioFrameClassification,
		    WavaVecaForCTC,
		    WavaVecaForMaskedLM,
		    WavaVecaForPreTraining,
		    WavaVecaForSequenceClassification,
		    WavaVecaForXVector,
		    WavaVecaModel,
		    WavaVecaPreTrainedModel,
		)

	try:
		if not is_tf_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_tf_wavaveca import (
		    TF_WAV_2_VEC_2_PRETRAINED_MODEL_ARCHIVE_LIST,
		    TFWavaVecaForCTC,
		    TFWavaVecaForSequenceClassification,
		    TFWavaVecaModel,
		    TFWavaVecaPreTrainedModel,
		)

	try:
		if not is_flax_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_tf_wavaveca import (
		    FlaxWavaVecaForCTC,
		    FlaxWavaVecaForPreTraining,
		    FlaxWavaVecaModel,
		    FlaxWavaVecaPreTrainedModel,
		)


else:
	import sys

	_a  :  Tuple=				_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)





