"""simple docstring"""






from __future__ import annotations

import unittest

from transformers import FunnelConfig, is_tf_available
from transformers.testing_utils import require_tf

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 (
						    TFFunnelBaseModel,
						    TFFunnelForMaskedLM,
						    TFFunnelForMultipleChoice,
						    TFFunnelForPreTraining,
						    TFFunnelForQuestionAnswering,
						    TFFunnelForSequenceClassification,
						    TFFunnelForTokenClassification,
						    TFFunnelModel,
						)

class lowerCamelCase		:






					'''simple docstring'''


					def __init__(						self			:				Dict   , _snake_case			:				List[Any]   , _snake_case			:				Any=13   , _snake_case			:				Dict=7   , _snake_case			:				Dict=True   , _snake_case			:				Any=True   , _snake_case			:				Tuple=True   , _snake_case			:				List[Any]=True   , _snake_case			:				Optional[int]=99   , _snake_case			:				Optional[Any]=[1, 1, 2]   , _snake_case			:				Optional[Any]=1   , _snake_case			:				List[Any]=32   , _snake_case			:				List[Any]=4   , _snake_case			:				List[str]=8   , _snake_case			:				Optional[Any]=37   , _snake_case			:				Union[str, Any]="gelu_new"   , _snake_case			:				Optional[Any]=0.1   , _snake_case			:				Optional[int]=0.1   , _snake_case			:				Optional[int]=0.0   , _snake_case			:				int=512   , _snake_case			:				Any=3   , _snake_case			:				int=0.02   , _snake_case			:				Any=3   , _snake_case			:				int=4   , _snake_case			:				Union[str, Any]=None   , _snake_case			:				str=False   , )							->       str:
									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__		  =				block_sizes
									SCREAMING_SNAKE_CASE__		  =				num_decoder_layers
									SCREAMING_SNAKE_CASE__		  =				d_model
									SCREAMING_SNAKE_CASE__		  =				n_head
									SCREAMING_SNAKE_CASE__		  =				d_head
									SCREAMING_SNAKE_CASE__		  =				d_inner
									SCREAMING_SNAKE_CASE__		  =				hidden_act
									SCREAMING_SNAKE_CASE__		  =				hidden_dropout
									SCREAMING_SNAKE_CASE__		  =				attention_dropout
									SCREAMING_SNAKE_CASE__		  =				activation_dropout
									SCREAMING_SNAKE_CASE__		  =				max_position_embeddings
									SCREAMING_SNAKE_CASE__		  =				type_vocab_size
									SCREAMING_SNAKE_CASE__		  =				2
									SCREAMING_SNAKE_CASE__		  =				num_labels
									SCREAMING_SNAKE_CASE__		  =				num_choices
									SCREAMING_SNAKE_CASE__		  =				scope
									SCREAMING_SNAKE_CASE__		  =				initializer_std

									# Used in the tests to check the size of the first attention layer
									SCREAMING_SNAKE_CASE__		  =				n_head
									# Used in the tests to check the size of the first hidden state
									SCREAMING_SNAKE_CASE__		  =				self.d_model
									# Used in the tests to check the number of output hidden states/attentions
									SCREAMING_SNAKE_CASE__		  =				sum(self.block_sizes		) + (0 if base else self.num_decoder_layers)
									# FunnelModel adds two hidden layers: input embeddings and the sum of the upsampled encoder hidden state with
									# the last hidden state of the first block (which is the first hidden state of the decoder).
									if not base:
													SCREAMING_SNAKE_CASE__		  =				self.num_hidden_layers + 2



					def 			lowerCAmelCase_					(						self			:				List[Any]		)							->       str:
									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
									if self.use_token_type_ids:
													SCREAMING_SNAKE_CASE__		  =				ids_tensor([self.batch_size, self.seq_length]   , self.type_vocab_size		)

									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__		  =				FunnelConfig(
									    vocab_size=self.vocab_size   , block_sizes=self.block_sizes   , num_decoder_layers=self.num_decoder_layers   , d_model=self.d_model   , n_head=self.n_head   , d_head=self.d_head   , d_inner=self.d_inner   , hidden_act=self.hidden_act   , hidden_dropout=self.hidden_dropout   , attention_dropout=self.attention_dropout   , activation_dropout=self.activation_dropout   , max_position_embeddings=self.max_position_embeddings   , type_vocab_size=self.type_vocab_size   , initializer_std=self.initializer_std   , )

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



					def 			lowerCAmelCase_					(						self			:				Tuple   , _snake_case			:				List[Any]   , _snake_case			:				Union[str, Any]   , _snake_case			:				List[str]   , _snake_case			:				List[Any]   , _snake_case			:				List[str]   , _snake_case			:				Union[str, Any]   , _snake_case			:				List[str]   , )							->       Optional[Any]:
									SCREAMING_SNAKE_CASE__		  =				TFFunnelModel(config=__A		)
									SCREAMING_SNAKE_CASE__		  =				{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
									SCREAMING_SNAKE_CASE__		  =				model(__A		)

									SCREAMING_SNAKE_CASE__		  =				[input_ids, input_mask]
									SCREAMING_SNAKE_CASE__		  =				model(__A		)

									SCREAMING_SNAKE_CASE__		  =				model(__A		)
									self.parent.assertEqual(result.last_hidden_state.shape   , (self.batch_size, self.seq_length, self.d_model)		)

									SCREAMING_SNAKE_CASE__		  =				False
									SCREAMING_SNAKE_CASE__		  =				TFFunnelModel(config=__A		)
									SCREAMING_SNAKE_CASE__		  =				model(__A		)
									self.parent.assertEqual(result.last_hidden_state.shape   , (self.batch_size, self.seq_length, self.d_model)		)

									SCREAMING_SNAKE_CASE__		  =				False
									SCREAMING_SNAKE_CASE__		  =				TFFunnelModel(config=__A		)
									SCREAMING_SNAKE_CASE__		  =				model(__A		)
									self.parent.assertEqual(result.last_hidden_state.shape   , (self.batch_size, self.seq_length, self.d_model)		)



					def 			lowerCAmelCase_					(						self			:				Tuple   , _snake_case			:				str   , _snake_case			:				Optional[Any]   , _snake_case			:				Optional[int]   , _snake_case			:				List[Any]   , _snake_case			:				Dict   , _snake_case			:				Union[str, Any]   , _snake_case			:				str   , )							->       Any:
									SCREAMING_SNAKE_CASE__		  =				TFFunnelBaseModel(config=__A		)
									SCREAMING_SNAKE_CASE__		  =				{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
									SCREAMING_SNAKE_CASE__		  =				model(__A		)

									SCREAMING_SNAKE_CASE__		  =				[input_ids, input_mask]
									SCREAMING_SNAKE_CASE__		  =				model(__A		)

									SCREAMING_SNAKE_CASE__		  =				model(__A		)
									self.parent.assertEqual(result.last_hidden_state.shape   , (self.batch_size, 2, self.d_model)		)

									SCREAMING_SNAKE_CASE__		  =				False
									SCREAMING_SNAKE_CASE__		  =				TFFunnelBaseModel(config=__A		)
									SCREAMING_SNAKE_CASE__		  =				model(__A		)
									self.parent.assertEqual(result.last_hidden_state.shape   , (self.batch_size, 3, self.d_model)		)

									SCREAMING_SNAKE_CASE__		  =				False
									SCREAMING_SNAKE_CASE__		  =				TFFunnelBaseModel(config=__A		)
									SCREAMING_SNAKE_CASE__		  =				model(__A		)
									self.parent.assertEqual(result.last_hidden_state.shape   , (self.batch_size, 2, self.d_model)		)



					def 			lowerCAmelCase_					(						self			:				str   , _snake_case			:				List[str]   , _snake_case			:				Union[str, Any]   , _snake_case			:				Any   , _snake_case			:				Optional[int]   , _snake_case			:				List[Any]   , _snake_case			:				List[str]   , _snake_case			:				Tuple   , )							->       Optional[int]:
									SCREAMING_SNAKE_CASE__		  =				TFFunnelForPreTraining(config=__A		)
									SCREAMING_SNAKE_CASE__		  =				{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
									SCREAMING_SNAKE_CASE__		  =				model(__A		)
									self.parent.assertEqual(result.logits.shape   , (self.batch_size, self.seq_length)		)



					def 			lowerCAmelCase_					(						self			:				Optional[int]   , _snake_case			:				Optional[Any]   , _snake_case			:				List[Any]   , _snake_case			:				List[str]   , _snake_case			:				List[Any]   , _snake_case			:				List[Any]   , _snake_case			:				Any   , _snake_case			:				List[str]   , )							->       Union[str, Any]:
									SCREAMING_SNAKE_CASE__		  =				TFFunnelForMaskedLM(config=__A		)
									SCREAMING_SNAKE_CASE__		  =				{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
									SCREAMING_SNAKE_CASE__		  =				model(__A		)
									self.parent.assertEqual(result.logits.shape   , (self.batch_size, self.seq_length, self.vocab_size)		)



					def 			lowerCAmelCase_					(						self			:				Tuple   , _snake_case			:				Dict   , _snake_case			:				Dict   , _snake_case			:				Union[str, Any]   , _snake_case			:				int   , _snake_case			:				Union[str, Any]   , _snake_case			:				int   , _snake_case			:				List[Any]   , )							->       Any:
									SCREAMING_SNAKE_CASE__		  =				self.num_labels
									SCREAMING_SNAKE_CASE__		  =				TFFunnelForSequenceClassification(config=__A		)
									SCREAMING_SNAKE_CASE__		  =				{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
									SCREAMING_SNAKE_CASE__		  =				model(__A		)
									self.parent.assertEqual(result.logits.shape   , (self.batch_size, self.num_labels)		)



					def 			lowerCAmelCase_					(						self			:				Any   , _snake_case			:				Optional[Any]   , _snake_case			:				Dict   , _snake_case			:				Optional[Any]   , _snake_case			:				Optional[int]   , _snake_case			:				Dict   , _snake_case			:				Union[str, Any]   , _snake_case			:				Union[str, Any]   , )							->       Tuple:
									SCREAMING_SNAKE_CASE__		  =				self.num_choices
									SCREAMING_SNAKE_CASE__		  =				TFFunnelForMultipleChoice(config=__A		)
									SCREAMING_SNAKE_CASE__		  =				tf.tile(tf.expand_dims(__A   , 1		)   , (1, self.num_choices, 1)		)
									SCREAMING_SNAKE_CASE__		  =				tf.tile(tf.expand_dims(__A   , 1		)   , (1, self.num_choices, 1)		)
									SCREAMING_SNAKE_CASE__		  =				tf.tile(tf.expand_dims(__A   , 1		)   , (1, self.num_choices, 1)		)
									SCREAMING_SNAKE_CASE__		  =				{
									    "input_ids": multiple_choice_inputs_ids,
									    "attention_mask": multiple_choice_input_mask,
									    "token_type_ids": multiple_choice_token_type_ids,
									}
									SCREAMING_SNAKE_CASE__		  =				model(__A		)
									self.parent.assertEqual(result.logits.shape   , (self.batch_size, self.num_choices)		)



					def 			lowerCAmelCase_					(						self			:				int   , _snake_case			:				str   , _snake_case			:				int   , _snake_case			:				int   , _snake_case			:				Tuple   , _snake_case			:				List[Any]   , _snake_case			:				List[str]   , _snake_case			:				Dict   , )							->       Tuple:
									SCREAMING_SNAKE_CASE__		  =				self.num_labels
									SCREAMING_SNAKE_CASE__		  =				TFFunnelForTokenClassification(config=__A		)
									SCREAMING_SNAKE_CASE__		  =				{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
									SCREAMING_SNAKE_CASE__		  =				model(__A		)
									self.parent.assertEqual(result.logits.shape   , (self.batch_size, self.seq_length, self.num_labels)		)



					def 			lowerCAmelCase_					(						self			:				Tuple   , _snake_case			:				Tuple   , _snake_case			:				int   , _snake_case			:				Any   , _snake_case			:				Any   , _snake_case			:				List[Any]   , _snake_case			:				List[str]   , _snake_case			:				Dict   , )							->       Tuple:
									SCREAMING_SNAKE_CASE__		  =				TFFunnelForQuestionAnswering(config=__A		)
									SCREAMING_SNAKE_CASE__		  =				{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
									SCREAMING_SNAKE_CASE__		  =				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			:				int		)							->       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__				
									)  ,       (
									    SCREAMING_SNAKE_CASE__				
									)  ,       				
									)		  =				config_and_inputs
									SCREAMING_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'''


					a   	=		(
					    (
					        TFFunnelModel,
					        TFFunnelForMaskedLM,
					        TFFunnelForPreTraining,
					        TFFunnelForQuestionAnswering,
					        TFFunnelForTokenClassification,
					    )
					    if is_tf_available()
					    else ()
					)
					a   	=		(
					    {
					        'feature-extraction': (TFFunnelBaseModel, TFFunnelModel),
					        'fill-mask': TFFunnelForMaskedLM,
					        'question-answering': TFFunnelForQuestionAnswering,
					        'text-classification': TFFunnelForSequenceClassification,
					        'token-classification': TFFunnelForTokenClassification,
					        'zero-shot': TFFunnelForSequenceClassification,
					    }
					    if is_tf_available()
					    else {}
					)
					a   	=		False
					a   	=		False



					def 			lowerCAmelCase_					(						self			:				List[Any]		)							->       Dict:
									SCREAMING_SNAKE_CASE__		  =				TFFunnelModelTester(self		)
									SCREAMING_SNAKE_CASE__		  =				ConfigTester(self   , config_class=__A		)



					def 			lowerCAmelCase_					(						self			:				str		)							->       List[str]:
									self.config_tester.run_common_tests()



					def 			lowerCAmelCase_					(						self			:				List[Any]		)							->       Optional[Any]:
									SCREAMING_SNAKE_CASE__		  =				self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_model(*__A		)



					def 			lowerCAmelCase_					(						self			:				List[str]		)							->       List[Any]:
									SCREAMING_SNAKE_CASE__		  =				self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_pretraining(*__A		)



					def 			lowerCAmelCase_					(						self			:				Any		)							->       str:
									SCREAMING_SNAKE_CASE__		  =				self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_masked_lm(*__A		)



					def 			lowerCAmelCase_					(						self			:				Union[str, Any]		)							->       List[str]:
									SCREAMING_SNAKE_CASE__		  =				self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_token_classification(*__A		)



					def 			lowerCAmelCase_					(						self			:				Tuple		)							->       str:
									SCREAMING_SNAKE_CASE__		  =				self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_question_answering(*__A		)



@require_tf
class lowerCamelCase		(__lowercase    ,    unittest.TestCase      ):






					'''simple docstring'''


					a   	=		(
					    (TFFunnelBaseModel, TFFunnelForMultipleChoice, TFFunnelForSequenceClassification) if is_tf_available() else ()
					)
					a   	=		False
					a   	=		False



					def 			lowerCAmelCase_					(						self			:				Union[str, Any]		)							->       Optional[int]:
									SCREAMING_SNAKE_CASE__		  =				TFFunnelModelTester(self   , base=__A		)
									SCREAMING_SNAKE_CASE__		  =				ConfigTester(self   , config_class=__A		)



					def 			lowerCAmelCase_					(						self			:				Tuple		)							->       Optional[Any]:
									self.config_tester.run_common_tests()



					def 			lowerCAmelCase_					(						self			:				List[str]		)							->       int:
									SCREAMING_SNAKE_CASE__		  =				self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_base_model(*__A		)



					def 			lowerCAmelCase_					(						self			:				Optional[int]		)							->       List[str]:
									SCREAMING_SNAKE_CASE__		  =				self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_sequence_classification(*__A		)



					def 			lowerCAmelCase_					(						self			:				Dict		)							->       List[Any]:
									SCREAMING_SNAKE_CASE__		  =				self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_multiple_choice(*__A		)

"""simple docstring"""






import unittest

from transformers import AlbertConfig, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import 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 (
						    MODEL_FOR_PRETRAINING_MAPPING,
						    AlbertForMaskedLM,
						    AlbertForMultipleChoice,
						    AlbertForPreTraining,
						    AlbertForQuestionAnswering,
						    AlbertForSequenceClassification,
						    AlbertForTokenClassification,
						    AlbertModel,
						)
						from transformers.models.albert.modeling_albert import ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST

class lowerCamelCase		:






					'''simple docstring'''


					def __init__(						self			:				str   , _snake_case			:				List[str]   , _snake_case			:				List[Any]=13   , _snake_case			:				List[str]=7   , _snake_case			:				Dict=True   , _snake_case			:				str=True   , _snake_case			:				Optional[Any]=True   , _snake_case			:				Tuple=True   , _snake_case			:				List[Any]=99   , _snake_case			:				Dict=16   , _snake_case			:				Tuple=36   , _snake_case			:				Optional[int]=6   , _snake_case			:				Optional[int]=6   , _snake_case			:				Tuple=6   , _snake_case			:				Optional[int]=37   , _snake_case			:				Dict="gelu"   , _snake_case			:				str=0.1   , _snake_case			:				Tuple=0.1   , _snake_case			:				List[str]=512   , _snake_case			:				Any=16   , _snake_case			:				Optional[int]=2   , _snake_case			:				Optional[int]=0.02   , _snake_case			:				Union[str, Any]=3   , _snake_case			:				int=4   , _snake_case			:				Optional[int]=None   , )							->       List[str]:
									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__		  =				embedding_size
									SCREAMING_SNAKE_CASE__		  =				hidden_size
									SCREAMING_SNAKE_CASE__		  =				num_hidden_layers
									SCREAMING_SNAKE_CASE__		  =				num_hidden_groups
									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



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

									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, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels



					def 			lowerCAmelCase_					(						self			:				Dict		)							->       Union[str, Any]:
									return AlbertConfig(
									    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   , num_hidden_groups=self.num_hidden_groups   , )



					def 			lowerCAmelCase_					(						self			:				int   , _snake_case			:				Tuple   , _snake_case			:				Optional[Any]   , _snake_case			:				Union[str, Any]   , _snake_case			:				int   , _snake_case			:				Union[str, Any]   , _snake_case			:				str   , _snake_case			:				int		)							->       Union[str, Any]:
									SCREAMING_SNAKE_CASE__		  =				AlbertModel(config=_snake_case		)
									model.to(_snake_case		)
									model.eval()
									SCREAMING_SNAKE_CASE__		  =				model(_snake_case   , attention_mask=_snake_case   , token_type_ids=_snake_case		)
									SCREAMING_SNAKE_CASE__		  =				model(_snake_case   , token_type_ids=_snake_case		)
									SCREAMING_SNAKE_CASE__		  =				model(_snake_case		)
									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			:				Tuple   , _snake_case			:				Optional[Any]   , _snake_case			:				int   , _snake_case			:				str   , _snake_case			:				List[Any]   , _snake_case			:				Dict   , _snake_case			:				Union[str, Any]   , _snake_case			:				str		)							->       Union[str, Any]:
									SCREAMING_SNAKE_CASE__		  =				AlbertForPreTraining(config=_snake_case		)
									model.to(_snake_case		)
									model.eval()
									SCREAMING_SNAKE_CASE__		  =				model(
									    _snake_case   , attention_mask=_snake_case   , token_type_ids=_snake_case   , labels=_snake_case   , sentence_order_label=_snake_case   , )
									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, config.num_labels)		)



					def 			lowerCAmelCase_					(						self			:				Union[str, Any]   , _snake_case			:				int   , _snake_case			:				Any   , _snake_case			:				List[Any]   , _snake_case			:				Any   , _snake_case			:				str   , _snake_case			:				Tuple   , _snake_case			:				List[Any]		)							->       Any:
									SCREAMING_SNAKE_CASE__		  =				AlbertForMaskedLM(config=_snake_case		)
									model.to(_snake_case		)
									model.eval()
									SCREAMING_SNAKE_CASE__		  =				model(_snake_case   , attention_mask=_snake_case   , token_type_ids=_snake_case   , labels=_snake_case		)
									self.parent.assertEqual(result.logits.shape   , (self.batch_size, self.seq_length, self.vocab_size)		)



					def 			lowerCAmelCase_					(						self			:				Optional[Any]   , _snake_case			:				Optional[Any]   , _snake_case			:				Optional[Any]   , _snake_case			:				Optional[Any]   , _snake_case			:				Any   , _snake_case			:				Optional[int]   , _snake_case			:				Optional[Any]   , _snake_case			:				Tuple		)							->       List[str]:
									SCREAMING_SNAKE_CASE__		  =				AlbertForQuestionAnswering(config=_snake_case		)
									model.to(_snake_case		)
									model.eval()
									SCREAMING_SNAKE_CASE__		  =				model(
									    _snake_case   , attention_mask=_snake_case   , token_type_ids=_snake_case   , start_positions=_snake_case   , end_positions=_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			:				Optional[Any]   , _snake_case			:				Optional[Any]   , _snake_case			:				str   , _snake_case			:				Optional[int]   , _snake_case			:				int   , _snake_case			:				List[Any]   , _snake_case			:				List[Any]   , _snake_case			:				str		)							->       Optional[int]:
									SCREAMING_SNAKE_CASE__		  =				self.num_labels
									SCREAMING_SNAKE_CASE__		  =				AlbertForSequenceClassification(_snake_case		)
									model.to(_snake_case		)
									model.eval()
									SCREAMING_SNAKE_CASE__		  =				model(_snake_case   , attention_mask=_snake_case   , token_type_ids=_snake_case   , labels=_snake_case		)
									self.parent.assertEqual(result.logits.shape   , (self.batch_size, self.num_labels)		)



					def 			lowerCAmelCase_					(						self			:				int   , _snake_case			:				Any   , _snake_case			:				str   , _snake_case			:				List[Any]   , _snake_case			:				Any   , _snake_case			:				Union[str, Any]   , _snake_case			:				Dict   , _snake_case			:				Tuple		)							->       Dict:
									SCREAMING_SNAKE_CASE__		  =				self.num_labels
									SCREAMING_SNAKE_CASE__		  =				AlbertForTokenClassification(config=_snake_case		)
									model.to(_snake_case		)
									model.eval()
									SCREAMING_SNAKE_CASE__		  =				model(_snake_case   , attention_mask=_snake_case   , token_type_ids=_snake_case   , labels=_snake_case		)
									self.parent.assertEqual(result.logits.shape   , (self.batch_size, self.seq_length, self.num_labels)		)



					def 			lowerCAmelCase_					(						self			:				Tuple   , _snake_case			:				str   , _snake_case			:				Any   , _snake_case			:				Any   , _snake_case			:				int   , _snake_case			:				List[Any]   , _snake_case			:				List[str]   , _snake_case			:				int		)							->       List[str]:
									SCREAMING_SNAKE_CASE__		  =				self.num_choices
									SCREAMING_SNAKE_CASE__		  =				AlbertForMultipleChoice(config=_snake_case		)
									model.to(_snake_case		)
									model.eval()
									SCREAMING_SNAKE_CASE__		  =				input_ids.unsqueeze(1		).expand(-1   , self.num_choices   , -1		).contiguous()
									SCREAMING_SNAKE_CASE__		  =				token_type_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(
									    _snake_case   , attention_mask=_snake_case   , token_type_ids=_snake_case   , labels=_snake_case   , )
									self.parent.assertEqual(result.logits.shape   , (self.batch_size, self.num_choices)		)



					def 			lowerCAmelCase_					(						self			:				Optional[int]		)							->       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__
									)  ,       (
									    SCREAMING_SNAKE_CASE__
									)  ,       
									)		  =				config_and_inputs
									SCREAMING_SNAKE_CASE__		  =				{"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
									return config, inputs_dict



@require_torch
class lowerCamelCase		(_SCREAMING_SNAKE_CASE    ,    _SCREAMING_SNAKE_CASE    ,    unittest.TestCase      ):






					'''simple docstring'''


					a   	=		(
					    (
					        AlbertModel,
					        AlbertForPreTraining,
					        AlbertForMaskedLM,
					        AlbertForMultipleChoice,
					        AlbertForSequenceClassification,
					        AlbertForTokenClassification,
					        AlbertForQuestionAnswering,
					    )
					    if is_torch_available()
					    else ()
					)
					a   	=		(
					    {
					        "feature-extraction": AlbertModel,
					        "fill-mask": AlbertForMaskedLM,
					        "question-answering": AlbertForQuestionAnswering,
					        "text-classification": AlbertForSequenceClassification,
					        "token-classification": AlbertForTokenClassification,
					        "zero-shot": AlbertForSequenceClassification,
					    }
					    if is_torch_available()
					    else {}
					)
					a   	=		True



					def 			lowerCAmelCase_					(						self			:				Union[str, Any]   , _snake_case			:				Dict   , _snake_case			:				str   , _snake_case			:				str=False		)							->       Dict:
									SCREAMING_SNAKE_CASE__		  =				super()._prepare_for_class(_snake_case   , _snake_case   , return_labels=_snake_case		)

									if return_labels:
													if model_class in get_values(_snake_case		):
																	SCREAMING_SNAKE_CASE__		  =				torch.zeros(
																	    (self.model_tester.batch_size, self.model_tester.seq_length)   , dtype=torch.long   , device=_snake_case		)
																	SCREAMING_SNAKE_CASE__		  =				torch.zeros(
																	    self.model_tester.batch_size   , dtype=torch.long   , device=_snake_case		)
									return inputs_dict



					def 			lowerCAmelCase_					(						self			:				Union[str, Any]		)							->       List[Any]:
									SCREAMING_SNAKE_CASE__		  =				AlbertModelTester(self		)
									SCREAMING_SNAKE_CASE__		  =				ConfigTester(self   , config_class=_snake_case   , hidden_size=37		)



					def 			lowerCAmelCase_					(						self			:				List[str]		)							->       List[str]:
									self.config_tester.run_common_tests()



					def 			lowerCAmelCase_					(						self			:				Dict		)							->       Union[str, Any]:
									SCREAMING_SNAKE_CASE__		  =				self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_model(*_snake_case		)



					def 			lowerCAmelCase_					(						self			:				Union[str, Any]		)							->       Tuple:
									SCREAMING_SNAKE_CASE__		  =				self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_pretraining(*_snake_case		)



					def 			lowerCAmelCase_					(						self			:				Any		)							->       Union[str, Any]:
									SCREAMING_SNAKE_CASE__		  =				self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_masked_lm(*_snake_case		)



					def 			lowerCAmelCase_					(						self			:				Union[str, Any]		)							->       Optional[Any]:
									SCREAMING_SNAKE_CASE__		  =				self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_multiple_choice(*_snake_case		)



					def 			lowerCAmelCase_					(						self			:				Optional[Any]		)							->       List[Any]:
									SCREAMING_SNAKE_CASE__		  =				self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_question_answering(*_snake_case		)



					def 			lowerCAmelCase_					(						self			:				Optional[Any]		)							->       Optional[Any]:
									SCREAMING_SNAKE_CASE__		  =				self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_sequence_classification(*_snake_case		)



					def 			lowerCAmelCase_					(						self			:				List[str]		)							->       Optional[int]:
									SCREAMING_SNAKE_CASE__		  =				self.model_tester.prepare_config_and_inputs()
									for type in ["absolute", "relative_key", "relative_key_query"]:
													SCREAMING_SNAKE_CASE__		  =				type
													self.model_tester.create_and_check_model(*_snake_case		)



					@slow
					def 			lowerCAmelCase_					(						self			:				Any		)							->       str:
									for model_name in ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
													SCREAMING_SNAKE_CASE__		  =				AlbertModel.from_pretrained(_snake_case		)
													self.assertIsNotNone(_snake_case		)



@require_torch
class lowerCamelCase		(unittest.TestCase      ):






					'''simple docstring'''


					@slow
					def 			lowerCAmelCase_					(						self			:				Any		)							->       Any:
									SCREAMING_SNAKE_CASE__		  =				AlbertModel.from_pretrained("albert-base-v2"		)
									SCREAMING_SNAKE_CASE__		  =				torch.tensor([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]]		)
									SCREAMING_SNAKE_CASE__		  =				torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]		)
									with torch.no_grad():
													SCREAMING_SNAKE_CASE__		  =				model(_snake_case   , attention_mask=_snake_case		)[0]
									SCREAMING_SNAKE_CASE__		  =				torch.Size((1, 11, 768)		)
									self.assertEqual(output.shape   , _snake_case		)
									SCREAMING_SNAKE_CASE__		  =				torch.tensor(
									    [[[-0.6513, 1.5035, -0.2766], [-0.6515, 1.5046, -0.2780], [-0.6512, 1.5049, -0.2784]]]		)

									self.assertTrue(torch.allclose(output[:, 1:4, 1:4]   , _snake_case   , atol=1e-4		)		)




