

"""simple docstring"""




import unittest

import torch

from diffusers import UNetaDModel
from diffusers.utils import floats_tensor, slow, torch_device

from .test_modeling_common import ModelTesterMixin, UNetTesterMixin





class      __UpperCamelCase					(  _A	,						_A	,						unittest.TestCase		):
		SCREAMING_SNAKE_CASE														=       UNetaDModel
		SCREAMING_SNAKE_CASE														=       "sample"


		@property
		def    SCREAMING_SNAKE_CASE__  (self					:						Tuple):
							A     =   4
							A     =   1_4
							A     =   1_6

							A     =   floats_tensor((batch_size, num_features, seq_len)).to(__SCREAMING_SNAKE_CASE)
							A     =   torch.tensor([1_0] * batch_size).to(__SCREAMING_SNAKE_CASE)

							return {"sample": noise, "timestep": time_step}


		@property
		def    SCREAMING_SNAKE_CASE__  (self					:						Optional[int]):
							return (4, 1_4, 1_6)


		@property
		def    SCREAMING_SNAKE_CASE__  (self					:						int):
							return (4, 1_4, 1_6)


		def    SCREAMING_SNAKE_CASE__  (self					:						List[Any]):
							pass


		def    SCREAMING_SNAKE_CASE__  (self					:						str):
							pass


		@unittest.skipIf(torch_device == "mps"	,	"mish op not supported in MPS")
		def    SCREAMING_SNAKE_CASE__  (self					:						Tuple):
							super().test_determinism()


		@unittest.skipIf(torch_device == "mps"	,	"mish op not supported in MPS")
		def    SCREAMING_SNAKE_CASE__  (self					:						Any):
							super().test_outputs_equivalence()


		@unittest.skipIf(torch_device == "mps"	,	"mish op not supported in MPS")
		def    SCREAMING_SNAKE_CASE__  (self					:						Any):
							super().test_from_save_pretrained()


		@unittest.skipIf(torch_device == "mps"	,	"mish op not supported in MPS")
		def    SCREAMING_SNAKE_CASE__  (self					:						Any):
							super().test_from_save_pretrained_variant()


		@unittest.skipIf(torch_device == "mps"	,	"mish op not supported in MPS")
		def    SCREAMING_SNAKE_CASE__  (self					:						Any):
							super().test_model_from_pretrained()


		@unittest.skipIf(torch_device == "mps"	,	"mish op not supported in MPS")
		def    SCREAMING_SNAKE_CASE__  (self					:						List[Any]):
							super().test_output()


		def    SCREAMING_SNAKE_CASE__  (self					:						Union[str, Any]):
							A     =   {
							    "block_out_channels": (3_2, 6_4, 1_2_8, 2_5_6),
							    "in_channels": 1_4,
							    "out_channels": 1_4,
							    "time_embedding_type": "positional",
							    "use_timestep_embedding": True,
							    "flip_sin_to_cos": False,
							    "freq_shift": 1.0,
							    "out_block_type": "OutConv1DBlock",
							    "mid_block_type": "MidResTemporalBlock1D",
							    "down_block_types": ("DownResnetBlock1D", "DownResnetBlock1D", "DownResnetBlock1D", "DownResnetBlock1D"),
							    "up_block_types": ("UpResnetBlock1D", "UpResnetBlock1D", "UpResnetBlock1D"),
							    "act_fn": "mish",
							}
							A     =   self.dummy_input
							return init_dict, inputs_dict


		@unittest.skipIf(torch_device == "mps"	,	"mish op not supported in MPS")
		def    SCREAMING_SNAKE_CASE__  (self					:						Optional[Any]):
							A     ,       A     =   UNetaDModel.from_pretrained(
							    "bglick13/hopper-medium-v2-value-function-hor32"	,	output_loading_info=__SCREAMING_SNAKE_CASE	,	subfolder="unet")
							self.assertIsNotNone(__SCREAMING_SNAKE_CASE)
							self.assertEqual(len(loading_info["missing_keys"])	,	0)

							model.to(__SCREAMING_SNAKE_CASE)
							A     =   model(**self.dummy_input)

							assert image is not None, "Make sure output is not None"


		@unittest.skipIf(torch_device == "mps"	,	"mish op not supported in MPS")
		def    SCREAMING_SNAKE_CASE__  (self					:						Optional[Any]):
							A     =   UNetaDModel.from_pretrained("bglick13/hopper-medium-v2-value-function-hor32"	,	subfolder="unet")
							torch.manual_seed(0)
							if torch.cuda.is_available():
												torch.cuda.manual_seed_all(0)

							A     =   model.config.in_channels
							A     =   1_6
							A     =   torch.randn((1, seq_len, num_features)).permute(
							    0	,	2	,	1)  # match original, we can update values and remove
							A     =   torch.full((num_features,)	,	0)

							with torch.no_grad():
												A     =   model(__SCREAMING_SNAKE_CASE	,	__SCREAMING_SNAKE_CASE).sample.permute(0	,	2	,	1)

							A     =   output[0, -3:, -3:].flatten()
							# fmt: off
							A     =   torch.tensor([-2.1_3_7_1_7_2, 1.1_4_2_6_0_1_6, 0.3_6_8_8_6_8_7, -0.7_6_6_9_2_2, 0.7_3_0_3_1_4_6, 0.1_1_0_3_8_8_6_4, -0.4_7_6_0_6_3_3, 0.1_3_2_7_0_1_7_2, 0.0_2_5_9_1_3_4_8])
							# fmt: on
							self.assertTrue(torch.allclose(__SCREAMING_SNAKE_CASE	,	__SCREAMING_SNAKE_CASE	,	rtol=1E-3))


		def    SCREAMING_SNAKE_CASE__  (self					:						Union[str, Any]):
							# Not implemented yet for this UNet
							pass


		@slow
		def    SCREAMING_SNAKE_CASE__  (self					:						Dict):
							A     =   "harmonai/maestro-150k"
							A     =   UNetaDModel.from_pretrained(__SCREAMING_SNAKE_CASE	,	subfolder="unet")
							model.to(__SCREAMING_SNAKE_CASE)

							A     =   6_5_5_3_6
							A     =   torch.sin(torch.arange(__SCREAMING_SNAKE_CASE)[None, None, :].repeat(1	,	2	,	1)).to(__SCREAMING_SNAKE_CASE)
							A     =   torch.tensor([1]).to(__SCREAMING_SNAKE_CASE)

							with torch.no_grad():
												A     =   model(__SCREAMING_SNAKE_CASE	,	__SCREAMING_SNAKE_CASE).sample

							A     =   output.abs().sum()
							A     =   output.abs().max()

							assert (output_sum - 2_2_4.0_8_9_6).abs() < 0.5
							assert (output_max - 0.0_6_0_7).abs() < 4E-4





class      __UpperCamelCase					(  _A	,						_A	,						unittest.TestCase		):
		SCREAMING_SNAKE_CASE														=       UNetaDModel
		SCREAMING_SNAKE_CASE														=       "sample"


		@property
		def    SCREAMING_SNAKE_CASE__  (self					:						Any):
							A     =   4
							A     =   1_4
							A     =   1_6

							A     =   floats_tensor((batch_size, num_features, seq_len)).to(__SCREAMING_SNAKE_CASE)
							A     =   torch.tensor([1_0] * batch_size).to(__SCREAMING_SNAKE_CASE)

							return {"sample": noise, "timestep": time_step}


		@property
		def    SCREAMING_SNAKE_CASE__  (self					:						int):
							return (4, 1_4, 1_6)


		@property
		def    SCREAMING_SNAKE_CASE__  (self					:						Tuple):
							return (4, 1_4, 1)


		@unittest.skipIf(torch_device == "mps"	,	"mish op not supported in MPS")
		def    SCREAMING_SNAKE_CASE__  (self					:						Optional[Any]):
							super().test_determinism()


		@unittest.skipIf(torch_device == "mps"	,	"mish op not supported in MPS")
		def    SCREAMING_SNAKE_CASE__  (self					:						str):
							super().test_outputs_equivalence()


		@unittest.skipIf(torch_device == "mps"	,	"mish op not supported in MPS")
		def    SCREAMING_SNAKE_CASE__  (self					:						Dict):
							super().test_from_save_pretrained()


		@unittest.skipIf(torch_device == "mps"	,	"mish op not supported in MPS")
		def    SCREAMING_SNAKE_CASE__  (self					:						Dict):
							super().test_from_save_pretrained_variant()


		@unittest.skipIf(torch_device == "mps"	,	"mish op not supported in MPS")
		def    SCREAMING_SNAKE_CASE__  (self					:						List[Any]):
							super().test_model_from_pretrained()


		@unittest.skipIf(torch_device == "mps"	,	"mish op not supported in MPS")
		def    SCREAMING_SNAKE_CASE__  (self					:						Any):
							# UNetRL is a value-function is different output shape
							A     ,       A     =   self.prepare_init_args_and_inputs_for_common()
							A     =   self.model_class(**__SCREAMING_SNAKE_CASE)
							model.to(__SCREAMING_SNAKE_CASE)
							model.eval()

							with torch.no_grad():
												A     =   model(**__SCREAMING_SNAKE_CASE)

												if isinstance(__SCREAMING_SNAKE_CASE	,	__SCREAMING_SNAKE_CASE):
																	A     =   output.sample

							self.assertIsNotNone(__SCREAMING_SNAKE_CASE)
							A     =   torch.Size((inputs_dict["sample"].shape[0], 1))
							self.assertEqual(output.shape	,	__SCREAMING_SNAKE_CASE	,	"Input and output shapes do not match")


		def    SCREAMING_SNAKE_CASE__  (self					:						Union[str, Any]):
							pass


		def    SCREAMING_SNAKE_CASE__  (self					:						Optional[int]):
							pass


		def    SCREAMING_SNAKE_CASE__  (self					:						Any):
							A     =   {
							    "in_channels": 1_4,
							    "out_channels": 1_4,
							    "down_block_types": ["DownResnetBlock1D", "DownResnetBlock1D", "DownResnetBlock1D", "DownResnetBlock1D"],
							    "up_block_types": [],
							    "out_block_type": "ValueFunction",
							    "mid_block_type": "ValueFunctionMidBlock1D",
							    "block_out_channels": [3_2, 6_4, 1_2_8, 2_5_6],
							    "layers_per_block": 1,
							    "downsample_each_block": True,
							    "use_timestep_embedding": True,
							    "freq_shift": 1.0,
							    "flip_sin_to_cos": False,
							    "time_embedding_type": "positional",
							    "act_fn": "mish",
							}
							A     =   self.dummy_input
							return init_dict, inputs_dict


		@unittest.skipIf(torch_device == "mps"	,	"mish op not supported in MPS")
		def    SCREAMING_SNAKE_CASE__  (self					:						int):
							A     ,       A     =   UNetaDModel.from_pretrained(
							    "bglick13/hopper-medium-v2-value-function-hor32"	,	output_loading_info=__SCREAMING_SNAKE_CASE	,	subfolder="value_function")
							self.assertIsNotNone(__SCREAMING_SNAKE_CASE)
							self.assertEqual(len(vf_loading_info["missing_keys"])	,	0)

							value_function.to(__SCREAMING_SNAKE_CASE)
							A     =   value_function(**self.dummy_input)

							assert image is not None, "Make sure output is not None"


		@unittest.skipIf(torch_device == "mps"	,	"mish op not supported in MPS")
		def    SCREAMING_SNAKE_CASE__  (self					:						Union[str, Any]):
							A     ,       A     =   UNetaDModel.from_pretrained(
							    "bglick13/hopper-medium-v2-value-function-hor32"	,	output_loading_info=__SCREAMING_SNAKE_CASE	,	subfolder="value_function")
							torch.manual_seed(0)
							if torch.cuda.is_available():
												torch.cuda.manual_seed_all(0)

							A     =   value_function.config.in_channels
							A     =   1_4
							A     =   torch.randn((1, seq_len, num_features)).permute(
							    0	,	2	,	1)  # match original, we can update values and remove
							A     =   torch.full((num_features,)	,	0)

							with torch.no_grad():
												A     =   value_function(__SCREAMING_SNAKE_CASE	,	__SCREAMING_SNAKE_CASE).sample

							# fmt: off
							A     =   torch.tensor([1_6_5.2_5] * seq_len)
							# fmt: on
							self.assertTrue(torch.allclose(__SCREAMING_SNAKE_CASE	,	__SCREAMING_SNAKE_CASE	,	rtol=1E-3))


		def    SCREAMING_SNAKE_CASE__  (self					:						Optional[Any]):
							# Not implemented yet for this UNet
							pass










'''simple docstring'''







from __future__ import annotations

import unittest

from transformers import AlbertConfig, is_tf_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
		import tensorflow as tf

		from transformers import TF_MODEL_FOR_PRETRAINING_MAPPING
		from transformers.models.albert.modeling_tf_albert import (
		    TF_ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
		    TFAlbertForMaskedLM,
		    TFAlbertForMultipleChoice,
		    TFAlbertForPreTraining,
		    TFAlbertForQuestionAnswering,
		    TFAlbertForSequenceClassification,
		    TFAlbertForTokenClassification,
		    TFAlbertModel,
		)

class      lowerCamelCase__     :






	'''simple docstring'''

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




								'''simple docstring'''





								lowerCAmelCase__  =   parent
								lowerCAmelCase__  =   13
								lowerCAmelCase__  =   7
								lowerCAmelCase__  =   True
								lowerCAmelCase__  =   True
								lowerCAmelCase__  =   True
								lowerCAmelCase__  =   True
								lowerCAmelCase__  =   99
								lowerCAmelCase__  =   16
								lowerCAmelCase__  =   32
								lowerCAmelCase__  =   2
								lowerCAmelCase__  =   4
								lowerCAmelCase__  =   37
								lowerCAmelCase__  =   """gelu"""
								lowerCAmelCase__  =   0.1
								lowerCAmelCase__  =   0.1
								lowerCAmelCase__  =   512
								lowerCAmelCase__  =   16
								lowerCAmelCase__  =   2
								lowerCAmelCase__  =   0.0_2
								lowerCAmelCase__  =   3
								lowerCAmelCase__  =   4
								lowerCAmelCase__  =   None




	def      lowercase__							(  self		:  Optional[int]					)     ->			int:




								'''simple docstring'''





								lowerCAmelCase__  =   ids_tensor([self.batch_size, self.seq_length]   ,		self.vocab_size					)

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

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

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

								lowerCAmelCase__  =   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      lowercase__							(  self		:  Optional[Any]   ,		__A		:  Optional[Any]   ,		__A		:  Tuple   ,		__A		:  List[Any]   ,		__A		:  Tuple   ,		__A		:  Dict   ,		__A		:  Optional[int]   ,		__A		:  List[Any]					)     ->			Optional[int]:




								'''simple docstring'''





								lowerCAmelCase__  =   TFAlbertModel(config=__A					)
								# inputs = {'input_ids': input_ids,
								#           'attention_mask': input_mask,
								#           'token_type_ids': token_type_ids}
								# sequence_output, pooled_output = model(**inputs)
								lowerCAmelCase__  =   {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
								lowerCAmelCase__  =   model(__A					)

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

								lowerCAmelCase__  =   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      lowercase__							(  self		:  List[str]   ,		__A		:  Optional[int]   ,		__A		:  Any   ,		__A		:  List[str]   ,		__A		:  Optional[int]   ,		__A		:  List[Any]   ,		__A		:  Optional[int]   ,		__A		:  Union[str, Any]					)     ->			Any:




								'''simple docstring'''





								lowerCAmelCase__  =   self.num_labels
								lowerCAmelCase__  =   TFAlbertForPreTraining(config=__A					)
								lowerCAmelCase__  =   {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
								lowerCAmelCase__  =   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      lowercase__							(  self		:  str   ,		__A		:  Dict   ,		__A		:  Any   ,		__A		:  List[Any]   ,		__A		:  Tuple   ,		__A		:  Union[str, Any]   ,		__A		:  int   ,		__A		:  str					)     ->			str:




								'''simple docstring'''





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




	def      lowercase__							(  self		:  Dict   ,		__A		:  List[Any]   ,		__A		:  Union[str, Any]   ,		__A		:  Union[str, Any]   ,		__A		:  Optional[Any]   ,		__A		:  Optional[Any]   ,		__A		:  str   ,		__A		:  List[str]					)     ->			List[Any]:




								'''simple docstring'''





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




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




								'''simple docstring'''





								lowerCAmelCase__  =   TFAlbertForQuestionAnswering(config=__A					)
								lowerCAmelCase__  =   {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
								lowerCAmelCase__  =   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      lowercase__							(  self		:  List[Any]   ,		__A		:  Union[str, Any]   ,		__A		:  List[Any]   ,		__A		:  Tuple   ,		__A		:  Dict   ,		__A		:  Tuple   ,		__A		:  List[str]   ,		__A		:  Dict					)     ->			List[Any]:




								'''simple docstring'''





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




	def      lowercase__							(  self		:  int   ,		__A		:  Tuple   ,		__A		:  Optional[Any]   ,		__A		:  Any   ,		__A		:  Union[str, Any]   ,		__A		:  Tuple   ,		__A		:  str   ,		__A		:  Optional[Any]					)     ->			str:




								'''simple docstring'''





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




	def      lowercase__							(  self		:  List[Any]					)     ->			Any:




								'''simple docstring'''





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





@require_tf
class      lowerCamelCase__     (     _A,     _A,     unittest.TestCase				):






	'''simple docstring'''

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




	def      lowercase__							(  self		:  Any   ,		__A		:  List[str]   ,		__A		:  int   ,		__A		:  Union[str, Any]=False					)     ->			Optional[int]:




								'''simple docstring'''





								lowerCAmelCase__  =   super()._prepare_for_class(__A   ,		__A   ,		return_labels=__A					)

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

								return inputs_dict




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




								'''simple docstring'''





								lowerCAmelCase__  =   TFAlbertModelTester(self					)
								lowerCAmelCase__  =   ConfigTester(self   ,		config_class=__A   ,		hidden_size=37					)




	def      lowercase__							(  self		:  List[str]					)     ->			str:




								'''simple docstring'''





								self.config_tester.run_common_tests()




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




								'''simple docstring'''





								lowerCAmelCase__  =   self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_albert_model(*__A					)




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




								'''simple docstring'''





								lowerCAmelCase__  =   self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_albert_for_pretraining(*__A					)




	def      lowercase__							(  self		:  List[Any]					)     ->			Dict:




								'''simple docstring'''





								lowerCAmelCase__  =   self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_albert_for_masked_lm(*__A					)




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




								'''simple docstring'''





								lowerCAmelCase__  =   self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_albert_for_multiple_choice(*__A					)




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




								'''simple docstring'''





								lowerCAmelCase__  =   self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_albert_for_sequence_classification(*__A					)




	def      lowercase__							(  self		:  Any					)     ->			Any:




								'''simple docstring'''





								lowerCAmelCase__  =   self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_albert_for_question_answering(*__A					)




	@slow
	def      lowercase__							(  self		:  Tuple					)     ->			Dict:




								'''simple docstring'''





								for model_name in TF_ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
															lowerCAmelCase__  =   TFAlbertModel.from_pretrained(__A					)
															self.assertIsNotNone(__A					)





@require_tf
class      lowerCamelCase__     (     unittest.TestCase				):






	'''simple docstring'''

	@slow
	def      lowercase__							(  self		:  Optional[int]					)     ->			str:




								'''simple docstring'''





								lowerCAmelCase__  =   TFAlbertForPreTraining.from_pretrained("""albert-base-v2"""					)
								lowerCAmelCase__  =   tf.constant([[0, 1, 2, 3, 4, 5]]					)
								lowerCAmelCase__  =   model(__A					)[0]

								lowerCAmelCase__  =   [1, 6, 3_0000]
								self.assertEqual(output.shape   ,		__A					)

								lowerCAmelCase__  =   tf.constant(
								    [
								        [
								            [4.5_9_5_6_6_8, 0.7_4_4_6_2_7_5_4, -1.8_1_8_1_4_7],
								            [4.5_9_5_4_3_4_7, 0.7_4_5_4_1_8_4, -1.8_1_8_8_2_5_8],
								            [4.5_9_5_4_9_0_5, 0.7_4_4_8_2_3_5, -1.8_1_8_2_3_1_6],
								        ]
								    ]					)
								tf.debugging.assert_near(output[:, :3, :3]   ,		__A   ,		atol=1E-4					)





