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





     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'''




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





     def 		UpperCAmelCase      (			self   ):

      '''simple docstring'''




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

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

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

      __UpperCamelCase       						= 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 		UpperCAmelCase      (			self   ):

      '''simple docstring'''




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







     def 		UpperCAmelCase      (			self   ):

      '''simple docstring'''




      __UpperCamelCase       						= self.prepare_config_and_inputs()
      __UpperCamelCase						,			__UpperCamelCase						,			__UpperCamelCase						,			__UpperCamelCase       						= config_and_inputs

      __UpperCamelCase       						= True
      __UpperCamelCase       						= floats_tensor([self.batch_size, self.seq_length, self.hidden_size]   )
      __UpperCamelCase       						= 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 __lowerCAmelCase	(   __SCREAMING_SNAKE_CASE    ,						unittest.TestCase    ):
     lowercase		     =		True

     lowercase		     =		(
         (
             FlaxBertModel,
             FlaxBertForPreTraining,
             FlaxBertForMaskedLM,
             FlaxBertForMultipleChoice,
             FlaxBertForQuestionAnswering,
             FlaxBertForNextSentencePrediction,
             FlaxBertForSequenceClassification,
             FlaxBertForTokenClassification,
             FlaxBertForQuestionAnswering,
         )
         if is_flax_available()
         else ()
     )





     def 		UpperCAmelCase      (			self   ):

      '''simple docstring'''




      __UpperCamelCase       						= FlaxBertModelTester(self   )







     @slow
     def 		UpperCAmelCase      (			self   ):

      '''simple docstring'''




      __UpperCamelCase       						= FlaxBertModel.from_pretrained('bert-base-cased'   )
      __UpperCamelCase       						= model(np.ones((1, 1)   )   )
      self.assertIsNotNone(__UpperCAmelCase   )





"""simple docstring"""

from typing import TYPE_CHECKING

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


UpperCamelCase			:       List[Any]									=				{
    "configuration_xlm_roberta": [
        "XLM_ROBERTA_PRETRAINED_CONFIG_ARCHIVE_MAP",
        "XLMRobertaConfig",
        "XLMRobertaOnnxConfig",
    ],
}

try:
      if not is_sentencepiece_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      UpperCamelCase			:       Optional[Any]									=				["XLMRobertaTokenizer"]

try:
      if not is_tokenizers_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      UpperCamelCase			:       int									=				["XLMRobertaTokenizerFast"]

try:
      if not is_torch_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      UpperCamelCase			:       Optional[int]									=				[
          "XLM_ROBERTA_PRETRAINED_MODEL_ARCHIVE_LIST",
          "XLMRobertaForCausalLM",
          "XLMRobertaForMaskedLM",
          "XLMRobertaForMultipleChoice",
          "XLMRobertaForQuestionAnswering",
          "XLMRobertaForSequenceClassification",
          "XLMRobertaForTokenClassification",
          "XLMRobertaModel",
          "XLMRobertaPreTrainedModel",
      ]

try:
      if not is_tf_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      UpperCamelCase			:       List[str]									=				[
          "TF_XLM_ROBERTA_PRETRAINED_MODEL_ARCHIVE_LIST",
          "TFXLMRobertaForCausalLM",
          "TFXLMRobertaForMaskedLM",
          "TFXLMRobertaForMultipleChoice",
          "TFXLMRobertaForQuestionAnswering",
          "TFXLMRobertaForSequenceClassification",
          "TFXLMRobertaForTokenClassification",
          "TFXLMRobertaModel",
          "TFXLMRobertaPreTrainedModel",
      ]

try:
      if not is_flax_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      UpperCamelCase			:       List[str]									=				[
          "FLAX_XLM_ROBERTA_PRETRAINED_MODEL_ARCHIVE_LIST",
          "FlaxXLMRobertaForMaskedLM",
          "FlaxXLMRobertaForCausalLM",
          "FlaxXLMRobertaForMultipleChoice",
          "FlaxXLMRobertaForQuestionAnswering",
          "FlaxXLMRobertaForSequenceClassification",
          "FlaxXLMRobertaForTokenClassification",
          "FlaxXLMRobertaModel",
          "FlaxXLMRobertaPreTrainedModel",
      ]

if TYPE_CHECKING:
      from .configuration_xlm_roberta import (
          XLM_ROBERTA_PRETRAINED_CONFIG_ARCHIVE_MAP,
          XLMRobertaConfig,
          XLMRobertaOnnxConfig,
      )

      try:
            if not is_sentencepiece_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .tokenization_xlm_roberta import XLMRobertaTokenizer

      try:
            if not is_tokenizers_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .tokenization_xlm_roberta_fast import XLMRobertaTokenizerFast

      try:
            if not is_torch_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_xlm_roberta import (
                XLM_ROBERTA_PRETRAINED_MODEL_ARCHIVE_LIST,
                XLMRobertaForCausalLM,
                XLMRobertaForMaskedLM,
                XLMRobertaForMultipleChoice,
                XLMRobertaForQuestionAnswering,
                XLMRobertaForSequenceClassification,
                XLMRobertaForTokenClassification,
                XLMRobertaModel,
                XLMRobertaPreTrainedModel,
            )

      try:
            if not is_tf_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_tf_xlm_roberta import (
                TF_XLM_ROBERTA_PRETRAINED_MODEL_ARCHIVE_LIST,
                TFXLMRobertaForCausalLM,
                TFXLMRobertaForMaskedLM,
                TFXLMRobertaForMultipleChoice,
                TFXLMRobertaForQuestionAnswering,
                TFXLMRobertaForSequenceClassification,
                TFXLMRobertaForTokenClassification,
                TFXLMRobertaModel,
                TFXLMRobertaPreTrainedModel,
            )

      try:
            if not is_flax_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_flax_xlm_roberta import (
                FLAX_XLM_ROBERTA_PRETRAINED_MODEL_ARCHIVE_LIST,
                FlaxXLMRobertaForCausalLM,
                FlaxXLMRobertaForMaskedLM,
                FlaxXLMRobertaForMultipleChoice,
                FlaxXLMRobertaForQuestionAnswering,
                FlaxXLMRobertaForSequenceClassification,
                FlaxXLMRobertaForTokenClassification,
                FlaxXLMRobertaModel,
                FlaxXLMRobertaPreTrainedModel,
            )

else:
      import sys

      UpperCamelCase			:       Dict									=				_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)



