

"""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    :

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

									"""simple docstring"""
									lowercase										=							parent
									lowercase										=							13
									lowercase										=							7
									lowercase										=							True
									lowercase										=							True
									lowercase										=							True
									lowercase										=							True
									lowercase										=							99
									lowercase										=							16
									lowercase										=							32
									lowercase										=							2
									lowercase										=							4
									lowercase										=							37
									lowercase										=							'''gelu'''
									lowercase										=							0.1
									lowercase										=							0.1
									lowercase										=							512
									lowercase										=							16
									lowercase										=							2
									lowercase										=							0.02
									lowercase										=							3
									lowercase										=							4
									lowercase										=							None

							def 					_lowerCAmelCase  ( self       :    Any    )   ->    Optional[Any]:

									"""simple docstring"""
									lowercase										=							ids_tensor([self.batch_size, self.seq_length] ,		self.vocab_size    )

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

									lowercase										=							None
									if self.use_token_type_ids:
											lowercase										=							ids_tensor([self.batch_size, self.seq_length] ,		self.type_vocab_size    )

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

									lowercase										=							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 					_lowerCAmelCase  ( self       :    Dict ,		a       :    Optional[int] ,		a       :    Union[str, Any] ,		a       :    Any ,		a       :    Optional[int] ,		a       :    List[str] ,		a       :    Optional[int] ,		a       :    Optional[int]    )   ->    Optional[Any]:

									"""simple docstring"""
									lowercase										=							TFAlbertModel(config=a    )
									# inputs = {'input_ids': input_ids,
									#           'attention_mask': input_mask,
									#           'token_type_ids': token_type_ids}
									# sequence_output, pooled_output = model(**inputs)
									lowercase										=							{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
									lowercase										=							model(a    )

									lowercase										=							[input_ids, input_mask]
									lowercase										=							model(a    )

									lowercase										=							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 					_lowerCAmelCase  ( self       :    Optional[int] ,		a       :    int ,		a       :    List[str] ,		a       :    Union[str, Any] ,		a       :    List[str] ,		a       :    str ,		a       :    Union[str, Any] ,		a       :    List[str]    )   ->    List[str]:

									"""simple docstring"""
									lowercase										=							self.num_labels
									lowercase										=							TFAlbertForPreTraining(config=a    )
									lowercase										=							{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
									lowercase										=							model(a    )
									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 					_lowerCAmelCase  ( self       :    Union[str, Any] ,		a       :    Any ,		a       :    Dict ,		a       :    Union[str, Any] ,		a       :    str ,		a       :    str ,		a       :    Tuple ,		a       :    str    )   ->    Union[str, Any]:

									"""simple docstring"""
									lowercase										=							TFAlbertForMaskedLM(config=a    )
									lowercase										=							{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
									lowercase										=							model(a    )
									self.parent.assertEqual(result.logits.shape ,		(self.batch_size, self.seq_length, self.vocab_size)    )

							def 					_lowerCAmelCase  ( self       :    Optional[Any] ,		a       :    int ,		a       :    Optional[int] ,		a       :    Optional[int] ,		a       :    List[Any] ,		a       :    Optional[Any] ,		a       :    Optional[Any] ,		a       :    Optional[int]    )   ->    List[Any]:

									"""simple docstring"""
									lowercase										=							self.num_labels
									lowercase										=							TFAlbertForSequenceClassification(config=a    )
									lowercase										=							{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
									lowercase										=							model(a    )
									self.parent.assertEqual(result.logits.shape ,		(self.batch_size, self.num_labels)    )

							def 					_lowerCAmelCase  ( self       :    List[Any] ,		a       :    Dict ,		a       :    Any ,		a       :    Optional[Any] ,		a       :    Optional[int] ,		a       :    Dict ,		a       :    List[str] ,		a       :    List[str]    )   ->    Any:

									"""simple docstring"""
									lowercase										=							TFAlbertForQuestionAnswering(config=a    )
									lowercase										=							{'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
									lowercase										=							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 					_lowerCAmelCase  ( self       :    Union[str, Any] ,		a       :    str ,		a       :    Optional[Any] ,		a       :    str ,		a       :    str ,		a       :    Optional[Any] ,		a       :    Union[str, Any] ,		a       :    List[Any]    )   ->    Any:

									"""simple docstring"""
									lowercase										=							self.num_choices
									lowercase										=							TFAlbertForMultipleChoice(config=a    )
									lowercase										=							tf.tile(tf.expand_dims(a ,		1    ) ,		(1, self.num_choices, 1)    )
									lowercase										=							tf.tile(tf.expand_dims(a ,		1    ) ,		(1, self.num_choices, 1)    )
									lowercase										=							tf.tile(tf.expand_dims(a ,		1    ) ,		(1, self.num_choices, 1)    )
									lowercase										=							{
									    '''input_ids''': multiple_choice_inputs_ids,
									    '''attention_mask''': multiple_choice_input_mask,
									    '''token_type_ids''': multiple_choice_token_type_ids,
									}
									lowercase										=							model(a    )
									self.parent.assertListEqual(list(result['''logits'''].shape    ) ,		[self.batch_size, self.num_choices]    )

							def 					_lowerCAmelCase  ( self       :    List[str] ,		a       :    Dict ,		a       :    Union[str, Any] ,		a       :    Any ,		a       :    Tuple ,		a       :    List[Any] ,		a       :    List[Any] ,		a       :    str    )   ->    Union[str, Any]:

									"""simple docstring"""
									lowercase										=							self.num_labels
									lowercase										=							TFAlbertForTokenClassification(config=a    )
									lowercase										=							{
									    '''input_ids''': input_ids,
									    '''attention_mask''': input_mask,
									    '''token_type_ids''': token_type_ids,
									}
									lowercase										=							model(a    )
									self.parent.assertListEqual(list(result['''logits'''].shape    ) ,		[self.batch_size, self.seq_length, self.num_labels]    )

							def 					_lowerCAmelCase  ( self       :    Tuple    )   ->    Any:

									"""simple docstring"""
									lowercase										=							self.prepare_config_and_inputs()
									(
									    (
									    lowercase
									)					,  (
									    lowercase
									)					,  (
									    lowercase
									)					,  (
									    lowercase
									)					,  (
									    lowercase
									)					,  (
									    lowercase
									)					,  (
									    lowercase
									)					,  
									)										=							config_and_inputs
									lowercase										=							{'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
									return config, inputs_dict




@require_tf
class 	_lowerCAmelCase    (      __snake_case       ,       __snake_case       ,       unittest.TestCase       ):
							__lowerCAmelCase					:    str     =  (
							    (
							        TFAlbertModel,
							        TFAlbertForPreTraining,
							        TFAlbertForMaskedLM,
							        TFAlbertForSequenceClassification,
							        TFAlbertForQuestionAnswering,
							        TFAlbertForTokenClassification,
							        TFAlbertForMultipleChoice,
							    )
							    if is_tf_available()
							    else ()
							)
							__lowerCAmelCase					:    Any     =  (
							    {
							        '''feature-extraction''': TFAlbertModel,
							        '''fill-mask''': TFAlbertForMaskedLM,
							        '''question-answering''': TFAlbertForQuestionAnswering,
							        '''text-classification''': TFAlbertForSequenceClassification,
							        '''token-classification''': TFAlbertForTokenClassification,
							        '''zero-shot''': TFAlbertForSequenceClassification,
							    }
							    if is_tf_available()
							    else {}
							)
							__lowerCAmelCase					:    Dict     =  False
							__lowerCAmelCase					:    List[str]     =  False

							def 					_lowerCAmelCase  ( self       :    Dict ,		a       :    List[str] ,		a       :    Union[str, Any] ,		a       :    str=False    )   ->    Union[str, Any]:

									"""simple docstring"""
									lowercase										=							super()._prepare_for_class(a ,		a ,		return_labels=a    )

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

									return inputs_dict

							def 					_lowerCAmelCase  ( self       :    Optional[Any]    )   ->    Optional[Any]:

									"""simple docstring"""
									lowercase										=							TFAlbertModelTester(self    )
									lowercase										=							ConfigTester(self ,		config_class=a ,		hidden_size=37    )

							def 					_lowerCAmelCase  ( self       :    Dict    )   ->    Optional[Any]:

									"""simple docstring"""
									self.config_tester.run_common_tests()

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

									"""simple docstring"""
									lowercase										=							self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_albert_model(*a    )

							def 					_lowerCAmelCase  ( self       :    Tuple    )   ->    Dict:

									"""simple docstring"""
									lowercase										=							self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_albert_for_pretraining(*a    )

							def 					_lowerCAmelCase  ( self       :    Dict    )   ->    Dict:

									"""simple docstring"""
									lowercase										=							self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_albert_for_masked_lm(*a    )

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

									"""simple docstring"""
									lowercase										=							self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_albert_for_multiple_choice(*a    )

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

									"""simple docstring"""
									lowercase										=							self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_albert_for_sequence_classification(*a    )

							def 					_lowerCAmelCase  ( self       :    str    )   ->    Optional[int]:

									"""simple docstring"""
									lowercase										=							self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_albert_for_question_answering(*a    )

							@slow
							def 					_lowerCAmelCase  ( self       :    Any    )   ->    Tuple:

									"""simple docstring"""
									for model_name in TF_ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
											lowercase										=							TFAlbertModel.from_pretrained(a    )
											self.assertIsNotNone(a    )




@require_tf
class 	_lowerCAmelCase    (      unittest.TestCase       ):

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

									"""simple docstring"""
									lowercase										=							TFAlbertForPreTraining.from_pretrained('''albert-base-v2'''    )
									lowercase										=							tf.constant([[0, 1, 2, 3, 4, 5]]    )
									lowercase										=							model(a    )[0]

									lowercase										=							[1, 6, 30000]
									self.assertEqual(output.shape ,		a    )

									lowercase										=							tf.constant(
									    [
									        [
									            [4.595_668, 0.74_462_754, -1.818_147],
									            [4.5_954_347, 0.7_454_184, -1.8_188_258],
									            [4.5_954_905, 0.7_448_235, -1.8_182_316],
									        ]
									    ]    )
									tf.debugging.assert_near(output[:, :3, :3] ,		a ,		atol=1E-4    )


"""simple docstring"""






import warnings

from ...utils import logging
from .image_processing_convnext import ConvNextImageProcessor


__lowerCAmelCase				      =   logging.get_logger(__name__)
class 	_lowerCAmelCase    (      __snake_case       ):

							def __init__( self       :    Dict ,		*a       :    Any ,		**a       :    List[str]    )   ->    None:

									"""simple docstring"""
									warnings.warn(
									    '''The class ConvNextFeatureExtractor is deprecated and will be removed in version 5 of Transformers.'''
									    ''' Please use ConvNextImageProcessor instead.''' ,		a ,		)
									super().__init__(*a ,		**a    )