




'''simple docstring'''







from __future__ import annotations

import unittest

from transformers import AlbertConfig, 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
						from transformers.models.albert.modeling_tf_albert import (
						    TF_ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
						    TFAlbertForMaskedLM,
						    TFAlbertForMultipleChoice,
						    TFAlbertForPreTraining,
						    TFAlbertForQuestionAnswering,
						    TFAlbertForSequenceClassification,
						    TFAlbertForTokenClassification,
						    TFAlbertModel,
						)





class 					lowerCamelCase_							:




					'''simple docstring'''






					def __init__(   self,  __UpperCamelCase,  __UpperCamelCase=13,  __UpperCamelCase=7,  __UpperCamelCase=True,  __UpperCamelCase=True,  __UpperCamelCase=True,  __UpperCamelCase=True,  __UpperCamelCase=99,  __UpperCamelCase=16,  __UpperCamelCase=32,  __UpperCamelCase=2,  __UpperCamelCase=4,  __UpperCamelCase=37,  __UpperCamelCase="gelu",  __UpperCamelCase=0.1,  __UpperCamelCase=0.1,  __UpperCamelCase=512,  __UpperCamelCase=16,  __UpperCamelCase=2,  __UpperCamelCase=0.02,  __UpperCamelCase=3,  __UpperCamelCase=4,  __UpperCamelCase=None,  ):
							_snake_case     	=	parent
							_snake_case     	=	13
							_snake_case     	=	7
							_snake_case     	=	True
							_snake_case     	=	True
							_snake_case     	=	True
							_snake_case     	=	True
							_snake_case     	=	99
							_snake_case     	=	16
							_snake_case     	=	32
							_snake_case     	=	2
							_snake_case     	=	4
							_snake_case     	=	37
							_snake_case     	=	"gelu"
							_snake_case     	=	0.1
							_snake_case     	=	0.1
							_snake_case     	=	512
							_snake_case     	=	16
							_snake_case     	=	2
							_snake_case     	=	0.02
							_snake_case     	=	3
							_snake_case     	=	4
							_snake_case     	=	None






					def     __SCREAMING_SNAKE_CASE     (   self			):
							_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
							if self.use_token_type_ids:
									_snake_case     	=	ids_tensor([self.batch_size, self.seq_length],  self.type_vocab_size			)

							_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     	=	AlbertConfig(
							    vocab_size=self.vocab_size,  hidden_size=self.hidden_size,  embedding_size=self.embedding_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,  )

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






					def     __SCREAMING_SNAKE_CASE     (   self,  __UpperCamelCase,  __UpperCamelCase,  __UpperCamelCase,  __UpperCamelCase,  __UpperCamelCase,  __UpperCamelCase,  __UpperCamelCase			):
							_snake_case     	=	TFAlbertModel(config=lowerCAmelCase__			)
							# inputs = {'input_ids': input_ids,
							#           'attention_mask': input_mask,
							#           'token_type_ids': token_type_ids}
							# sequence_output, pooled_output = model(**inputs)
							_snake_case     	=	{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
							_snake_case     	=	model(lowerCAmelCase__			)

							_snake_case     	=	[input_ids, input_mask]
							_snake_case     	=	model(lowerCAmelCase__			)

							_snake_case     	=	model(lowerCAmelCase__			)

							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     __SCREAMING_SNAKE_CASE     (   self,  __UpperCamelCase,  __UpperCamelCase,  __UpperCamelCase,  __UpperCamelCase,  __UpperCamelCase,  __UpperCamelCase,  __UpperCamelCase			):
							_snake_case     	=	self.num_labels
							_snake_case     	=	TFAlbertForPreTraining(config=lowerCAmelCase__			)
							_snake_case     	=	{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
							_snake_case     	=	model(lowerCAmelCase__			)
							self.parent.assertEqual(result.prediction_logits.shape,  (self.batch_size, self.seq_length, self.vocab_size)			)
							self.parent.assertEqual(result.sop_logits.shape,  (self.batch_size, self.num_labels)			)






					def     __SCREAMING_SNAKE_CASE     (   self,  __UpperCamelCase,  __UpperCamelCase,  __UpperCamelCase,  __UpperCamelCase,  __UpperCamelCase,  __UpperCamelCase,  __UpperCamelCase			):
							_snake_case     	=	TFAlbertForMaskedLM(config=lowerCAmelCase__			)
							_snake_case     	=	{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
							_snake_case     	=	model(lowerCAmelCase__			)
							self.parent.assertEqual(result.logits.shape,  (self.batch_size, self.seq_length, self.vocab_size)			)






					def     __SCREAMING_SNAKE_CASE     (   self,  __UpperCamelCase,  __UpperCamelCase,  __UpperCamelCase,  __UpperCamelCase,  __UpperCamelCase,  __UpperCamelCase,  __UpperCamelCase			):
							_snake_case     	=	self.num_labels
							_snake_case     	=	TFAlbertForSequenceClassification(config=lowerCAmelCase__			)
							_snake_case     	=	{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
							_snake_case     	=	model(lowerCAmelCase__			)
							self.parent.assertEqual(result.logits.shape,  (self.batch_size, self.num_labels)			)






					def     __SCREAMING_SNAKE_CASE     (   self,  __UpperCamelCase,  __UpperCamelCase,  __UpperCamelCase,  __UpperCamelCase,  __UpperCamelCase,  __UpperCamelCase,  __UpperCamelCase			):
							_snake_case     	=	TFAlbertForQuestionAnswering(config=lowerCAmelCase__			)
							_snake_case     	=	{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
							_snake_case     	=	model(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,  __UpperCamelCase,  __UpperCamelCase,  __UpperCamelCase,  __UpperCamelCase,  __UpperCamelCase,  __UpperCamelCase,  __UpperCamelCase			):
							_snake_case     	=	self.num_choices
							_snake_case     	=	TFAlbertForMultipleChoice(config=lowerCAmelCase__			)
							_snake_case     	=	tf.tile(tf.expand_dims(lowerCAmelCase__,  1			),  (1, self.num_choices, 1)			)
							_snake_case     	=	tf.tile(tf.expand_dims(lowerCAmelCase__,  1			),  (1, self.num_choices, 1)			)
							_snake_case     	=	tf.tile(tf.expand_dims(lowerCAmelCase__,  1			),  (1, self.num_choices, 1)			)
							_snake_case     	=	{
							    "input_ids": multiple_choice_inputs_ids,
							    "attention_mask": multiple_choice_input_mask,
							    "token_type_ids": multiple_choice_token_type_ids,
							}
							_snake_case     	=	model(lowerCAmelCase__			)
							self.parent.assertListEqual(list(result["logits"].shape			),  [self.batch_size, self.num_choices]			)






					def     __SCREAMING_SNAKE_CASE     (   self,  __UpperCamelCase,  __UpperCamelCase,  __UpperCamelCase,  __UpperCamelCase,  __UpperCamelCase,  __UpperCamelCase,  __UpperCamelCase			):
							_snake_case     	=	self.num_labels
							_snake_case     	=	TFAlbertForTokenClassification(config=lowerCAmelCase__			)
							_snake_case     	=	{
							    "input_ids": input_ids,
							    "attention_mask": input_mask,
							    "token_type_ids": token_type_ids,
							}
							_snake_case     	=	model(lowerCAmelCase__			)
							self.parent.assertListEqual(list(result["logits"].shape			),  [self.batch_size, self.seq_length, self.num_labels]			)






					def     __SCREAMING_SNAKE_CASE     (   self			):
							_snake_case     	=	self.prepare_config_and_inputs()
							(
							    (
							    _snake_case 
							)	,   (
							    _snake_case 
							)	,   (
							    _snake_case 
							)	,   (
							    _snake_case 
							)	,   (
							    _snake_case 
							)	,   (
							    _snake_case 
							)	,   (
							    _snake_case 
							)	,    
							)     	=	config_and_inputs
							_snake_case     	=	{"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
							return config, inputs_dict





@require_tf
class 					lowerCamelCase_							(	lowercase__,	lowercase__,	unittest.TestCase							):




					'''simple docstring'''






					lowercase__   =			(
					    (
					        TFAlbertModel,
					        TFAlbertForPreTraining,
					        TFAlbertForMaskedLM,
					        TFAlbertForSequenceClassification,
					        TFAlbertForQuestionAnswering,
					        TFAlbertForTokenClassification,
					        TFAlbertForMultipleChoice,
					    )
					    if is_tf_available()
					    else ()
					)
					lowercase__   =			(
					    {
					        '''feature-extraction''': TFAlbertModel,
					        '''fill-mask''': TFAlbertForMaskedLM,
					        '''question-answering''': TFAlbertForQuestionAnswering,
					        '''text-classification''': TFAlbertForSequenceClassification,
					        '''token-classification''': TFAlbertForTokenClassification,
					        '''zero-shot''': TFAlbertForSequenceClassification,
					    }
					    if is_tf_available()
					    else {}
					)
					lowercase__   =			False
					lowercase__   =			False






					def     __SCREAMING_SNAKE_CASE     (   self,  __UpperCamelCase,  __UpperCamelCase,  __UpperCamelCase=False			):
							_snake_case     	=	super()._prepare_for_class(lowerCAmelCase__,  lowerCAmelCase__,  return_labels=lowerCAmelCase__			)

							if return_labels:
									if model_class in get_values(lowerCAmelCase__			):
											_snake_case     	=	tf.zeros(self.model_tester.batch_size,  dtype=tf.intaa			)

							return inputs_dict






					def     __SCREAMING_SNAKE_CASE     (   self			):
							_snake_case     	=	TFAlbertModelTester(self			)
							_snake_case     	=	ConfigTester(self,  config_class=lowerCAmelCase__,  hidden_size=37			)






					def     __SCREAMING_SNAKE_CASE     (   self			):
							self.config_tester.run_common_tests()






					def     __SCREAMING_SNAKE_CASE     (   self			):
							_snake_case     	=	self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_albert_model(*lowerCAmelCase__			)






					def     __SCREAMING_SNAKE_CASE     (   self			):
							_snake_case     	=	self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_albert_for_pretraining(*lowerCAmelCase__			)






					def     __SCREAMING_SNAKE_CASE     (   self			):
							_snake_case     	=	self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_albert_for_masked_lm(*lowerCAmelCase__			)






					def     __SCREAMING_SNAKE_CASE     (   self			):
							_snake_case     	=	self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_albert_for_multiple_choice(*lowerCAmelCase__			)






					def     __SCREAMING_SNAKE_CASE     (   self			):
							_snake_case     	=	self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_albert_for_sequence_classification(*lowerCAmelCase__			)






					def     __SCREAMING_SNAKE_CASE     (   self			):
							_snake_case     	=	self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_albert_for_question_answering(*lowerCAmelCase__			)






					@slow
					def     __SCREAMING_SNAKE_CASE     (   self			):
							for model_name in TF_ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
									_snake_case     	=	TFAlbertModel.from_pretrained(lowerCAmelCase__			)
									self.assertIsNotNone(lowerCAmelCase__			)





@require_tf
class 					lowerCamelCase_							(	unittest.TestCase							):




					'''simple docstring'''






					@slow
					def     __SCREAMING_SNAKE_CASE     (   self			):
							_snake_case     	=	TFAlbertForPreTraining.from_pretrained("albert-base-v2"			)
							_snake_case     	=	tf.constant([[0, 1, 2, 3, 4, 5]]			)
							_snake_case     	=	model(lowerCAmelCase__			)[0]

							_snake_case     	=	[1, 6, 30_000]
							self.assertEqual(output.shape,  lowerCAmelCase__			)

							_snake_case     	=	tf.constant(
							    [
							        [
							            [4.59_56_68, 0.74_46_27_54, -1.81_81_47],
							            [4.5_95_43_47, 0.7_45_41_84, -1.8_18_82_58],
							            [4.5_95_49_05, 0.7_44_82_35, -1.8_18_23_16],
							        ]
							    ]			)
							tf.debugging.assert_near(output[:, :3, :3],  lowerCAmelCase__,  atol=1E-4			)











'''simple docstring'''







from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available


_lowerCamelCase							:						List[Any]							     =  {
    'configuration_mobilenet_v1': [
        'MOBILENET_V1_PRETRAINED_CONFIG_ARCHIVE_MAP',
        'MobileNetV1Config',
        'MobileNetV1OnnxConfig',
    ],
}

try:
						if not is_vision_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						_lowerCamelCase							:						str							     =  ['MobileNetV1FeatureExtractor']
						_lowerCamelCase							:						Tuple							     =  ['MobileNetV1ImageProcessor']

try:
						if not is_torch_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						_lowerCamelCase							:						List[Any]							     =  [
						    'MOBILENET_V1_PRETRAINED_MODEL_ARCHIVE_LIST',
						    'MobileNetV1ForImageClassification',
						    'MobileNetV1Model',
						    'MobileNetV1PreTrainedModel',
						    'load_tf_weights_in_mobilenet_v1',
						]


if TYPE_CHECKING:
						from .configuration_mobilenet_va import (
						    MOBILENET_V1_PRETRAINED_CONFIG_ARCHIVE_MAP,
						    MobileNetVaConfig,
						    MobileNetVaOnnxConfig,
						)

						try:
												if not is_vision_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .feature_extraction_mobilenet_va import MobileNetVaFeatureExtractor
												from .image_processing_mobilenet_va import MobileNetVaImageProcessor

						try:
												if not is_torch_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_mobilenet_va import (
												    MOBILENET_V1_PRETRAINED_MODEL_ARCHIVE_LIST,
												    MobileNetVaForImageClassification,
												    MobileNetVaModel,
												    MobileNetVaPreTrainedModel,
												    load_tf_weights_in_mobilenet_va,
												)


else:
						import sys

						_lowerCamelCase							:						Union[str, Any]							     =  _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)





