

"""simple docstring"""


import unittest

import numpy as np

from transformers import DistilBertConfig, 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.distilbert.modeling_flax_distilbert import (
			    FlaxDistilBertForMaskedLM,
			    FlaxDistilBertForMultipleChoice,
			    FlaxDistilBertForQuestionAnswering,
			    FlaxDistilBertForSequenceClassification,
			    FlaxDistilBertForTokenClassification,
			    FlaxDistilBertModel,
			)





class     snake_case	(				unittest.TestCase  ):

				def __init__(	self							:				int     ,  UpperCamelCase__							:				Optional[Any]     ,  UpperCamelCase__							:				Any=1_3     ,  UpperCamelCase__							:				str=7     ,  UpperCamelCase__							:				Union[str, Any]=True     ,  UpperCamelCase__							:				Any=True     ,  UpperCamelCase__							:				List[Any]=True     ,  UpperCamelCase__							:				Tuple=True     ,  UpperCamelCase__							:				Union[str, Any]=9_9     ,  UpperCamelCase__							:				str=3_2     ,  UpperCamelCase__							:				List[Any]=5     ,  UpperCamelCase__							:				Dict=4     ,  UpperCamelCase__							:				Tuple=3_7     ,  UpperCamelCase__							:				Optional[int]="gelu"     ,  UpperCamelCase__							:				List[str]=0.1     ,  UpperCamelCase__							:				Optional[Any]=0.1     ,  UpperCamelCase__							:				Optional[int]=5_1_2     ,  UpperCamelCase__							:				Dict=1_6     ,  UpperCamelCase__							:				List[str]=2     ,  UpperCamelCase__							:				Union[str, Any]=0.02     ,  UpperCamelCase__							:				List[Any]=4     ,  )->   Tuple:



						'''simple docstring'''


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

				def 							lowercase_     (	self							:				Any)->   Dict:



						'''simple docstring'''


						__lowerCAmelCase:       Tuple          =			ids_tensor([self.batch_size, self.seq_length]     ,  self.vocab_size)

						__lowerCAmelCase:       List[str]          =			None
						if self.use_attention_mask:
								__lowerCAmelCase:       Tuple          =			random_attention_mask([self.batch_size, self.seq_length])

						__lowerCAmelCase:       str          =			DistilBertConfig(
						    vocab_size=self.vocab_size     ,  dim=self.hidden_size     ,  n_layers=self.num_hidden_layers     ,  n_heads=self.num_attention_heads     ,  hidden_dim=self.intermediate_size     ,  hidden_act=self.hidden_act     ,  dropout=self.hidden_dropout_prob     ,  attention_dropout=self.attention_probs_dropout_prob     ,  max_position_embeddings=self.max_position_embeddings     ,  initializer_range=self.initializer_range     ,  tie_weights_=UpperCamelCase__     ,  )

						return config, input_ids, attention_mask




				def 							lowercase_     (	self							:				List[str])->   Any:



						'''simple docstring'''


						__lowerCAmelCase:       List[Any]          =			self.prepare_config_and_inputs()
						__lowerCAmelCase      , __lowerCAmelCase      , __lowerCAmelCase:       str          =			config_and_inputs
						__lowerCAmelCase:       int          =			{"input_ids": input_ids, "attention_mask": attention_mask}
						return config, inputs_dict





@require_flax
class     snake_case	(				__snake_case,							unittest.TestCase  ):
				SCREAMING_SNAKE_CASE_   :      List[Any]         =  (
				    (
				        FlaxDistilBertModel,
				        FlaxDistilBertForMaskedLM,
				        FlaxDistilBertForMultipleChoice,
				        FlaxDistilBertForQuestionAnswering,
				        FlaxDistilBertForSequenceClassification,
				        FlaxDistilBertForTokenClassification,
				        FlaxDistilBertForQuestionAnswering,
				    )
				    if is_flax_available()
				    else ()
				)

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



						'''simple docstring'''


						__lowerCAmelCase:       int          =			FlaxDistilBertModelTester(self)




				@slow
				def 							lowercase_     (	self							:				Any)->   Optional[int]:



						'''simple docstring'''


						for model_class_name in self.all_model_classes:
								__lowerCAmelCase:       Tuple          =			model_class_name.from_pretrained("distilbert-base-uncased")
								__lowerCAmelCase:       str          =			model(np.ones((1, 1)))
								self.assertIsNotNone(UpperCamelCase__)





@require_flax
class     snake_case	(				unittest.TestCase  ):

				@slow
				def 							lowercase_     (	self							:				Any)->   List[str]:



						'''simple docstring'''


						__lowerCAmelCase:       List[Any]          =			FlaxDistilBertModel.from_pretrained("distilbert-base-uncased")
						__lowerCAmelCase:       Union[str, Any]          =			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]])
						__lowerCAmelCase:       List[Any]          =			np.array([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]])
						__lowerCAmelCase:       Tuple          =			model(UpperCamelCase__     ,  attention_mask=UpperCamelCase__)[0]
						__lowerCAmelCase:       List[str]          =			(1, 1_1, 7_6_8)
						self.assertEqual(output.shape     ,  UpperCamelCase__)
						__lowerCAmelCase:       Optional[int]          =			np.array([[[-0.1639, 0.3299, 0.1648], [-0.1746, 0.3289, 0.1710], [-0.1884, 0.3357, 0.1810]]])

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





"""simple docstring"""


from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


__A						   =			logging.get_logger(__name__)

__A						   =			{
    "microsoft/beit-base-patch16-224-pt22k": (
        "https://huggingface.co/microsoft/beit-base-patch16-224-pt22k/resolve/main/config.json"
    ),
    # See all BEiT models at https://huggingface.co/models?filter=beit
}





class     snake_case	(				__snake_case  ):
				SCREAMING_SNAKE_CASE_   :      Tuple         =  """beit"""

				def __init__(	self							:				List[Any]     ,  UpperCamelCase__							:				List[str]=8_1_9_2     ,  UpperCamelCase__							:				Dict=7_6_8     ,  UpperCamelCase__							:				List[str]=1_2     ,  UpperCamelCase__							:				Union[str, Any]=1_2     ,  UpperCamelCase__							:				Dict=3_0_7_2     ,  UpperCamelCase__							:				Optional[int]="gelu"     ,  UpperCamelCase__							:				Tuple=0.0     ,  UpperCamelCase__							:				Tuple=0.0     ,  UpperCamelCase__							:				Union[str, Any]=0.02     ,  UpperCamelCase__							:				Optional[Any]=1e-12     ,  UpperCamelCase__							:				str=2_2_4     ,  UpperCamelCase__							:				str=1_6     ,  UpperCamelCase__							:				Union[str, Any]=3     ,  UpperCamelCase__							:				Optional[int]=False     ,  UpperCamelCase__							:				int=False     ,  UpperCamelCase__							:				Optional[Any]=False     ,  UpperCamelCase__							:				Optional[Any]=False     ,  UpperCamelCase__							:				Dict=0.1     ,  UpperCamelCase__							:				List[Any]=0.1     ,  UpperCamelCase__							:				Any=True     ,  UpperCamelCase__							:				Optional[Any]=[3, 5, 7, 1_1]     ,  UpperCamelCase__							:				Optional[Any]=[1, 2, 3, 6]     ,  UpperCamelCase__							:				Optional[Any]=True     ,  UpperCamelCase__							:				Tuple=0.4     ,  UpperCamelCase__							:				Optional[Any]=2_5_6     ,  UpperCamelCase__							:				Optional[int]=1     ,  UpperCamelCase__							:				Optional[int]=False     ,  UpperCamelCase__							:				Optional[Any]=2_5_5     ,  **UpperCamelCase__							:				Optional[int]     ,  )->   int:



						'''simple docstring'''


						super().__init__(**UpperCamelCase__)

						__lowerCAmelCase:       str          =			vocab_size
						__lowerCAmelCase:       List[Any]          =			hidden_size
						__lowerCAmelCase:       str          =			num_hidden_layers
						__lowerCAmelCase:       Tuple          =			num_attention_heads
						__lowerCAmelCase:       Union[str, Any]          =			intermediate_size
						__lowerCAmelCase:       List[Any]          =			hidden_act
						__lowerCAmelCase:       Optional[Any]          =			hidden_dropout_prob
						__lowerCAmelCase:       List[Any]          =			attention_probs_dropout_prob
						__lowerCAmelCase:       str          =			initializer_range
						__lowerCAmelCase:       Optional[Any]          =			layer_norm_eps

						__lowerCAmelCase:       Any          =			image_size
						__lowerCAmelCase:       Any          =			patch_size
						__lowerCAmelCase:       Union[str, Any]          =			num_channels
						__lowerCAmelCase:       Tuple          =			use_mask_token
						__lowerCAmelCase:       Optional[Any]          =			use_absolute_position_embeddings
						__lowerCAmelCase:       List[Any]          =			use_relative_position_bias
						__lowerCAmelCase:       Optional[Any]          =			use_shared_relative_position_bias
						__lowerCAmelCase:       List[str]          =			layer_scale_init_value
						__lowerCAmelCase:       str          =			drop_path_rate
						__lowerCAmelCase:       str          =			use_mean_pooling
						# decode head attributes (semantic segmentation)
						__lowerCAmelCase:       Optional[Any]          =			out_indices
						__lowerCAmelCase:       Union[str, Any]          =			pool_scales
						# auxiliary head attributes (semantic segmentation)
						__lowerCAmelCase:       List[str]          =			use_auxiliary_head
						__lowerCAmelCase:       Union[str, Any]          =			auxiliary_loss_weight
						__lowerCAmelCase:       Optional[int]          =			auxiliary_channels
						__lowerCAmelCase:       Dict          =			auxiliary_num_convs
						__lowerCAmelCase:       List[Any]          =			auxiliary_concat_input
						__lowerCAmelCase:       str          =			semantic_loss_ignore_index





class     snake_case	(				__snake_case  ):
				SCREAMING_SNAKE_CASE_   :      Optional[Any]         =  version.parse("""1.11"""  )

				@property
				def 							lowercase_     (	self							:				str)->   Mapping[str, Mapping[int, str]]:



						'''simple docstring'''


						return OrderedDict(
						    [
						        ("pixel_values", {0: "batch", 1: "num_channels", 2: "height", 3: "width"}),
						    ])




				@property
				def 							lowercase_     (	self							:				Any)->   float:



						'''simple docstring'''


						return 1e-4


