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




	'''simple docstring'''




	def __init__(      self	:List[str]  ,     a	:Optional[int]  ,     a	:int=1_3  ,     a	:Any=7  ,     a	:Optional[Any]=True  ,     a	:List[Any]=True  ,     a	:List[str]=True  ,     a	:Dict=True  ,     a	:str=9_9  ,     a	:List[str]=3_2  ,     a	:Any=5  ,     a	:List[Any]=4  ,     a	:str=3_7  ,     a	:List[Any]="gelu"  ,     a	:Any=0.1  ,     a	:Tuple=0.1  ,     a	:Tuple=5_1_2  ,     a	:Any=1_6  ,     a	:str=2  ,     a	:Union[str, Any]=0.02  ,     a	:str=4  ,     )	->				str:
								__UpperCamelCase			:     Union[str, Any]         =      parent
								__UpperCamelCase			:     List[str]         =      batch_size
								__UpperCamelCase			:     List[Any]         =      seq_length
								__UpperCamelCase			:     int         =      is_training
								__UpperCamelCase			:     Optional[int]         =      use_attention_mask
								__UpperCamelCase			:     Union[str, Any]         =      use_token_type_ids
								__UpperCamelCase			:     str         =      use_labels
								__UpperCamelCase			:     Optional[Any]         =      vocab_size
								__UpperCamelCase			:     Optional[int]         =      hidden_size
								__UpperCamelCase			:     Dict         =      num_hidden_layers
								__UpperCamelCase			:     Dict         =      num_attention_heads
								__UpperCamelCase			:     List[Any]         =      intermediate_size
								__UpperCamelCase			:     str         =      hidden_act
								__UpperCamelCase			:     int         =      hidden_dropout_prob
								__UpperCamelCase			:     Optional[Any]         =      attention_probs_dropout_prob
								__UpperCamelCase			:     Tuple         =      max_position_embeddings
								__UpperCamelCase			:     Optional[Any]         =      type_vocab_size
								__UpperCamelCase			:     Optional[int]         =      type_sequence_label_size
								__UpperCamelCase			:     List[Any]         =      initializer_range
								__UpperCamelCase			:     Tuple         =      num_choices







	def      _lowerCamelCase       (      self	:Union[str, Any]		)	->				Union[str, Any]:
								__UpperCamelCase			:     Tuple         =      ids_tensor([self.batch_size, self.seq_length]  ,     self.vocab_size		)

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

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

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

								return config, input_ids, token_type_ids, attention_mask







	def      _lowerCamelCase       (      self	:int		)	->				int:
								__UpperCamelCase			:     Optional[Any]         =      self.prepare_config_and_inputs()
								__UpperCamelCase     ,		__UpperCamelCase     ,		__UpperCamelCase     ,		__UpperCamelCase			:     Optional[Any]         =      config_and_inputs
								__UpperCamelCase			:     List[Any]         =      {"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": attention_mask}
								return config, inputs_dict




@require_flax
class 				lowerCamelCase__							(       __lowercase  ,		unittest.TestCase):




	'''simple docstring'''




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







	def      _lowerCamelCase       (      self	:Optional[int]		)	->				Any:
								__UpperCamelCase			:     Optional[Any]         =      FlaxAlbertModelTester(self		)







	@slow
	def      _lowerCamelCase       (      self	:int		)	->				int:
								for model_class_name in self.all_model_classes:
															__UpperCamelCase			:     int         =      model_class_name.from_pretrained("albert-base-v2"		)
															__UpperCamelCase			:     List[Any]         =      model(np.ones((1, 1)		)		)
															self.assertIsNotNone(a		)




@require_flax
class 				lowerCamelCase__							(       unittest.TestCase):




	'''simple docstring'''




	@slow
	def      _lowerCamelCase       (      self	:Any		)	->				str:
								__UpperCamelCase			:     str         =      FlaxAlbertModel.from_pretrained("albert-base-v2"		)
								__UpperCamelCase			:     int         =      np.array([[0, 3_4_5, 2_3_2, 3_2_8, 7_4_0, 1_4_0, 1_6_9_5, 6_9, 6_0_7_8, 1_5_8_8, 2]]		)
								__UpperCamelCase			:     int         =      np.array([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]		)
								__UpperCamelCase			:     List[Any]         =      model(a  ,     attention_mask=a		)[0]
								__UpperCamelCase			:     List[str]         =      (1, 1_1, 7_6_8)
								self.assertEqual(output.shape  ,     a		)
								__UpperCamelCase			:     Any         =      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]  ,     a  ,     atol=1E-4		)		)

from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


lowercase						:      Tuple									= {
    'configuration_swinv2': ['SWINV2_PRETRAINED_CONFIG_ARCHIVE_MAP', 'Swinv2Config'],
}


try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		lowercase						:      Union[str, 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

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