




from ...configuration_utils import PretrainedConfig


lowerCamelCase							:						List[Any]					       =  {
    "google/tapas-base-finetuned-sqa": (
        "https://huggingface.co/google/tapas-base-finetuned-sqa/resolve/main/config.json"
    ),
    "google/tapas-base-finetuned-wtq": (
        "https://huggingface.co/google/tapas-base-finetuned-wtq/resolve/main/config.json"
    ),
    "google/tapas-base-finetuned-wikisql-supervised": (
        "https://huggingface.co/google/tapas-base-finetuned-wikisql-supervised/resolve/main/config.json"
    ),
    "google/tapas-base-finetuned-tabfact": (
        "https://huggingface.co/google/tapas-base-finetuned-tabfact/resolve/main/config.json"
    ),
}







class     A(		UpperCamelCase  ):



 '''simple docstring'''


 UpperCamelCase		  =		'''tapas'''

 def __init__(							self   :    Dict		,				A_   :    int=30522		,				A_   :    int=768		,				A_   :    Any=12		,				A_   :    Tuple=12		,				A_   :    Optional[Any]=3072		,				A_   :    Optional[Any]="gelu"		,				A_   :    Union[str, Any]=0.1		,				A_   :    Dict=0.1		,				A_   :    Optional[Any]=1024		,				A_   :    Tuple=[3, 256, 256, 2, 256, 256, 10]		,				A_   :    Optional[Any]=0.02		,				A_   :    str=1E-12		,				A_   :    str=0		,				A_   :    Tuple=10.0		,				A_   :    int=0		,				A_   :    int=1.0		,				A_   :    Any=None		,				A_   :    List[str]=1.0		,				A_   :    Optional[Any]=False		,				A_   :    List[Any]=None		,				A_   :    Optional[int]=1.0		,				A_   :    Union[str, Any]=1.0		,				A_   :    List[str]=False		,				A_   :    Optional[int]=False		,				A_   :    Any="ratio"		,				A_   :    List[str]=None		,				A_   :    Dict=None		,				A_   :    int=64		,				A_   :    Union[str, Any]=32		,				A_   :    Dict=False		,				A_   :    List[str]=True		,				A_   :    int=False		,				A_   :    Tuple=False		,				A_   :    Dict=True		,				A_   :    Tuple=False		,				A_   :    Optional[Any]=None		,				A_   :    Union[str, Any]=None		,				**A_   :    Optional[int]		,				)  ->      str:

       """simple docstring"""






       super().__init__(pad_token_id=A_		,				**A_    )

       # BERT hyperparameters (with updated max_position_embeddings and type_vocab_sizes)
       lowerCamelCase_							=       vocab_size
       lowerCamelCase_							=       hidden_size
       lowerCamelCase_							=       num_hidden_layers
       lowerCamelCase_							=       num_attention_heads
       lowerCamelCase_							=       hidden_act
       lowerCamelCase_							=       intermediate_size
       lowerCamelCase_							=       hidden_dropout_prob
       lowerCamelCase_							=       attention_probs_dropout_prob
       lowerCamelCase_							=       max_position_embeddings
       lowerCamelCase_							=       type_vocab_sizes
       lowerCamelCase_							=       initializer_range
       lowerCamelCase_							=       layer_norm_eps

       # Fine-tuning task hyperparameters
       lowerCamelCase_							=       positive_label_weight
       lowerCamelCase_							=       num_aggregation_labels
       lowerCamelCase_							=       aggregation_loss_weight
       lowerCamelCase_							=       use_answer_as_supervision
       lowerCamelCase_							=       answer_loss_importance
       lowerCamelCase_							=       use_normalized_answer_loss
       lowerCamelCase_							=       huber_loss_delta
       lowerCamelCase_							=       temperature
       lowerCamelCase_							=       aggregation_temperature
       lowerCamelCase_							=       use_gumbel_for_cells
       lowerCamelCase_							=       use_gumbel_for_aggregation
       lowerCamelCase_							=       average_approximation_function
       lowerCamelCase_							=       cell_selection_preference
       lowerCamelCase_							=       answer_loss_cutoff
       lowerCamelCase_							=       max_num_rows
       lowerCamelCase_							=       max_num_columns
       lowerCamelCase_							=       average_logits_per_cell
       lowerCamelCase_							=       select_one_column
       lowerCamelCase_							=       allow_empty_column_selection
       lowerCamelCase_							=       init_cell_selection_weights_to_zero
       lowerCamelCase_							=       reset_position_index_per_cell
       lowerCamelCase_							=       disable_per_token_loss

       # Aggregation hyperparameters
       lowerCamelCase_							=       aggregation_labels
       lowerCamelCase_							=       no_aggregation_label_index

       if isinstance(self.aggregation_labels		,				A_    ):
             lowerCamelCase_							=       {int(A_    ): v for k, v in aggregation_labels.items()}











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





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





	def 	_SCREAMING_SNAKE_CASE ( self   :					List[str]		)		->     str:
				UpperCAmelCase_	:					List[str]     	=   ids_tensor([self.batch_size, self.seq_length]      ,      self.vocab_size		)

				UpperCAmelCase_	:					Tuple     	=   None
				if self.use_attention_mask:
							UpperCAmelCase_	:					Dict     	=   random_attention_mask([self.batch_size, self.seq_length]		)

				UpperCAmelCase_	:					Any     	=   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_=lowerCAmelCase_      ,      )

				return config, input_ids, attention_mask





	def 	_SCREAMING_SNAKE_CASE ( self   :					List[Any]		)		->     Union[str, Any]:
				UpperCAmelCase_	:					Any     	=   self.prepare_config_and_inputs()
				UpperCAmelCase_	,      UpperCAmelCase_	,      UpperCAmelCase_	:					List[str]     	=   config_and_inputs
				UpperCAmelCase_	:					Optional[Any]     	=   {"input_ids": input_ids, "attention_mask": attention_mask}
				return config, inputs_dict







@require_flax
class      UpperCamelCase_			(__A							,		unittest.TestCase	):
	__magic_name__       =							(
	    (
	        FlaxDistilBertModel,
	        FlaxDistilBertForMaskedLM,
	        FlaxDistilBertForMultipleChoice,
	        FlaxDistilBertForQuestionAnswering,
	        FlaxDistilBertForSequenceClassification,
	        FlaxDistilBertForTokenClassification,
	        FlaxDistilBertForQuestionAnswering,
	    )
	    if is_flax_available()
	    else ()
	)





	def 	_SCREAMING_SNAKE_CASE ( self   :					List[str]		)		->     Optional[Any]:
				UpperCAmelCase_	:					List[Any]     	=   FlaxDistilBertModelTester(self		)





	@slow
	def 	_SCREAMING_SNAKE_CASE ( self   :					Optional[Any]		)		->     List[str]:
				for model_class_name in self.all_model_classes:
							UpperCAmelCase_	:					str     	=   model_class_name.from_pretrained("distilbert-base-uncased"		)
							UpperCAmelCase_	:					List[str]     	=   model(np.ones((1, 1)		)		)
							self.assertIsNotNone(lowerCAmelCase_		)







@require_flax
class      UpperCamelCase_			(unittest.TestCase	):





	@slow
	def 	_SCREAMING_SNAKE_CASE ( self   :					str		)		->     Optional[int]:
				UpperCAmelCase_	:					Any     	=   FlaxDistilBertModel.from_pretrained("distilbert-base-uncased"		)
				UpperCAmelCase_	:					int     	=   np.array([[0, 345, 232, 328, 740, 140, 1_695, 69, 6_078, 1_588, 2]]		)
				UpperCAmelCase_	:					List[str]     	=   np.array([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]		)
				UpperCAmelCase_	:					Any     	=   model(lowerCAmelCase_      ,      attention_mask=lowerCAmelCase_		)[0]
				UpperCAmelCase_	:					Union[str, Any]     	=   (1, 11, 768)
				self.assertEqual(output.shape      ,      lowerCAmelCase_		)
				UpperCAmelCase_	:					Dict     	=   np.array([[[-0.1_6_3_9, 0.3_2_9_9, 0.1_6_4_8], [-0.1_7_4_6, 0.3_2_8_9, 0.1_7_1_0], [-0.1_8_8_4, 0.3_3_5_7, 0.1_8_1_0]]]		)

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



