

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    ,       A__    ,       A__=13    ,       A__=7    ,       A__=True    ,       A__=True    ,       A__=True    ,       A__=True    ,       A__=99    ,       A__=32    ,       A__=5    ,       A__=4    ,       A__=37    ,       A__="gelu"    ,       A__=0.1    ,       A__=0.1    ,       A__=512    ,       A__=16    ,       A__=2    ,       A__=0.0_2    ,       A__=4    ,       ):
						A__							:    Union[str, Any]        =		parent
						A__							:    Optional[int]        =		batch_size
						A__							:    Dict        =		seq_length
						A__							:    Optional[Any]        =		is_training
						A__							:    Optional[Any]        =		use_attention_mask
						A__							:    List[str]        =		use_token_type_ids
						A__							:    Dict        =		use_labels
						A__							:    Any        =		vocab_size
						A__							:    List[str]        =		hidden_size
						A__							:    Any        =		num_hidden_layers
						A__							:    Optional[Any]        =		num_attention_heads
						A__							:    List[str]        =		intermediate_size
						A__							:    Union[str, Any]        =		hidden_act
						A__							:    Tuple        =		hidden_dropout_prob
						A__							:    int        =		attention_probs_dropout_prob
						A__							:    Tuple        =		max_position_embeddings
						A__							:    List[str]        =		type_vocab_size
						A__							:    Any        =		type_sequence_label_size
						A__							:    List[Any]        =		initializer_range
						A__							:    str        =		num_choices






					def   __A			( self			):
						A__							:    List[Any]        =		ids_tensor([self.batch_size, self.seq_length]    ,       self.vocab_size			)

						A__							:    Dict        =		None
						if self.use_attention_mask:
							A__							:    Union[str, Any]        =		random_attention_mask([self.batch_size, self.seq_length]			)

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

						A__							:    Tuple        =		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=__snake_case    ,       initializer_range=self.initializer_range    ,       )

						return config, input_ids, token_type_ids, attention_mask






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






					def   __A			( self			):
						A__							:    Optional[Any]        =		self.prepare_config_and_inputs()
						A__							:    List[Any]        =		config_and_inputs

						A__							:    Any        =		True
						A__							:    Tuple        =		floats_tensor([self.batch_size, self.seq_length, self.hidden_size]			)
						A__							:    List[str]        =		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						(_snake_case		,   unittest.TestCase				):


					'''simple docstring'''






					UpperCAmelCase__:   List[str]  							=       True

					UpperCAmelCase__:   Optional[int]  							=       (
					    (
					        FlaxBertModel,
					        FlaxBertForPreTraining,
					        FlaxBertForMaskedLM,
					        FlaxBertForMultipleChoice,
					        FlaxBertForQuestionAnswering,
					        FlaxBertForNextSentencePrediction,
					        FlaxBertForSequenceClassification,
					        FlaxBertForTokenClassification,
					        FlaxBertForQuestionAnswering,
					    )
					    if is_flax_available()
					    else ()
					)






					def   __A			( self			):
						A__							:    Optional[Any]        =		FlaxBertModelTester(self			)






					@slow
					def   __A			( self			):
						# Only check this for base model, not necessary for all model classes.
						# This will also help speed-up tests.
						A__							:    Tuple        =		FlaxBertModel.from_pretrained("""bert-base-cased"""			)
						A__							:    List[str]        =		model(np.ones((1, 1)			)			)
						self.assertIsNotNone(__snake_case			)







'''simple docstring'''


UpperCAmelCase_		:   Union[str, Any]							   =		'\n# Transformers installation\n! pip install transformers datasets\n# To install from source instead of the last release, comment the command above and uncomment the following one.\n# ! pip install git+https://github.com/huggingface/transformers.git\n'

UpperCAmelCase_		:   Dict							   =		[{'type': 'code', 'content': INSTALL_CONTENT}]
UpperCAmelCase_		:   Any							   =		{
    '{processor_class}': 'FakeProcessorClass',
    '{model_class}': 'FakeModelClass',
    '{object_class}': 'FakeObjectClass',
}




