



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



 '''simple docstring'''







 def __init__(self				,     A				,     A=13				,     A=7				,     A=True				,     A=True				,     A=True				,     A=True				,     A=99				,     A=32				,     A=5				,     A=4				,     A=37				,     A="gelu"				,     A=0.1				,     A=0.1				,     A=512				,     A=16				,     A=2				,     A=0.02				,     A=4				,     )					->  Dict:


      """simple docstring"""



      _a											=						parent
      _a											=						batch_size
      _a											=						seq_length
      _a											=						is_training
      _a											=						use_attention_mask
      _a											=						use_token_type_ids
      _a											=						use_labels
      _a											=						vocab_size
      _a											=						hidden_size
      _a											=						num_hidden_layers
      _a											=						num_attention_heads
      _a											=						intermediate_size
      _a											=						hidden_act
      _a											=						hidden_dropout_prob
      _a											=						attention_probs_dropout_prob
      _a											=						max_position_embeddings
      _a											=						type_vocab_size
      _a											=						type_sequence_label_size
      _a											=						initializer_range
      _a											=						num_choices



 def       a__						(self )					->  Optional[Any]:


      """simple docstring"""



      _a											=						ids_tensor([self.batch_size, self.seq_length]				,     self.vocab_size )

      _a											=						None
      if self.use_attention_mask:
           _a											=						random_attention_mask([self.batch_size, self.seq_length] )

      _a											=						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_=A				,     )

      return config, input_ids, attention_mask



 def       a__						(self )					->  Dict:


      """simple docstring"""



      _a											=						self.prepare_config_and_inputs()
      _a						,					_a						,					_a											=						config_and_inputs
      _a											=						{'''input_ids''': input_ids, '''attention_mask''': attention_mask}
      return config, inputs_dict






@require_flax
class __A    (						A     ,     unittest.TestCase		):



 '''simple docstring'''







 __lowerCamelCase					: Dict    = (
     (
         FlaxDistilBertModel,
         FlaxDistilBertForMaskedLM,
         FlaxDistilBertForMultipleChoice,
         FlaxDistilBertForQuestionAnswering,
         FlaxDistilBertForSequenceClassification,
         FlaxDistilBertForTokenClassification,
         FlaxDistilBertForQuestionAnswering,
     )
     if is_flax_available()
     else ()
 )



 def       a__						(self )					->  Tuple:


      """simple docstring"""



      _a											=						FlaxDistilBertModelTester(self )



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


      """simple docstring"""



      for model_class_name in self.all_model_classes:
           _a											=						model_class_name.from_pretrained('''distilbert-base-uncased''' )
           _a											=						model(np.ones((1, 1) ) )
           self.assertIsNotNone(A )






@require_flax
class __A    (						unittest.TestCase		):



 '''simple docstring'''







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


      """simple docstring"""



      _a											=						FlaxDistilBertModel.from_pretrained('''distilbert-base-uncased''' )
      _a											=						np.array([[0, 345, 232, 328, 740, 140, 1_695, 69, 6_078, 1_588, 2]] )
      _a											=						np.array([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]] )
      _a											=						model(A				,     attention_mask=A )[0]
      _a											=						(1, 11, 768)
      self.assertEqual(output.shape				,     A )
      _a											=						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]				,     A				,     atol=1E-4 ) )








'''simple docstring'''





def lowerCAmelCase						(__A):



     """simple docstring"""



     _a											=						set()
     # To detect a back edge, keep track of vertices currently in the recursion stack
     _a											=						set()
     return any(
         node not in visited and depth_first_search(__A						,			__A						,			__A						,			__A)
         for node in graph)




def lowerCAmelCase						(__A						,			__A						,			__A						,			__A):



     """simple docstring"""



     visited.add(__A)
     rec_stk.add(__A)

     for node in graph[vertex]:
          if node not in visited:
               if depth_first_search(__A						,			__A						,			__A						,			__A):
                    return True
          elif node in rec_stk:
               return True

    # The node needs to be removed from recursion stack before function ends
     rec_stk.remove(__A)
     return False


if __name__ == "__main__":
  from doctest import testmod

  testmod()



