



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 					__lowerCAmelCase (     unittest.TestCase       ):




				def __init__(							self						,				_snake_case						,				_snake_case=13						,				_snake_case=7						,				_snake_case=True						,				_snake_case=True						,				_snake_case=True						,				_snake_case=True						,				_snake_case=99						,				_snake_case=32						,				_snake_case=5						,				_snake_case=4						,				_snake_case=37						,				_snake_case="gelu"						,				_snake_case=0.1						,				_snake_case=0.1						,				_snake_case=512						,				_snake_case=16						,				_snake_case=2						,				_snake_case=0.02						,				_snake_case=4						,				):



									"""simple docstring"""





									_lowerCAmelCase						=    parent
									_lowerCAmelCase						=    batch_size
									_lowerCAmelCase						=    seq_length
									_lowerCAmelCase						=    is_training
									_lowerCAmelCase						=    use_attention_mask
									_lowerCAmelCase						=    use_token_type_ids
									_lowerCAmelCase						=    use_labels
									_lowerCAmelCase						=    vocab_size
									_lowerCAmelCase						=    hidden_size
									_lowerCAmelCase						=    num_hidden_layers
									_lowerCAmelCase						=    num_attention_heads
									_lowerCAmelCase						=    intermediate_size
									_lowerCAmelCase						=    hidden_act
									_lowerCAmelCase						=    hidden_dropout_prob
									_lowerCAmelCase						=    attention_probs_dropout_prob
									_lowerCAmelCase						=    max_position_embeddings
									_lowerCAmelCase						=    type_vocab_size
									_lowerCAmelCase						=    type_sequence_label_size
									_lowerCAmelCase						=    initializer_range
									_lowerCAmelCase						=    num_choices




				def 							snake_case   (							self		):



									"""simple docstring"""





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

									_lowerCAmelCase						=    None
									if self.use_attention_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						=    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=SCREAMING_SNAKE_CASE_						,				initializer_range=self.initializer_range						,				)

									return config, input_ids, token_type_ids, attention_mask




				def 							snake_case   (							self		):



									"""simple docstring"""





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





@require_flax
class 					__lowerCAmelCase (     lowerCamelCase__       ,						unittest.TestCase       ):
				__lowerCamelCase =				(
				    (
				        FlaxAlbertModel,
				        FlaxAlbertForPreTraining,
				        FlaxAlbertForMaskedLM,
				        FlaxAlbertForMultipleChoice,
				        FlaxAlbertForQuestionAnswering,
				        FlaxAlbertForSequenceClassification,
				        FlaxAlbertForTokenClassification,
				        FlaxAlbertForQuestionAnswering,
				    )
				    if is_flax_available()
				    else ()
				)




				def 							snake_case   (							self		):



									"""simple docstring"""





									_lowerCAmelCase						=    FlaxAlbertModelTester(self		)




				@slow
				def 							snake_case   (							self		):



									"""simple docstring"""





									for model_class_name in self.all_model_classes:
														_lowerCAmelCase						=    model_class_name.from_pretrained("""albert-base-v2"""		)
														_lowerCAmelCase						=    model(np.ones((1, 1)		)		)
														self.assertIsNotNone(SCREAMING_SNAKE_CASE_		)





@require_flax
class 					__lowerCAmelCase (     unittest.TestCase       ):




				@slow
				def 							snake_case   (							self		):



									"""simple docstring"""





									_lowerCAmelCase						=    FlaxAlbertModel.from_pretrained("""albert-base-v2"""		)
									_lowerCAmelCase						=    np.array([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]]		)
									_lowerCAmelCase						=    np.array([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]		)
									_lowerCAmelCase						=    model(SCREAMING_SNAKE_CASE_						,				attention_mask=SCREAMING_SNAKE_CASE_		)[0]
									_lowerCAmelCase						=    (1, 11, 768)
									self.assertEqual(output.shape						,				SCREAMING_SNAKE_CASE_		)
									_lowerCAmelCase						=    np.array(
									    [[[-0.6513, 1.5035, -0.2766], [-0.6515, 1.5046, -0.2780], [-0.6512, 1.5049, -0.2784]]]		)

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





from typing import TYPE_CHECKING

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


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


try:
						if not is_torch_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						__a  			=					[
						    '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

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




