
"""simple docstring"""







import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin


if is_torch_available():
							import torch

if is_vision_available():
							from PIL import Image

							from transformers import ChineseCLIPImageProcessor




class 			A__	(     unittest.TestCase):

		def __init__(				self	,		_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE=7	,		_SCREAMING_SNAKE_CASE=3	,		_SCREAMING_SNAKE_CASE=18	,		_SCREAMING_SNAKE_CASE=30	,		_SCREAMING_SNAKE_CASE=4_00	,		_SCREAMING_SNAKE_CASE=True	,		_SCREAMING_SNAKE_CASE=None	,		_SCREAMING_SNAKE_CASE=True	,		_SCREAMING_SNAKE_CASE=None	,		_SCREAMING_SNAKE_CASE=True	,		_SCREAMING_SNAKE_CASE=[0.4814_5466, 0.457_8275, 0.4082_1073]	,		_SCREAMING_SNAKE_CASE=[0.2686_2954, 0.2613_0258, 0.2757_7711]	,		_SCREAMING_SNAKE_CASE=True	,		):
			__lowerCAmelCase      :						List[str]						      =				size if size is not None else {'height': 2_24, 'width': 2_24}
			__lowerCAmelCase      :						Optional[Any]						      =				crop_size if crop_size is not None else {'height': 18, 'width': 18}
			__lowerCAmelCase      :						Tuple						      =				parent
			__lowerCAmelCase      :						str						      =				batch_size
			__lowerCAmelCase      :						List[Any]						      =				num_channels
			__lowerCAmelCase      :						str						      =				image_size
			__lowerCAmelCase      :						Optional[int]						      =				min_resolution
			__lowerCAmelCase      :						Optional[Any]						      =				max_resolution
			__lowerCAmelCase      :						Any						      =				do_resize
			__lowerCAmelCase      :						Union[str, Any]						      =				size
			__lowerCAmelCase      :						Optional[int]						      =				do_center_crop
			__lowerCAmelCase      :						Union[str, Any]						      =				crop_size
			__lowerCAmelCase      :						Optional[Any]						      =				do_normalize
			__lowerCAmelCase      :						List[Any]						      =				image_mean
			__lowerCAmelCase      :						str						      =				image_std
			__lowerCAmelCase      :						Union[str, Any]						      =				do_convert_rgb

		def 							__lowerCamelCase							(				self			):
			return {
			    "do_resize": self.do_resize,
			    "size": self.size,
			    "do_center_crop": self.do_center_crop,
			    "crop_size": self.crop_size,
			    "do_normalize": self.do_normalize,
			    "image_mean": self.image_mean,
			    "image_std": self.image_std,
			    "do_convert_rgb": self.do_convert_rgb,
			}







		def 							__lowerCamelCase							(				self	,		_SCREAMING_SNAKE_CASE=False	,		_SCREAMING_SNAKE_CASE=False	,		_SCREAMING_SNAKE_CASE=False			):
			assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

			if equal_resolution:
				__lowerCAmelCase      :						int						      =				[]
				for i in range(self.batch_size			):
					image_inputs.append(
					    np.random.randint(
					        2_55	,		size=(self.num_channels, self.max_resolution, self.max_resolution)	,		dtype=np.uinta			)			)
			else:
				__lowerCAmelCase      :						List[str]						      =				[]
				for i in range(self.batch_size			):
					__lowerCAmelCase      ,       __lowerCAmelCase      :						int						      =				np.random.choice(np.arange(self.min_resolution	,		self.max_resolution			)	,		2			)
					image_inputs.append(np.random.randint(2_55	,		size=(self.num_channels, width, height)	,		dtype=np.uinta			)			)

			if not numpify and not torchify:
				# PIL expects the channel dimension as last dimension
				__lowerCAmelCase      :						List[Any]						      =				[Image.fromarray(np.moveaxis(_SCREAMING_SNAKE_CASE	,		0	,		-1			)			) for x in image_inputs]

			if torchify:
				__lowerCAmelCase      :						int						      =				[torch.from_numpy(_SCREAMING_SNAKE_CASE			) for x in image_inputs]

			return image_inputs




@require_torch
@require_vision
class 			A__	(     _lowerCamelCase	,					unittest.TestCase):
		A_						:	Any           =     ChineseCLIPImageProcessor if is_vision_available() else None

		def 							__lowerCamelCase							(				self			):
			__lowerCAmelCase      :						List[Any]						      =				ChineseCLIPImageProcessingTester(self	,		do_center_crop=_SCREAMING_SNAKE_CASE			)

		@property
		def 							__lowerCamelCase							(				self			):
			return self.image_processor_tester.prepare_image_processor_dict()

		def 							__lowerCamelCase							(				self			):
			__lowerCAmelCase      :						Union[str, Any]						      =				self.image_processing_class(**self.image_processor_dict			)
			self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE	,		'do_resize'			)			)
			self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE	,		'size'			)			)
			self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE	,		'do_center_crop'			)			)
			self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE	,		'center_crop'			)			)
			self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE	,		'do_normalize'			)			)
			self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE	,		'image_mean'			)			)
			self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE	,		'image_std'			)			)
			self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE	,		'do_convert_rgb'			)			)

		def 							__lowerCamelCase							(				self			):
			__lowerCAmelCase      :						Optional[Any]						      =				self.image_processing_class.from_dict(self.image_processor_dict			)
			self.assertEqual(image_processor.size	,		{'height': 2_24, 'width': 2_24}			)
			self.assertEqual(image_processor.crop_size	,		{'height': 18, 'width': 18}			)

			__lowerCAmelCase      :						List[str]						      =				self.image_processing_class.from_dict(self.image_processor_dict	,		size=42	,		crop_size=84			)
			self.assertEqual(image_processor.size	,		{'shortest_edge': 42}			)
			self.assertEqual(image_processor.crop_size	,		{'height': 84, 'width': 84}			)

		def 							__lowerCamelCase							(				self			):
			pass

		def 							__lowerCamelCase							(				self			):
			# Initialize image_processing
			__lowerCAmelCase      :						Dict						      =				self.image_processing_class(**self.image_processor_dict			)
			# create random PIL images
			__lowerCAmelCase      :						Union[str, Any]						      =				self.image_processor_tester.prepare_inputs(equal_resolution=_SCREAMING_SNAKE_CASE			)
			for image in image_inputs:
				self.assertIsInstance(_SCREAMING_SNAKE_CASE	,		Image.Image			)

			# Test not batched input
			__lowerCAmelCase      :						Optional[Any]						      =				image_processing(image_inputs[0]	,		return_tensors='pt'			).pixel_values
			self.assertEqual(
			    encoded_images.shape	,		(
			        1,
			        self.image_processor_tester.num_channels,
			        self.image_processor_tester.crop_size['height'],
			        self.image_processor_tester.crop_size['width'],
			    )	,		)

			# Test batched
			__lowerCAmelCase      :						Any						      =				image_processing(_SCREAMING_SNAKE_CASE	,		return_tensors='pt'			).pixel_values
			self.assertEqual(
			    encoded_images.shape	,		(
			        self.image_processor_tester.batch_size,
			        self.image_processor_tester.num_channels,
			        self.image_processor_tester.crop_size['height'],
			        self.image_processor_tester.crop_size['width'],
			    )	,		)

		def 							__lowerCamelCase							(				self			):
			# Initialize image_processing
			__lowerCAmelCase      :						int						      =				self.image_processing_class(**self.image_processor_dict			)
			# create random numpy tensors
			__lowerCAmelCase      :						Optional[Any]						      =				self.image_processor_tester.prepare_inputs(equal_resolution=_SCREAMING_SNAKE_CASE	,		numpify=_SCREAMING_SNAKE_CASE			)
			for image in image_inputs:
				self.assertIsInstance(_SCREAMING_SNAKE_CASE	,		np.ndarray			)

			# Test not batched input
			__lowerCAmelCase      :						Optional[Any]						      =				image_processing(image_inputs[0]	,		return_tensors='pt'			).pixel_values
			self.assertEqual(
			    encoded_images.shape	,		(
			        1,
			        self.image_processor_tester.num_channels,
			        self.image_processor_tester.crop_size['height'],
			        self.image_processor_tester.crop_size['width'],
			    )	,		)

			# Test batched
			__lowerCAmelCase      :						Optional[int]						      =				image_processing(_SCREAMING_SNAKE_CASE	,		return_tensors='pt'			).pixel_values
			self.assertEqual(
			    encoded_images.shape	,		(
			        self.image_processor_tester.batch_size,
			        self.image_processor_tester.num_channels,
			        self.image_processor_tester.crop_size['height'],
			        self.image_processor_tester.crop_size['width'],
			    )	,		)







		def 							__lowerCamelCase							(				self			):
			# Initialize image_processing
			__lowerCAmelCase      :						List[str]						      =				self.image_processing_class(**self.image_processor_dict			)
			# create random PyTorch tensors
			__lowerCAmelCase      :						List[str]						      =				self.image_processor_tester.prepare_inputs(equal_resolution=_SCREAMING_SNAKE_CASE	,		torchify=_SCREAMING_SNAKE_CASE			)
			for image in image_inputs:
				self.assertIsInstance(_SCREAMING_SNAKE_CASE	,		torch.Tensor			)

			# Test not batched input
			__lowerCAmelCase      :						List[str]						      =				image_processing(image_inputs[0]	,		return_tensors='pt'			).pixel_values
			self.assertEqual(
			    encoded_images.shape	,		(
			        1,
			        self.image_processor_tester.num_channels,
			        self.image_processor_tester.crop_size['height'],
			        self.image_processor_tester.crop_size['width'],
			    )	,		)

			# Test batched
			__lowerCAmelCase      :						Any						      =				image_processing(_SCREAMING_SNAKE_CASE	,		return_tensors='pt'			).pixel_values
			self.assertEqual(
			    encoded_images.shape	,		(
			        self.image_processor_tester.batch_size,
			        self.image_processor_tester.num_channels,
			        self.image_processor_tester.crop_size['height'],
			        self.image_processor_tester.crop_size['width'],
			    )	,		)




@require_torch
@require_vision
class 			A__	(     _lowerCamelCase	,					unittest.TestCase):
		A_						:	List[str]           =     ChineseCLIPImageProcessor if is_vision_available() else None

		def 							__lowerCamelCase							(				self			):
			__lowerCAmelCase      :						Optional[int]						      =				ChineseCLIPImageProcessingTester(self	,		num_channels=4	,		do_center_crop=_SCREAMING_SNAKE_CASE			)
			__lowerCAmelCase      :						Any						      =				3

		@property
		def 							__lowerCamelCase							(				self			):
			return self.image_processor_tester.prepare_image_processor_dict()

		def 							__lowerCamelCase							(				self			):
			__lowerCAmelCase      :						str						      =				self.image_processing_class(**self.image_processor_dict			)
			self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE	,		'do_resize'			)			)
			self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE	,		'size'			)			)
			self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE	,		'do_center_crop'			)			)
			self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE	,		'center_crop'			)			)
			self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE	,		'do_normalize'			)			)
			self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE	,		'image_mean'			)			)
			self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE	,		'image_std'			)			)
			self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE	,		'do_convert_rgb'			)			)

		def 							__lowerCamelCase							(				self			):
			pass







		def 							__lowerCamelCase							(				self			):
			# Initialize image_processing
			__lowerCAmelCase      :						str						      =				self.image_processing_class(**self.image_processor_dict			)
			# create random PIL images
			__lowerCAmelCase      :						Optional[int]						      =				self.image_processor_tester.prepare_inputs(equal_resolution=_SCREAMING_SNAKE_CASE			)
			for image in image_inputs:
				self.assertIsInstance(_SCREAMING_SNAKE_CASE	,		Image.Image			)

			# Test not batched input
			__lowerCAmelCase      :						int						      =				image_processing(image_inputs[0]	,		return_tensors='pt'			).pixel_values
			self.assertEqual(
			    encoded_images.shape	,		(
			        1,
			        self.expected_encoded_image_num_channels,
			        self.image_processor_tester.crop_size['height'],
			        self.image_processor_tester.crop_size['width'],
			    )	,		)

			# Test batched
			__lowerCAmelCase      :						str						      =				image_processing(_SCREAMING_SNAKE_CASE	,		return_tensors='pt'			).pixel_values
			self.assertEqual(
			    encoded_images.shape	,		(
			        self.image_processor_tester.batch_size,
			        self.expected_encoded_image_num_channels,
			        self.image_processor_tester.crop_size['height'],
			        self.image_processor_tester.crop_size['width'],
			    )	,		)

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

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

		def 							__lowerCamelCase							(				self			):
			__lowerCAmelCase      :						Dict						      =				ids_tensor([self.batch_size, self.seq_length]	,		self.vocab_size			)

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

			__lowerCAmelCase      :						Any						      =				None
			if self.use_token_type_ids:
				__lowerCAmelCase      :						List[str]						      =				ids_tensor([self.batch_size, self.seq_length]	,		self.type_vocab_size			)

			__lowerCAmelCase      :						Optional[int]						      =				None
			__lowerCAmelCase      :						Optional[Any]						      =				None
			__lowerCAmelCase      :						Any						      =				None
			if self.use_labels:
				__lowerCAmelCase      :						List[str]						      =				ids_tensor([self.batch_size]	,		self.type_sequence_label_size			)
				__lowerCAmelCase      :						Optional[int]						      =				ids_tensor([self.batch_size, self.seq_length]	,		self.num_labels			)
				__lowerCAmelCase      :						int						      =				ids_tensor([self.batch_size]	,		self.num_choices			)

			__lowerCAmelCase      :						Any						      =				self.get_config()

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

		def 							__lowerCamelCase							(				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 							__lowerCamelCase							(				self	,		_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE			):
			__lowerCAmelCase      :						List[str]						      =				AlbertModel(config=_SCREAMING_SNAKE_CASE			)
			model.to(_SCREAMING_SNAKE_CASE			)
			model.eval()
			__lowerCAmelCase      :						Dict						      =				model(_SCREAMING_SNAKE_CASE	,		attention_mask=_SCREAMING_SNAKE_CASE	,		token_type_ids=_SCREAMING_SNAKE_CASE			)
			__lowerCAmelCase      :						Optional[Any]						      =				model(_SCREAMING_SNAKE_CASE	,		token_type_ids=_SCREAMING_SNAKE_CASE			)
			__lowerCAmelCase      :						List[Any]						      =				model(_SCREAMING_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	,		_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE			):
			__lowerCAmelCase      :						str						      =				AlbertForPreTraining(config=_SCREAMING_SNAKE_CASE			)
			model.to(_SCREAMING_SNAKE_CASE			)
			model.eval()
			__lowerCAmelCase      :						Any						      =				model(
			    _SCREAMING_SNAKE_CASE	,		attention_mask=_SCREAMING_SNAKE_CASE	,		token_type_ids=_SCREAMING_SNAKE_CASE	,		labels=_SCREAMING_SNAKE_CASE	,		sentence_order_label=_SCREAMING_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	,		_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE			):
			__lowerCAmelCase      :						Optional[int]						      =				AlbertForMaskedLM(config=_SCREAMING_SNAKE_CASE			)
			model.to(_SCREAMING_SNAKE_CASE			)
			model.eval()
			__lowerCAmelCase      :						Any						      =				model(_SCREAMING_SNAKE_CASE	,		attention_mask=_SCREAMING_SNAKE_CASE	,		token_type_ids=_SCREAMING_SNAKE_CASE	,		labels=_SCREAMING_SNAKE_CASE			)
			self.parent.assertEqual(result.logits.shape	,		(self.batch_size, self.seq_length, self.vocab_size)			)

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

		def 							__lowerCamelCase							(				self	,		_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE			):
			__lowerCAmelCase      :						Optional[Any]						      =				self.num_labels
			__lowerCAmelCase      :						List[str]						      =				AlbertForTokenClassification(config=_SCREAMING_SNAKE_CASE			)
			model.to(_SCREAMING_SNAKE_CASE			)
			model.eval()
			__lowerCAmelCase      :						Dict						      =				model(_SCREAMING_SNAKE_CASE	,		attention_mask=_SCREAMING_SNAKE_CASE	,		token_type_ids=_SCREAMING_SNAKE_CASE	,		labels=_SCREAMING_SNAKE_CASE			)
			self.parent.assertEqual(result.logits.shape	,		(self.batch_size, self.seq_length, self.num_labels)			)

		def 							__lowerCamelCase							(				self	,		_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE			):
			__lowerCAmelCase      :						str						      =				self.num_choices
			__lowerCAmelCase      :						Dict						      =				AlbertForMultipleChoice(config=_SCREAMING_SNAKE_CASE			)
			model.to(_SCREAMING_SNAKE_CASE			)
			model.eval()
			__lowerCAmelCase      :						Union[str, Any]						      =				input_ids.unsqueeze(1			).expand(-1	,		self.num_choices	,		-1			).contiguous()
			__lowerCAmelCase      :						Dict						      =				token_type_ids.unsqueeze(1			).expand(-1	,		self.num_choices	,		-1			).contiguous()
			__lowerCAmelCase      :						List[str]						      =				input_mask.unsqueeze(1			).expand(-1	,		self.num_choices	,		-1			).contiguous()
			__lowerCAmelCase      :						Dict						      =				model(
			    _SCREAMING_SNAKE_CASE	,		attention_mask=_SCREAMING_SNAKE_CASE	,		token_type_ids=_SCREAMING_SNAKE_CASE	,		labels=_SCREAMING_SNAKE_CASE	,		)
			self.parent.assertEqual(result.logits.shape	,		(self.batch_size, self.num_choices)			)







		def 							__lowerCamelCase							(				self			):
			__lowerCAmelCase      :						List[Any]						      =				self.prepare_config_and_inputs()
			(
			    (
			    __lowerCAmelCase
			)      ,       (
			    __lowerCAmelCase
			)      ,       (
			    __lowerCAmelCase
			)      ,       (
			    __lowerCAmelCase
			)      ,       (
			    __lowerCAmelCase
			)      ,       (
			    __lowerCAmelCase
			)      ,       (
			    __lowerCAmelCase
			)      ,       
			)      :						int						      =				config_and_inputs
			__lowerCAmelCase      :						Tuple						      =				{'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
			return config, inputs_dict




@require_torch
class 			A__	(     _lowerCamelCase	,					_lowerCamelCase	,					unittest.TestCase):
		A_						:	List[str]           =     (
		    (
		        AlbertModel,
		        AlbertForPreTraining,
		        AlbertForMaskedLM,
		        AlbertForMultipleChoice,
		        AlbertForSequenceClassification,
		        AlbertForTokenClassification,
		        AlbertForQuestionAnswering,
		    )
		    if is_torch_available()
		    else ()
		)
		A_						:	str           =     (
		    {
		        'feature-extraction': AlbertModel,
		        'fill-mask': AlbertForMaskedLM,
		        'question-answering': AlbertForQuestionAnswering,
		        'text-classification': AlbertForSequenceClassification,
		        'token-classification': AlbertForTokenClassification,
		        'zero-shot': AlbertForSequenceClassification,
		    }
		    if is_torch_available()
		    else {}
		)
		A_						:	Union[str, Any]           =     True

		def 							__lowerCamelCase							(				self	,		_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE=False			):
			__lowerCAmelCase      :						Optional[Any]						      =				super()._prepare_for_class(_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE	,		return_labels=_SCREAMING_SNAKE_CASE			)

			if return_labels:
				if model_class in get_values(_SCREAMING_SNAKE_CASE			):
					__lowerCAmelCase      :						List[Any]						      =				torch.zeros(
					    (self.model_tester.batch_size, self.model_tester.seq_length)	,		dtype=torch.long	,		device=_SCREAMING_SNAKE_CASE			)
					__lowerCAmelCase      :						List[Any]						      =				torch.zeros(
					    self.model_tester.batch_size	,		dtype=torch.long	,		device=_SCREAMING_SNAKE_CASE			)
			return inputs_dict

		def 							__lowerCamelCase							(				self			):
			__lowerCAmelCase      :						List[str]						      =				AlbertModelTester(self			)
			__lowerCAmelCase      :						List[str]						      =				ConfigTester(self	,		config_class=_SCREAMING_SNAKE_CASE	,		hidden_size=37			)

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

		def 							__lowerCamelCase							(				self			):
			__lowerCAmelCase      :						Any						      =				self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_model(*_SCREAMING_SNAKE_CASE			)

		def 							__lowerCamelCase							(				self			):
			__lowerCAmelCase      :						Tuple						      =				self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_for_pretraining(*_SCREAMING_SNAKE_CASE			)

		def 							__lowerCamelCase							(				self			):
			__lowerCAmelCase      :						Tuple						      =				self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_for_masked_lm(*_SCREAMING_SNAKE_CASE			)

		def 							__lowerCamelCase							(				self			):
			__lowerCAmelCase      :						Optional[Any]						      =				self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_for_multiple_choice(*_SCREAMING_SNAKE_CASE			)

		def 							__lowerCamelCase							(				self			):
			__lowerCAmelCase      :						List[Any]						      =				self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_for_question_answering(*_SCREAMING_SNAKE_CASE			)

		def 							__lowerCamelCase							(				self			):
			__lowerCAmelCase      :						Dict						      =				self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_for_sequence_classification(*_SCREAMING_SNAKE_CASE			)

		def 							__lowerCamelCase							(				self			):
			__lowerCAmelCase      :						Optional[Any]						      =				self.model_tester.prepare_config_and_inputs()
			for type in ["absolute", "relative_key", "relative_key_query"]:
				__lowerCAmelCase      :						Optional[Any]						      =				type
				self.model_tester.create_and_check_model(*_SCREAMING_SNAKE_CASE			)







		@slow
		def 							__lowerCamelCase							(				self			):
			for model_name in ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
				__lowerCAmelCase      :						Optional[int]						      =				AlbertModel.from_pretrained(_SCREAMING_SNAKE_CASE			)
				self.assertIsNotNone(_SCREAMING_SNAKE_CASE			)




@require_torch
class 			A__	(     unittest.TestCase):

		@slow
		def 							__lowerCamelCase							(				self			):
			__lowerCAmelCase      :						str						      =				AlbertModel.from_pretrained('albert-base-v2'			)
			__lowerCAmelCase      :						List[str]						      =				torch.tensor([[0, 3_45, 2_32, 3_28, 7_40, 1_40, 16_95, 69, 60_78, 15_88, 2]]			)
			__lowerCAmelCase      :						Optional[Any]						      =				torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]			)
			with torch.no_grad():
				__lowerCAmelCase      :						Dict						      =				model(_SCREAMING_SNAKE_CASE	,		attention_mask=_SCREAMING_SNAKE_CASE			)[0]
			__lowerCAmelCase      :						Dict						      =				torch.Size((1, 11, 7_68)			)
			self.assertEqual(output.shape	,		_SCREAMING_SNAKE_CASE			)
			__lowerCAmelCase      :						List[Any]						      =				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]	,		_SCREAMING_SNAKE_CASE	,		atol=1E-4			)			)