



'''simple docstring'''





import unittest

import numpy as np

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

from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor, random_attention_mask


if is_flax_available():
       import jax.numpy as jnp

       from transformers.models.albert.modeling_flax_albert import (
           FlaxAlbertForMaskedLM,
           FlaxAlbertForMultipleChoice,
           FlaxAlbertForPreTraining,
           FlaxAlbertForQuestionAnswering,
           FlaxAlbertForSequenceClassification,
           FlaxAlbertForTokenClassification,
           FlaxAlbertModel,
       )







class     UpperCAmelCase_       (       unittest.TestCase	):
    """simple docstring"""







    def __init__(    self					:     str ,     snake_case_					:     Optional[int] ,     snake_case_					:     Optional[Any]=13 ,     snake_case_					:     Optional[Any]=7 ,     snake_case_					:     List[Any]=True ,     snake_case_					:     List[str]=True ,     snake_case_					:     str=True ,     snake_case_					:     Optional[int]=True ,     snake_case_					:     Tuple=99 ,     snake_case_					:     Dict=32 ,     snake_case_					:     str=5 ,     snake_case_					:     Tuple=4 ,     snake_case_					:     str=37 ,     snake_case_					:     str="gelu" ,     snake_case_					:     List[Any]=0.1 ,     snake_case_					:     List[Any]=0.1 ,     snake_case_					:     List[str]=512 ,     snake_case_					:     List[Any]=16 ,     snake_case_					:     str=2 ,     snake_case_					:     Union[str, Any]=0.02 ,     snake_case_					:     Any=4 ,     ):
          snake_case__  :    Any    						=      parent
          snake_case__  :    List[str]    						=      batch_size
          snake_case__  :    Union[str, Any]    						=      seq_length
          snake_case__  :    List[str]    						=      is_training
          snake_case__  :    Optional[Any]    						=      use_attention_mask
          snake_case__  :    Any    						=      use_token_type_ids
          snake_case__  :    Dict    						=      use_labels
          snake_case__  :    List[str]    						=      vocab_size
          snake_case__  :    Dict    						=      hidden_size
          snake_case__  :    Any    						=      num_hidden_layers
          snake_case__  :    List[Any]    						=      num_attention_heads
          snake_case__  :    List[Any]    						=      intermediate_size
          snake_case__  :    str    						=      hidden_act
          snake_case__  :    Optional[int]    						=      hidden_dropout_prob
          snake_case__  :    int    						=      attention_probs_dropout_prob
          snake_case__  :    List[Any]    						=      max_position_embeddings
          snake_case__  :    Union[str, Any]    						=      type_vocab_size
          snake_case__  :    str    						=      type_sequence_label_size
          snake_case__  :    int    						=      initializer_range
          snake_case__  :    List[Any]    						=      num_choices




    def lowerCamelCase       (    self					:     Any						):
          snake_case__  :    Optional[int]    						=      ids_tensor([self.batch_size, self.seq_length] ,     self.vocab_size						)

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

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

          snake_case__  :    List[Any]    						=      AlbertConfig(
              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 lowerCamelCase       (    self					:     str						):
          snake_case__  :    int    						=      self.prepare_config_and_inputs()
          snake_case__  :    str    						=      config_and_inputs
          snake_case__  :    Tuple    						=      {"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": attention_mask}
          return config, inputs_dict







@require_flax
class     UpperCAmelCase_       (       _lowercase		,		unittest.TestCase	):
    """simple docstring"""







    lowercase					=		(
        (
            FlaxAlbertModel,
            FlaxAlbertForPreTraining,
            FlaxAlbertForMaskedLM,
            FlaxAlbertForMultipleChoice,
            FlaxAlbertForQuestionAnswering,
            FlaxAlbertForSequenceClassification,
            FlaxAlbertForTokenClassification,
            FlaxAlbertForQuestionAnswering,
        )
        if is_flax_available()
        else ()
    )




    def lowerCamelCase       (    self					:     int						):
          snake_case__  :    int    						=      FlaxAlbertModelTester(self						)




    @slow
    def lowerCamelCase       (    self					:     str						):
          for model_class_name in self.all_model_classes:
                snake_case__  :    Union[str, Any]    						=      model_class_name.from_pretrained("""albert-base-v2"""						)
                snake_case__  :    Dict    						=      model(np.ones((1, 1)						)						)
                self.assertIsNotNone(UpperCamelCase__						)







@require_flax
class     UpperCAmelCase_       (       unittest.TestCase	):
    """simple docstring"""







    @slow
    def lowerCamelCase       (    self					:     List[Any]						):
          snake_case__  :    Dict    						=      FlaxAlbertModel.from_pretrained("""albert-base-v2"""						)
          snake_case__  :    Dict    						=      np.array([[0, 345, 232, 328, 740, 140, 1_695, 69, 6_078, 1_588, 2]]						)
          snake_case__  :    List[str]    						=      np.array([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]						)
          snake_case__  :    int    						=      model(UpperCamelCase__ ,     attention_mask=UpperCamelCase__						)[0]
          snake_case__  :    List[Any]    						=      (1, 11, 768)
          self.assertEqual(output.shape ,     UpperCamelCase__						)
          snake_case__  :    int    						=      np.array(
              [[[-0.6513, 1.5035, -0.2766], [-0.6515, 1.5046, -0.2780], [-0.6512, 1.5049, -0.2784]]]						)

          self.assertTrue(jnp.allclose(output[:, 1:4, 1:4] ,     UpperCamelCase__ ,     atol=1E-4						)						)








'''simple docstring'''







from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


_A	:			Dict         ={
    '''configuration_swinv2''': ['''SWINV2_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''Swinv2Config'''],
}


try:
			if not is_torch_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			_A	:			List[Any]         =[
			    '''SWINV2_PRETRAINED_MODEL_ARCHIVE_LIST''',
			    '''Swinv2ForImageClassification''',
			    '''Swinv2ForMaskedImageModeling''',
			    '''Swinv2Model''',
			    '''Swinv2PreTrainedModel''',
			]


if TYPE_CHECKING:
			from .configuration_swinva import SWINV2_PRETRAINED_CONFIG_ARCHIVE_MAP, SwinvaConfig

			try:
						if not is_torch_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .modeling_swinva import (
						    SWINV2_PRETRAINED_MODEL_ARCHIVE_LIST,
						    SwinvaForImageClassification,
						    SwinvaForMaskedImageModeling,
						    SwinvaModel,
						    SwinvaPreTrainedModel,
						)


else:
			import sys

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

