



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







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

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







      def 					__lowercase    (  self   :      List[Any]				):

             """simple docstring"""
             SCREAMING_SNAKE_CASE					:      List[Any]     					=			ids_tensor([self.batch_size, self.seq_length]				,    self.vocab_size				)

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

             SCREAMING_SNAKE_CASE					:      Union[str, 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_=UpperCamelCase__				,    )

             return config, input_ids, attention_mask







      def 					__lowercase    (  self   :      int				):

             """simple docstring"""
             SCREAMING_SNAKE_CASE					:      Any     					=			self.prepare_config_and_inputs()
             SCREAMING_SNAKE_CASE					:      Tuple     					=			config_and_inputs
             SCREAMING_SNAKE_CASE					:      str     					=			{'''input_ids''': input_ids, '''attention_mask''': attention_mask}
             return config, inputs_dict


@require_flax
class 	lowerCamelCase_							(					UpperCamelCase_    ,				unittest.TestCase			):
      _lowerCAmelCase     :   Union[str, Any]	     =				(
          (
              FlaxDistilBertModel,
              FlaxDistilBertForMaskedLM,
              FlaxDistilBertForMultipleChoice,
              FlaxDistilBertForQuestionAnswering,
              FlaxDistilBertForSequenceClassification,
              FlaxDistilBertForTokenClassification,
              FlaxDistilBertForQuestionAnswering,
          )
          if is_flax_available()
          else ()
      )







      def 					__lowercase    (  self   :      Any				):

             """simple docstring"""
             SCREAMING_SNAKE_CASE					:      Union[str, Any]     					=			FlaxDistilBertModelTester(self				)







      @slow
      def 					__lowercase    (  self   :      Any				):

             """simple docstring"""





             for model_class_name in self.all_model_classes:
                    SCREAMING_SNAKE_CASE					:      str     					=			model_class_name.from_pretrained('''distilbert-base-uncased'''				)
                    SCREAMING_SNAKE_CASE					:      Dict     					=			model(np.ones((1, 1)				)				)
                    self.assertIsNotNone(UpperCamelCase__				)


@require_flax
class 	lowerCamelCase_							(					unittest.TestCase			):







      @slow
      def 					__lowercase    (  self   :      int				):

             """simple docstring"""
             SCREAMING_SNAKE_CASE					:      Any     					=			FlaxDistilBertModel.from_pretrained('''distilbert-base-uncased'''				)
             SCREAMING_SNAKE_CASE					:      List[Any]     					=			np.array([[0, 3_45, 2_32, 3_28, 7_40, 1_40, 16_95, 69, 60_78, 15_88, 2]]				)
             SCREAMING_SNAKE_CASE					:      Any     					=			np.array([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]				)
             SCREAMING_SNAKE_CASE					:      Tuple     					=			model(UpperCamelCase__				,    attention_mask=UpperCamelCase__				)[0]
             SCREAMING_SNAKE_CASE					:      Tuple     					=			(1, 11, 7_68)
             self.assertEqual(output.shape				,    UpperCamelCase__				)
             SCREAMING_SNAKE_CASE					:      str     					=			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 typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tf_available, is_torch_available


lowerCAmelCase_     :       Tuple								=						{
    'configuration_tapas': ['TAPAS_PRETRAINED_CONFIG_ARCHIVE_MAP', 'TapasConfig'],
    'tokenization_tapas': ['TapasTokenizer'],
}

try:
							if not is_torch_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							lowerCAmelCase_     :       Dict								=						[
							    'TAPAS_PRETRAINED_MODEL_ARCHIVE_LIST',
							    'TapasForMaskedLM',
							    'TapasForQuestionAnswering',
							    'TapasForSequenceClassification',
							    'TapasModel',
							    'TapasPreTrainedModel',
							    'load_tf_weights_in_tapas',
							]
try:
							if not is_tf_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							lowerCAmelCase_     :       str								=						[
							    'TF_TAPAS_PRETRAINED_MODEL_ARCHIVE_LIST',
							    'TFTapasForMaskedLM',
							    'TFTapasForQuestionAnswering',
							    'TFTapasForSequenceClassification',
							    'TFTapasModel',
							    'TFTapasPreTrainedModel',
							]


if TYPE_CHECKING:
							from .configuration_tapas import TAPAS_PRETRAINED_CONFIG_ARCHIVE_MAP, TapasConfig
							from .tokenization_tapas import TapasTokenizer

							try:
														if not is_torch_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_tapas import (
														    TAPAS_PRETRAINED_MODEL_ARCHIVE_LIST,
														    TapasForMaskedLM,
														    TapasForQuestionAnswering,
														    TapasForSequenceClassification,
														    TapasModel,
														    TapasPreTrainedModel,
														    load_tf_weights_in_tapas,
														)

							try:
														if not is_tf_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_tf_tapas import (
														    TF_TAPAS_PRETRAINED_MODEL_ARCHIVE_LIST,
														    TFTapasForMaskedLM,
														    TFTapasForQuestionAnswering,
														    TFTapasForSequenceClassification,
														    TFTapasModel,
														    TFTapasPreTrainedModel,
														)


else:
							import sys

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




