


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


							def __init__(self      ,				lowerCAmelCase      ,				lowerCAmelCase=1_3      ,				lowerCAmelCase=7      ,				lowerCAmelCase=True      ,				lowerCAmelCase=True      ,				lowerCAmelCase=True      ,				lowerCAmelCase=True      ,				lowerCAmelCase=9_9      ,				lowerCAmelCase=1_6      ,				lowerCAmelCase=3_6      ,				lowerCAmelCase=6      ,				lowerCAmelCase=6      ,				lowerCAmelCase=6      ,				lowerCAmelCase=3_7      ,				lowerCAmelCase="gelu"      ,				lowerCAmelCase=0.1      ,				lowerCAmelCase=0.1      ,				lowerCAmelCase=5_1_2      ,				lowerCAmelCase=1_6      ,				lowerCAmelCase=2      ,				lowerCAmelCase=0.02      ,				lowerCAmelCase=3      ,				lowerCAmelCase=4      ,				lowerCAmelCase=None      ,				):
									__lowercase=			parent
									__lowercase=			batch_size
									__lowercase=			seq_length
									__lowercase=			is_training
									__lowercase=			use_input_mask
									__lowercase=			use_token_type_ids
									__lowercase=			use_labels
									__lowercase=			vocab_size
									__lowercase=			embedding_size
									__lowercase=			hidden_size
									__lowercase=			num_hidden_layers
									__lowercase=			num_hidden_groups
									__lowercase=			num_attention_heads
									__lowercase=			intermediate_size
									__lowercase=			hidden_act
									__lowercase=			hidden_dropout_prob
									__lowercase=			attention_probs_dropout_prob
									__lowercase=			max_position_embeddings
									__lowercase=			type_vocab_size
									__lowercase=			type_sequence_label_size
									__lowercase=			initializer_range
									__lowercase=			num_labels
									__lowercase=			num_choices
									__lowercase=			scope


							def 			_A       (self					):
									__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=			self.get_config()

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


							def 			_A       (self					):
									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 			_A       (self      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase					):
									__lowercase=			AlbertModel(config=__UpperCamelCase					)
									model.to(__UpperCamelCase					)
									model.eval()
									__lowercase=			model(__UpperCamelCase      ,				attention_mask=__UpperCamelCase      ,				token_type_ids=__UpperCamelCase					)
									__lowercase=			model(__UpperCamelCase      ,				token_type_ids=__UpperCamelCase					)
									__lowercase=			model(__UpperCamelCase					)
									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 			_A       (self      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase					):
									__lowercase=			AlbertForPreTraining(config=__UpperCamelCase					)
									model.to(__UpperCamelCase					)
									model.eval()
									__lowercase=			model(
									    __UpperCamelCase      ,				attention_mask=__UpperCamelCase      ,				token_type_ids=__UpperCamelCase      ,				labels=__UpperCamelCase      ,				sentence_order_label=__UpperCamelCase      ,				)
									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 			_A       (self      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase					):
									__lowercase=			AlbertForMaskedLM(config=__UpperCamelCase					)
									model.to(__UpperCamelCase					)
									model.eval()
									__lowercase=			model(__UpperCamelCase      ,				attention_mask=__UpperCamelCase      ,				token_type_ids=__UpperCamelCase      ,				labels=__UpperCamelCase					)
									self.parent.assertEqual(result.logits.shape      ,				(self.batch_size, self.seq_length, self.vocab_size)					)


							def 			_A       (self      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase					):
									__lowercase=			AlbertForQuestionAnswering(config=__UpperCamelCase					)
									model.to(__UpperCamelCase					)
									model.eval()
									__lowercase=			model(
									    __UpperCamelCase      ,				attention_mask=__UpperCamelCase      ,				token_type_ids=__UpperCamelCase      ,				start_positions=__UpperCamelCase      ,				end_positions=__UpperCamelCase      ,				)
									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 			_A       (self      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase					):
									__lowercase=			self.num_labels
									__lowercase=			AlbertForSequenceClassification(__UpperCamelCase					)
									model.to(__UpperCamelCase					)
									model.eval()
									__lowercase=			model(__UpperCamelCase      ,				attention_mask=__UpperCamelCase      ,				token_type_ids=__UpperCamelCase      ,				labels=__UpperCamelCase					)
									self.parent.assertEqual(result.logits.shape      ,				(self.batch_size, self.num_labels)					)


							def 			_A       (self      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase					):
									__lowercase=			self.num_labels
									__lowercase=			AlbertForTokenClassification(config=__UpperCamelCase					)
									model.to(__UpperCamelCase					)
									model.eval()
									__lowercase=			model(__UpperCamelCase      ,				attention_mask=__UpperCamelCase      ,				token_type_ids=__UpperCamelCase      ,				labels=__UpperCamelCase					)
									self.parent.assertEqual(result.logits.shape      ,				(self.batch_size, self.seq_length, self.num_labels)					)


							def 			_A       (self      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase					):
									__lowercase=			self.num_choices
									__lowercase=			AlbertForMultipleChoice(config=__UpperCamelCase					)
									model.to(__UpperCamelCase					)
									model.eval()
									__lowercase=			input_ids.unsqueeze(1					).expand(-1      ,				self.num_choices      ,				-1					).contiguous()
									__lowercase=			token_type_ids.unsqueeze(1					).expand(-1      ,				self.num_choices      ,				-1					).contiguous()
									__lowercase=			input_mask.unsqueeze(1					).expand(-1      ,				self.num_choices      ,				-1					).contiguous()
									__lowercase=			model(
									    __UpperCamelCase      ,				attention_mask=__UpperCamelCase      ,				token_type_ids=__UpperCamelCase      ,				labels=__UpperCamelCase      ,				)
									self.parent.assertEqual(result.logits.shape      ,				(self.batch_size, self.num_choices)					)







							def 			_A       (self					):
									__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_torch
class       A    (   lowercase_					,				lowercase_					,				unittest.TestCase ):
							UpperCamelCase_   :							Optional[Any]       =(
							    (
							        AlbertModel,
							        AlbertForPreTraining,
							        AlbertForMaskedLM,
							        AlbertForMultipleChoice,
							        AlbertForSequenceClassification,
							        AlbertForTokenClassification,
							        AlbertForQuestionAnswering,
							    )
							    if is_torch_available()
							    else ()
							)
							UpperCamelCase_   :							int       =(
							    {
							        '''feature-extraction''': AlbertModel,
							        '''fill-mask''': AlbertForMaskedLM,
							        '''question-answering''': AlbertForQuestionAnswering,
							        '''text-classification''': AlbertForSequenceClassification,
							        '''token-classification''': AlbertForTokenClassification,
							        '''zero-shot''': AlbertForSequenceClassification,
							    }
							    if is_torch_available()
							    else {}
							)
							UpperCamelCase_   :							Optional[Any]       =True


							def 			_A       (self      ,				lowerCAmelCase      ,				lowerCAmelCase      ,				lowerCAmelCase=False					):
									__lowercase=			super()._prepare_for_class(__UpperCamelCase      ,				__UpperCamelCase      ,				return_labels=__UpperCamelCase					)

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


							def 			_A       (self					):
									__lowercase=			AlbertModelTester(self					)
									__lowercase=			ConfigTester(self      ,				config_class=__UpperCamelCase      ,				hidden_size=3_7					)


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


							def 			_A       (self					):
									__lowercase=			self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_model(*__UpperCamelCase					)


							def 			_A       (self					):
									__lowercase=			self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_pretraining(*__UpperCamelCase					)


							def 			_A       (self					):
									__lowercase=			self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_masked_lm(*__UpperCamelCase					)


							def 			_A       (self					):
									__lowercase=			self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_multiple_choice(*__UpperCamelCase					)


							def 			_A       (self					):
									__lowercase=			self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_question_answering(*__UpperCamelCase					)


							def 			_A       (self					):
									__lowercase=			self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_for_sequence_classification(*__UpperCamelCase					)


							def 			_A       (self					):
									__lowercase=			self.model_tester.prepare_config_and_inputs()
									for type in ["absolute", "relative_key", "relative_key_query"]:
											__lowercase=			type
											self.model_tester.create_and_check_model(*__UpperCamelCase					)







							@slow
							def 			_A       (self					):
									for model_name in ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
											__lowercase=			AlbertModel.from_pretrained(__UpperCamelCase					)
											self.assertIsNotNone(__UpperCamelCase					)





@require_torch
class       A    (   unittest.TestCase ):


							@slow
							def 			_A       (self					):
									__lowercase=			AlbertModel.from_pretrained('albert-base-v2'					)
									__lowercase=			torch.tensor([[0, 3_4_5, 2_3_2, 3_2_8, 7_4_0, 1_4_0, 1_6_9_5, 6_9, 6_0_7_8, 1_5_8_8, 2]]					)
									__lowercase=			torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]					)
									with torch.no_grad():
											__lowercase=			model(__UpperCamelCase      ,				attention_mask=__UpperCamelCase					)[0]
									__lowercase=			torch.Size((1, 1_1, 7_6_8)					)
									self.assertEqual(output.shape      ,				__UpperCamelCase					)
									__lowercase=			torch.tensor(
									    [[[-0.65_13, 1.50_35, -0.27_66], [-0.65_15, 1.50_46, -0.27_80], [-0.65_12, 1.50_49, -0.27_84]]]					)

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













"""simple docstring"""
from ...configuration_utils import PretrainedConfig
from ...utils import logging


_snake_case     :		Optional[int]       						= logging.get_logger(__name__)

_snake_case     :		Optional[int]       						= {
    'google/vivit-b-16x2-kinetics400': (
        'https://huggingface.co/google/vivit-b-16x2-kinetics400/resolve/main/config.json'
    ),
    # See all Vivit models at https://huggingface.co/models?filter=vivit
}






class 					_UpperCAmelCase   (	lowercase_ ):
					UpperCamelCase      =							'''vivit'''


					def __init__(					self			:Optional[Any]     ,       __UpperCamelCase			:Dict=2_24     ,       __UpperCamelCase			:int=32     ,       __UpperCamelCase			:Union[str, Any]=[2, 16, 16]     ,       __UpperCamelCase			:Optional[Any]=3     ,       __UpperCamelCase			:Optional[Any]=7_68     ,       __UpperCamelCase			:Any=12     ,       __UpperCamelCase			:List[str]=12     ,       __UpperCamelCase			:List[str]=30_72     ,       __UpperCamelCase			:Any="gelu_fast"     ,       __UpperCamelCase			:List[Any]=0.0     ,       __UpperCamelCase			:str=0.0     ,       __UpperCamelCase			:Dict=0.02     ,       __UpperCamelCase			:Optional[Any]=1e-06     ,       __UpperCamelCase			:Dict=True     ,       **__UpperCamelCase			:Tuple     ,       ):
												A		=  hidden_size
												A		=  num_hidden_layers
												A		=  num_attention_heads
												A		=  intermediate_size
												A		=  hidden_act
												A		=  hidden_dropout_prob
												A		=  attention_probs_dropout_prob
												A		=  initializer_range
												A		=  layer_norm_eps

												A		=  image_size
												A		=  num_frames
												A		=  tubelet_size
												A		=  num_channels
												A		=  qkv_bias

												super().__init__(**__UpperCamelCase		)


