


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 				SCREAMING_SNAKE_CASE__						(       unittest.TestCase    ):
      def __init__( self       : Dict  ,							SCREAMING_SNAKE_CASE__       : Union[str, Any]  ,							SCREAMING_SNAKE_CASE__       : int=1_3  ,							SCREAMING_SNAKE_CASE__       : int=7  ,							SCREAMING_SNAKE_CASE__       : str=True  ,							SCREAMING_SNAKE_CASE__       : Union[str, Any]=True  ,							SCREAMING_SNAKE_CASE__       : Dict=True  ,							SCREAMING_SNAKE_CASE__       : Union[str, Any]=True  ,							SCREAMING_SNAKE_CASE__       : List[Any]=9_9  ,							SCREAMING_SNAKE_CASE__       : List[str]=3_2  ,							SCREAMING_SNAKE_CASE__       : Optional[Any]=5  ,							SCREAMING_SNAKE_CASE__       : Union[str, Any]=4  ,							SCREAMING_SNAKE_CASE__       : str=3_7  ,							SCREAMING_SNAKE_CASE__       : List[str]="gelu"  ,							SCREAMING_SNAKE_CASE__       : Optional[Any]=0.1  ,							SCREAMING_SNAKE_CASE__       : Optional[int]=0.1  ,							SCREAMING_SNAKE_CASE__       : Any=5_1_2  ,							SCREAMING_SNAKE_CASE__       : Optional[Any]=1_6  ,							SCREAMING_SNAKE_CASE__       : Dict=2  ,							SCREAMING_SNAKE_CASE__       : str=0.02  ,							SCREAMING_SNAKE_CASE__       : str=4  ,							)	->    List[Any]:
             a_      :	List[str]							=						parent
             a_      :	List[Any]							=						batch_size
             a_      :	Optional[Any]							=						seq_length
             a_      :	Dict							=						is_training
             a_      :	Optional[int]							=						use_attention_mask
             a_      :	Optional[Any]							=						use_token_type_ids
             a_      :	List[Any]							=						use_labels
             a_      :	int							=						vocab_size
             a_      :	Tuple							=						hidden_size
             a_      :	str							=						num_hidden_layers
             a_      :	int							=						num_attention_heads
             a_      :	Tuple							=						intermediate_size
             a_      :	Dict							=						hidden_act
             a_      :	int							=						hidden_dropout_prob
             a_      :	List[Any]							=						attention_probs_dropout_prob
             a_      :	str							=						max_position_embeddings
             a_      :	Union[str, Any]							=						type_vocab_size
             a_      :	Dict							=						type_sequence_label_size
             a_      :	List[Any]							=						initializer_range
             a_      :	Tuple							=						num_choices
      def  SCREAMING_SNAKE_CASE							( self       : str  )	->    str:
             a_      :	List[str]							=						ids_tensor([self.batch_size, self.seq_length]  ,							self.vocab_size  )

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

             a_      :	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_=SCREAMING_SNAKE_CASE__  ,							)

             return config, input_ids, attention_mask

      def  SCREAMING_SNAKE_CASE							( self       : List[str]  )	->    Dict:
             a_      :	Union[str, Any]							=						self.prepare_config_and_inputs()
             a_      :	Optional[int]							=						config_and_inputs
             a_      :	Union[str, Any]							=						{'input_ids': input_ids, 'attention_mask': attention_mask}
             return config, inputs_dict
@require_flax
class 				SCREAMING_SNAKE_CASE__						(       lowercase__		,					unittest.TestCase    ):
      snake_case__       :  Tuple       =		(
          (
              FlaxDistilBertModel,
              FlaxDistilBertForMaskedLM,
              FlaxDistilBertForMultipleChoice,
              FlaxDistilBertForQuestionAnswering,
              FlaxDistilBertForSequenceClassification,
              FlaxDistilBertForTokenClassification,
              FlaxDistilBertForQuestionAnswering,
          )
          if is_flax_available()
          else ()
      )
      def  SCREAMING_SNAKE_CASE							( self       : Any  )	->    int:
             a_      :	Union[str, Any]							=						FlaxDistilBertModelTester(self  )

      @slow
      def  SCREAMING_SNAKE_CASE							( self       : Tuple  )	->    List[Any]:
             for model_class_name in self.all_model_classes:
                    a_      :	Optional[Any]							=						model_class_name.from_pretrained('distilbert-base-uncased'  )
                    a_      :	Tuple							=						model(np.ones((1, 1)  )  )
                    self.assertIsNotNone(SCREAMING_SNAKE_CASE__  )
@require_flax
class 				SCREAMING_SNAKE_CASE__						(       unittest.TestCase    ):
      @slow
      def  SCREAMING_SNAKE_CASE							( self       : Optional[Any]  )	->    List[Any]:
             a_      :	List[Any]							=						FlaxDistilBertModel.from_pretrained('distilbert-base-uncased'  )
             a_      :	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]]  )
             a_      :	Dict							=						np.array([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]  )
             a_      :	Optional[Any]							=						model(SCREAMING_SNAKE_CASE__  ,							attention_mask=SCREAMING_SNAKE_CASE__  )[0]
             a_      :	Tuple							=						(1, 1_1, 7_6_8)
             self.assertEqual(output.shape  ,							SCREAMING_SNAKE_CASE__  )
             a_      :	List[Any]							=						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]  ,							SCREAMING_SNAKE_CASE__  ,							atol=1E-4  )  )





def  SCREAMING_SNAKE_CASE_		(    __A				:    int       )			->	bool:

       """simple docstring"""

       a_      :	List[Any]							=						n ** (1 / 3)
       return (val * val * val) == n


if __name__ == "__main__":
   print(perfect_cube(27))
   print(perfect_cube(4))


