



import unittest

import numpy as np

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

from ...test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask


if is_flax_available():
						from transformers.models.bert.modeling_flax_bert import (
						    FlaxBertForMaskedLM,
						    FlaxBertForMultipleChoice,
						    FlaxBertForNextSentencePrediction,
						    FlaxBertForPreTraining,
						    FlaxBertForQuestionAnswering,
						    FlaxBertForSequenceClassification,
						    FlaxBertForTokenClassification,
						    FlaxBertModel,
						)


class 				_a						(       unittest.TestCase			):





							'''simple docstring'''

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







											"""simple docstring"""



											a__	:							int      						= parent
											a__	:							List[Any]      						= batch_size
											a__	:							Union[str, Any]      						= seq_length
											a__	:							List[Any]      						= is_training
											a__	:							str      						= use_attention_mask
											a__	:							List[str]      						= use_token_type_ids
											a__	:							Optional[Any]      						= use_labels
											a__	:							List[str]      						= vocab_size
											a__	:							List[Any]      						= hidden_size
											a__	:							Any      						= num_hidden_layers
											a__	:							Optional[int]      						= num_attention_heads
											a__	:							Dict      						= intermediate_size
											a__	:							List[Any]      						= hidden_act
											a__	:							Union[str, Any]      						= hidden_dropout_prob
											a__	:							List[str]      						= attention_probs_dropout_prob
											a__	:							str      						= max_position_embeddings
											a__	:							Union[str, Any]      						= type_vocab_size
											a__	:							Union[str, Any]      						= type_sequence_label_size
											a__	:							Dict      						= initializer_range
											a__	:							List[Any]      						= num_choices



							def 		_A	(							self				):







											"""simple docstring"""



											a__	:							int      						= ids_tensor([self.batch_size, self.seq_length] ,					self.vocab_size				)

											a__	:							Dict      						= None
											if self.use_attention_mask:
															a__	:							Tuple      						= random_attention_mask([self.batch_size, self.seq_length]				)

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

											a__	:							Any      						= BertConfig(
											    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=__UpperCAmelCase ,					initializer_range=self.initializer_range ,					)

											return config, input_ids, token_type_ids, attention_mask



							def 		_A	(							self				):







											"""simple docstring"""



											a__	:							List[str]      						= self.prepare_config_and_inputs()
											a__						,   a__						,   a__						,   a__	:							int      						= config_and_inputs
											a__	:							Optional[Any]      						= {"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": attention_mask}
											return config, inputs_dict




							def 		_A	(							self				):







											"""simple docstring"""



											a__	:							Dict      						= self.prepare_config_and_inputs()
											a__						,   a__						,   a__						,   a__	:							int      						= config_and_inputs

											a__	:							Optional[int]      						= True
											a__	:							Optional[int]      						= floats_tensor([self.batch_size, self.seq_length, self.hidden_size]				)
											a__	:							int      						= ids_tensor([self.batch_size, self.seq_length] ,					vocab_size=2				)

											return (
											    config,
											    input_ids,
											    attention_mask,
											    encoder_hidden_states,
											    encoder_attention_mask,
											)





@require_flax
class 				_a						(       SCREAMING_SNAKE_CASE       ,  unittest.TestCase			):





							'''simple docstring'''

							A				:int =       True

							A				:List[Any] =       (
							    (
							        FlaxBertModel,
							        FlaxBertForPreTraining,
							        FlaxBertForMaskedLM,
							        FlaxBertForMultipleChoice,
							        FlaxBertForQuestionAnswering,
							        FlaxBertForNextSentencePrediction,
							        FlaxBertForSequenceClassification,
							        FlaxBertForTokenClassification,
							        FlaxBertForQuestionAnswering,
							    )
							    if is_flax_available()
							    else ()
							)



							def 		_A	(							self				):







											"""simple docstring"""



											a__	:							Tuple      						= FlaxBertModelTester(self				)




							@slow
							def 		_A	(							self				):







											"""simple docstring"""



											a__	:							Tuple      						= FlaxBertModel.from_pretrained("bert-base-cased"				)
											a__	:							str      						= model(np.ones((1, 1)				)				)
											self.assertIsNotNone(__UpperCAmelCase				)







from typing import TYPE_CHECKING

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


lowerCamelCase		       =      {
    """configuration_trocr""": ["""TROCR_PRETRAINED_CONFIG_ARCHIVE_MAP""", """TrOCRConfig"""],
    """processing_trocr""": ["""TrOCRProcessor"""],
}


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

						lowerCamelCase		       =      _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)


