

'''simple docstring'''

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


		"""simple docstring"""

		def __init__( self    ,			snake_case    ,			snake_case=1_3    ,			snake_case=7    ,			snake_case=True    ,			snake_case=True    ,			snake_case=True    ,			snake_case=True    ,			snake_case=9_9    ,			snake_case=3_2    ,			snake_case=5    ,			snake_case=4    ,			snake_case=3_7    ,			snake_case="gelu"    ,			snake_case=0.1    ,			snake_case=0.1    ,			snake_case=5_1_2    ,			snake_case=1_6    ,			snake_case=2    ,			snake_case=0.02    ,			snake_case=4    ,			):


							'''simple docstring'''

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







		def       A_       ( self			):


							'''simple docstring'''

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

							UpperCAmelCase		:							Optional[Any]   					=   None
							if self.use_attention_mask:
												UpperCAmelCase		:							int   					=   random_attention_mask([self.batch_size, self.seq_length]			)

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

							UpperCAmelCase		:							List[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=_lowerCamelCase    ,			initializer_range=self.initializer_range    ,			)

							return config, input_ids, token_type_ids, attention_mask







		def       A_       ( self			):


							'''simple docstring'''

							UpperCAmelCase		:							Union[str, Any]   					=   self.prepare_config_and_inputs()
							UpperCAmelCase					, UpperCAmelCase					, UpperCAmelCase					, UpperCAmelCase		:							Tuple   					=   config_and_inputs
							UpperCAmelCase		:							Any   					=   {"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": attention_mask}
							return config, inputs_dict







		def       A_       ( self			):


							'''simple docstring'''

							UpperCAmelCase		:							List[Any]   					=   self.prepare_config_and_inputs()
							UpperCAmelCase					, UpperCAmelCase					, UpperCAmelCase					, UpperCAmelCase		:							int   					=   config_and_inputs

							UpperCAmelCase		:							Optional[Any]   					=   True
							UpperCAmelCase		:							List[Any]   					=   floats_tensor([self.batch_size, self.seq_length, self.hidden_size]			)
							UpperCAmelCase		:							Dict   					=   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   UpperCamelCase__    (   a_							,							unittest.TestCase   ):


		"""simple docstring"""

		SCREAMING_SNAKE_CASE__  :	Dict   =							True

		SCREAMING_SNAKE_CASE__  :	Any   =							(
		    (
		        FlaxBertModel,
		        FlaxBertForPreTraining,
		        FlaxBertForMaskedLM,
		        FlaxBertForMultipleChoice,
		        FlaxBertForQuestionAnswering,
		        FlaxBertForNextSentencePrediction,
		        FlaxBertForSequenceClassification,
		        FlaxBertForTokenClassification,
		        FlaxBertForQuestionAnswering,
		    )
		    if is_flax_available()
		    else ()
		)







		def       A_       ( self			):


							'''simple docstring'''

							UpperCAmelCase		:							List[Any]   					=   FlaxBertModelTester(self			)







		@slow
		def       A_       ( self			):


							'''simple docstring'''

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








"""simple docstring"""



from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


_UpperCamelCase		:  Dict						=		{
    'configuration_roberta': ['ROBERTA_PRETRAINED_CONFIG_ARCHIVE_MAP', 'RobertaConfig', 'RobertaOnnxConfig'],
    'tokenization_roberta': ['RobertaTokenizer'],
}

try:
    if not is_tokenizers_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    _UpperCamelCase		:  str						=		['RobertaTokenizerFast']

try:
    if not is_torch_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    _UpperCamelCase		:  Tuple						=		[
        'ROBERTA_PRETRAINED_MODEL_ARCHIVE_LIST',
        'RobertaForCausalLM',
        'RobertaForMaskedLM',
        'RobertaForMultipleChoice',
        'RobertaForQuestionAnswering',
        'RobertaForSequenceClassification',
        'RobertaForTokenClassification',
        'RobertaModel',
        'RobertaPreTrainedModel',
    ]

try:
    if not is_tf_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    _UpperCamelCase		:  List[Any]						=		[
        'TF_ROBERTA_PRETRAINED_MODEL_ARCHIVE_LIST',
        'TFRobertaForCausalLM',
        'TFRobertaForMaskedLM',
        'TFRobertaForMultipleChoice',
        'TFRobertaForQuestionAnswering',
        'TFRobertaForSequenceClassification',
        'TFRobertaForTokenClassification',
        'TFRobertaMainLayer',
        'TFRobertaModel',
        'TFRobertaPreTrainedModel',
    ]

try:
    if not is_flax_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    _UpperCamelCase		:  Optional[int]						=		[
        'FlaxRobertaForCausalLM',
        'FlaxRobertaForMaskedLM',
        'FlaxRobertaForMultipleChoice',
        'FlaxRobertaForQuestionAnswering',
        'FlaxRobertaForSequenceClassification',
        'FlaxRobertaForTokenClassification',
        'FlaxRobertaModel',
        'FlaxRobertaPreTrainedModel',
    ]


if TYPE_CHECKING:
    from .configuration_roberta import ROBERTA_PRETRAINED_CONFIG_ARCHIVE_MAP, RobertaConfig, RobertaOnnxConfig
    from .tokenization_roberta import RobertaTokenizer

    try:
        if not is_tokenizers_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .tokenization_roberta_fast import RobertaTokenizerFast

    try:
        if not is_torch_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .modeling_roberta import (
            ROBERTA_PRETRAINED_MODEL_ARCHIVE_LIST,
            RobertaForCausalLM,
            RobertaForMaskedLM,
            RobertaForMultipleChoice,
            RobertaForQuestionAnswering,
            RobertaForSequenceClassification,
            RobertaForTokenClassification,
            RobertaModel,
            RobertaPreTrainedModel,
        )

    try:
        if not is_tf_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .modeling_tf_roberta import (
            TF_ROBERTA_PRETRAINED_MODEL_ARCHIVE_LIST,
            TFRobertaForCausalLM,
            TFRobertaForMaskedLM,
            TFRobertaForMultipleChoice,
            TFRobertaForQuestionAnswering,
            TFRobertaForSequenceClassification,
            TFRobertaForTokenClassification,
            TFRobertaMainLayer,
            TFRobertaModel,
            TFRobertaPreTrainedModel,
        )

    try:
        if not is_flax_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .modeling_flax_roberta import (
            FlaxRobertaForCausalLM,
            FlaxRobertaForMaskedLM,
            FlaxRobertaForMultipleChoice,
            FlaxRobertaForQuestionAnswering,
            FlaxRobertaForSequenceClassification,
            FlaxRobertaForTokenClassification,
            FlaxRobertaModel,
            FlaxRobertaPreTrainedModel,
        )

else:
    import sys

    _UpperCamelCase		:  Optional[Any]						=		_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)


