


'''simple docstring'''





import unittest

import numpy as np

from transformers import AlbertConfig, is_flax_available
from transformers.testing_utils import require_flax, slow

from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor, random_attention_mask


if is_flax_available():
					import jax.numpy as jnp

					from transformers.models.albert.modeling_flax_albert import (
					    FlaxAlbertForMaskedLM,
					    FlaxAlbertForMultipleChoice,
					    FlaxAlbertForPreTraining,
					    FlaxAlbertForQuestionAnswering,
					    FlaxAlbertForSequenceClassification,
					    FlaxAlbertForTokenClassification,
					    FlaxAlbertModel,
					)
class 						a__					(					unittest.TestCase   ):





			'''simple docstring'''

			def __init__(  self							:			Any			,    lowerCAmelCase_							:			int			,    lowerCAmelCase_							:			int=13			,    lowerCAmelCase_							:			Dict=7			,    lowerCAmelCase_							:			Any=True			,    lowerCAmelCase_							:			Optional[Any]=True			,    lowerCAmelCase_							:			List[str]=True			,    lowerCAmelCase_							:			Optional[int]=True			,    lowerCAmelCase_							:			Tuple=99			,    lowerCAmelCase_							:			List[Any]=32			,    lowerCAmelCase_							:			Optional[Any]=5			,    lowerCAmelCase_							:			List[str]=4			,    lowerCAmelCase_							:			str=37			,    lowerCAmelCase_							:			int="gelu"			,    lowerCAmelCase_							:			Tuple=0.1			,    lowerCAmelCase_							:			Any=0.1			,    lowerCAmelCase_							:			List[Any]=512			,    lowerCAmelCase_							:			Optional[int]=16			,    lowerCAmelCase_							:			Union[str, Any]=2			,    lowerCAmelCase_							:			Any=0.02			,    lowerCAmelCase_							:			str=4			,    )      ->		Optional[Any]:
						__A=	parent
						__A=	batch_size
						__A=	seq_length
						__A=	is_training
						__A=	use_attention_mask
						__A=	use_token_type_ids
						__A=	use_labels
						__A=	vocab_size
						__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=	max_position_embeddings
						__A=	type_vocab_size
						__A=	type_sequence_label_size
						__A=	initializer_range
						__A=	num_choices
			def 					lowerCAmelCase     (  self							:			int	)      ->		List[Any]:
						__A=	ids_tensor([self.batch_size, self.seq_length]			,    self.vocab_size	)

						__A=	None
						if self.use_attention_mask:
									__A=	random_attention_mask([self.batch_size, self.seq_length]	)

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

						__A=	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			,    is_decoder=lowerCAmelCase_			,    initializer_range=self.initializer_range			,    )

						return config, input_ids, token_type_ids, attention_mask

			def 					lowerCAmelCase     (  self							:			List[Any]	)      ->		Optional[int]:
						__A=	self.prepare_config_and_inputs()
						__A,	__A,	__A,	__A=	config_and_inputs
						__A=	{'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': attention_mask}
						return config, inputs_dict


@require_flax
class 						a__					(					a_      ,  unittest.TestCase   ):





			'''simple docstring'''

			A						:				List[str]					      =			(
			    (
			        FlaxAlbertModel,
			        FlaxAlbertForPreTraining,
			        FlaxAlbertForMaskedLM,
			        FlaxAlbertForMultipleChoice,
			        FlaxAlbertForQuestionAnswering,
			        FlaxAlbertForSequenceClassification,
			        FlaxAlbertForTokenClassification,
			        FlaxAlbertForQuestionAnswering,
			    )
			    if is_flax_available()
			    else ()
			)
			def 					lowerCAmelCase     (  self							:			Optional[int]	)      ->		List[str]:
						__A=	FlaxAlbertModelTester(self	)

			@slow
			def 					lowerCAmelCase     (  self							:			Dict	)      ->		Union[str, Any]:
						for model_class_name in self.all_model_classes:
									__A=	model_class_name.from_pretrained('albert-base-v2'	)
									__A=	model(np.ones((1, 1)	)	)
									self.assertIsNotNone(lowerCAmelCase_	)


@require_flax
class 						a__					(					unittest.TestCase   ):





			'''simple docstring'''

			@slow
			def 					lowerCAmelCase     (  self							:			Union[str, Any]	)      ->		Dict:
						__A=	FlaxAlbertModel.from_pretrained('albert-base-v2'	)
						__A=	np.array([[0, 345, 232, 328, 740, 140, 1_695, 69, 6_078, 1_588, 2]]	)
						__A=	np.array([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]	)
						__A=	model(lowerCAmelCase_			,    attention_mask=lowerCAmelCase_	)[0]
						__A=	(1, 11, 768)
						self.assertEqual(output.shape			,    lowerCAmelCase_	)
						__A=	np.array(
						    [[[-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(jnp.allclose(output[:, 1:4, 1:4]			,    lowerCAmelCase_			,    atol=1E-4	)	)







'''simple docstring'''





from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_sentencepiece_available,
    is_speech_available,
    is_torch_available,
)


UpperCAmelCase__  			=				{
    '''configuration_trocr''': ['''TROCR_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''TrOCRConfig'''],
    '''processing_trocr''': ['''TrOCRProcessor'''],
}


try:
					if not is_torch_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					UpperCAmelCase__  			=				[
					    '''TROCR_PRETRAINED_MODEL_ARCHIVE_LIST''',
					    '''TrOCRForCausalLM''',
					    '''TrOCRPreTrainedModel''',
					]


if TYPE_CHECKING:
					from .configuration_trocr import TROCR_PRETRAINED_CONFIG_ARCHIVE_MAP, TrOCRConfig
					from .processing_trocr import TrOCRProcessor

					try:
										if not is_torch_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_trocr import TROCR_PRETRAINED_MODEL_ARCHIVE_LIST, TrOCRForCausalLM, TrOCRPreTrainedModel

else:
					import sys

					UpperCAmelCase__  			=				_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)



