
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      ):



      """simple docstring"""







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




      def 		snake_case_			(      self		:       Tuple				):
          __lowercase		:			int	    =       ids_tensor([self.batch_size, self.seq_length]				,       self.vocab_size				)

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

          __lowercase		:			Optional[int]	    =       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_=_snake_case				,       )

          return config, input_ids, attention_mask




      def 		snake_case_			(      self		:       Any				):
          __lowercase		:			Any	    =       self.prepare_config_and_inputs()
          __lowercase		:			List[str]	    =       config_and_inputs
          __lowercase		:			str	    =       {'''input_ids''': input_ids, '''attention_mask''': attention_mask}
          return config, inputs_dict






@require_flax
class 						__lowerCAmelCase	(	lowerCAmelCase_ , unittest.TestCase      ):



      """simple docstring"""







      A__	:			str        =    (
          (
              FlaxDistilBertModel,
              FlaxDistilBertForMaskedLM,
              FlaxDistilBertForMultipleChoice,
              FlaxDistilBertForQuestionAnswering,
              FlaxDistilBertForSequenceClassification,
              FlaxDistilBertForTokenClassification,
              FlaxDistilBertForQuestionAnswering,
          )
          if is_flax_available()
          else ()
      )




      def 		snake_case_			(      self		:       str				):
          __lowercase		:			Optional[Any]	    =       FlaxDistilBertModelTester(self				)




      @slow
      def 		snake_case_			(      self		:       List[Any]				):
          for model_class_name in self.all_model_classes:
              __lowercase		:			int	    =       model_class_name.from_pretrained('''distilbert-base-uncased'''				)
              __lowercase		:			List[Any]	    =       model(np.ones((1, 1)				)				)
              self.assertIsNotNone(_snake_case				)






@require_flax
class 						__lowerCAmelCase	(	unittest.TestCase      ):



      """simple docstring"""







      @slow
      def 		snake_case_			(      self		:       List[Any]				):
          __lowercase		:			Union[str, Any]	    =       FlaxDistilBertModel.from_pretrained('''distilbert-base-uncased'''				)
          __lowercase		:			Optional[Any]	    =       np.array([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]]				)
          __lowercase		:			Tuple	    =       np.array([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]				)
          __lowercase		:			Any	    =       model(_snake_case				,       attention_mask=_snake_case				)[0]
          __lowercase		:			Dict	    =       (1, 11, 768)
          self.assertEqual(output.shape				,       _snake_case				)
          __lowercase		:			str	    =       np.array([[[-0.16_39, 0.32_99, 0.16_48], [-0.17_46, 0.32_89, 0.17_10], [-0.18_84, 0.33_57, 0.18_10]]]				)

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




from __future__ import annotations


def     UpperCAmelCase_  (						__lowerCAmelCase	) ->						int:
    if not nums:
        return 0
    __lowercase		:			List[Any]	    =       nums[0]
    __lowercase		:			Union[str, Any]	    =       0
    for num in nums[1:]:
        __lowercase    ,      __lowercase		:			Dict	    =       (
            max_excluding + num,
            max(__lowerCAmelCase	,					__lowerCAmelCase	),
        )
    return max(__lowerCAmelCase	,					__lowerCAmelCase	)


if __name__ == "__main__":
 import doctest

 doctest.testmod()


