





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


   def __init__(   self      :    Tuple      ,					a      :    List[str]      ,					a      :    Union[str, Any]=13      ,					a      :    Tuple=7      ,					a      :    List[str]=True      ,					a      :    Tuple=True      ,					a      :    Optional[int]=True      ,					a      :    Any=True      ,					a      :    Optional[Any]=99      ,					a      :    Optional[Any]=32      ,					a      :    Optional[int]=5      ,					a      :    int=4      ,					a      :    Dict=37      ,					a      :    Union[str, Any]="gelu"      ,					a      :    List[str]=0.1      ,					a      :    Optional[int]=0.1      ,					a      :    Dict=512      ,					a      :    List[Any]=16      ,					a      :    Tuple=2      ,					a      :    Dict=0.02      ,					a      :    int=4      ,					)->       List[str]:





     """simple docstring"""







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


   def 	SCREAMING_SNAKE_CASE_							(   self      :    Union[str, Any]	)->       Tuple:





     """simple docstring"""







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

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

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

     lowercase__           =  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=a      ,					initializer_range=self.initializer_range      ,					)

     return config, input_ids, token_type_ids, attention_mask


   def 	SCREAMING_SNAKE_CASE_							(   self      :    Tuple	)->       int:





     """simple docstring"""







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


   def 	SCREAMING_SNAKE_CASE_							(   self      :    Dict	)->       List[str]:





     """simple docstring"""







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

     lowercase__           =  True
     lowercase__           =  floats_tensor([self.batch_size, self.seq_length, self.hidden_size]	)
     lowercase__           =  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     SCREAMING_SNAKE_CASE       (UpperCAmelCase      ,     unittest.TestCase				):
   _UpperCamelCase   :		Union[str, Any]			 =	True

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


   def 	SCREAMING_SNAKE_CASE_							(   self      :    List[str]	)->       List[str]:





     """simple docstring"""







     lowercase__           =  FlaxBertModelTester(self	)


   @slow
   def 	SCREAMING_SNAKE_CASE_							(   self      :    Tuple	)->       Tuple:





     """simple docstring"""







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









from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tf_available,
    is_torch_available,
    is_vision_available,
)


lowercase_          =		{
    """configuration_efficientformer""": [
        """EFFICIENTFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP""",
        """EfficientFormerConfig""",
    ]
}

try:
      if not is_vision_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      lowercase_          =		["""EfficientFormerImageProcessor"""]

try:
      if not is_torch_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      lowercase_          =		[
          """EFFICIENTFORMER_PRETRAINED_MODEL_ARCHIVE_LIST""",
          """EfficientFormerForImageClassification""",
          """EfficientFormerForImageClassificationWithTeacher""",
          """EfficientFormerModel""",
          """EfficientFormerPreTrainedModel""",
      ]

try:
      if not is_tf_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      lowercase_          =		[
          """TF_EFFICIENTFORMER_PRETRAINED_MODEL_ARCHIVE_LIST""",
          """TFEfficientFormerForImageClassification""",
          """TFEfficientFormerForImageClassificationWithTeacher""",
          """TFEfficientFormerModel""",
          """TFEfficientFormerPreTrainedModel""",
      ]

if TYPE_CHECKING:
      from .configuration_efficientformer import EFFICIENTFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP, EfficientFormerConfig

      try:
            if not is_vision_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .image_processing_efficientformer import EfficientFormerImageProcessor

      try:
            if not is_torch_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_efficientformer import (
                EFFICIENTFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
                EfficientFormerForImageClassification,
                EfficientFormerForImageClassificationWithTeacher,
                EfficientFormerModel,
                EfficientFormerPreTrainedModel,
            )
      try:
            if not is_tf_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_tf_efficientformer import (
                TF_EFFICIENTFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
                TFEfficientFormerForImageClassification,
                TFEfficientFormerForImageClassificationWithTeacher,
                TFEfficientFormerModel,
                TFEfficientFormerPreTrainedModel,
            )

else:
      import sys

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


