





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





 """simple docstring"""


 def __init__(    self					,						__lowerCamelCase					,						__lowerCamelCase=13					,						__lowerCamelCase=7					,						__lowerCamelCase=True					,						__lowerCamelCase=True					,						__lowerCamelCase=True					,						__lowerCamelCase=True					,						__lowerCamelCase=99					,						__lowerCamelCase=32					,						__lowerCamelCase=5					,						__lowerCamelCase=4					,						__lowerCamelCase=37					,						__lowerCamelCase="gelu"					,						__lowerCamelCase=0.1					,						__lowerCamelCase=0.1					,						__lowerCamelCase=512					,						__lowerCamelCase=16					,						__lowerCamelCase=2					,						__lowerCamelCase=0.0_2					,						__lowerCamelCase=4					,						):



     '''simple docstring'''




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

 def 					UpperCamelCase__(    self  ):



     '''simple docstring'''




     __A    :						str						 =     ids_tensor([self.batch_size, self.seq_length]					,						self.vocab_size  )

     __A    :						Optional[Any]						 =     None
     if self.use_attention_mask:
         __A    :						Union[str, Any]						 =     random_attention_mask([self.batch_size, self.seq_length]  )

     __A    :						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_=__a					,						)

     return config, input_ids, attention_mask







 def 					UpperCamelCase__(    self  ):



     '''simple docstring'''




     __A    :						Optional[Any]						 =     self.prepare_config_and_inputs()
     __A ,       __A ,       __A    :						Optional[Any]						 =     config_and_inputs
     __A    :						Optional[int]						 =     {'''input_ids''': input_ids, '''attention_mask''': attention_mask}
     return config, inputs_dict






@require_flax
class 		__snake_case					(		UpperCamelCase__							,							unittest.TestCase     ):





 """simple docstring"""


 _lowerCamelCase        =     (
     (
         FlaxDistilBertModel,
         FlaxDistilBertForMaskedLM,
         FlaxDistilBertForMultipleChoice,
         FlaxDistilBertForQuestionAnswering,
         FlaxDistilBertForSequenceClassification,
         FlaxDistilBertForTokenClassification,
         FlaxDistilBertForQuestionAnswering,
     )
     if is_flax_available()
     else ()
 )

 def 					UpperCamelCase__(    self  ):



     '''simple docstring'''




     __A    :						Union[str, Any]						 =     FlaxDistilBertModelTester(self  )







 @slow
 def 					UpperCamelCase__(    self  ):



     '''simple docstring'''




     for model_class_name in self.all_model_classes:
         __A    :						Optional[int]						 =     model_class_name.from_pretrained('''distilbert-base-uncased'''  )
         __A    :						Any						 =     model(np.ones((1, 1)  )  )
         self.assertIsNotNone(__a  )






@require_flax
class 		__snake_case					(		unittest.TestCase     ):





 """simple docstring"""


 @slow
 def 					UpperCamelCase__(    self  ):



     '''simple docstring'''




     __A    :						Tuple						 =     FlaxDistilBertModel.from_pretrained('''distilbert-base-uncased'''  )
     __A    :						int						 =     np.array([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]]  )
     __A    :						Tuple						 =     np.array([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]  )
     __A    :						str						 =     model(__a					,						attention_mask=__a  )[0]
     __A    :						int						 =     (1, 11, 768)
     self.assertEqual(output.shape					,						__a  )
     __A    :						Any						 =     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]					,						__a					,						atol=1e-4  )  )





'''simple docstring'''





from transformers import DistilBertTokenizer, DistilBertTokenizerFast
from transformers.testing_utils import require_tokenizers, slow

from ..bert.test_tokenization_bert import BertTokenizationTest




@require_tokenizers
class        __A      ( UpperCamelCase__	):
    a__       :						Optional[Any]          =  DistilBertTokenizer
    a__       :						Any          =  DistilBertTokenizerFast
    a__       :						str          =  True



    @slow
    def 					_lowercase						(self    :    int ):
         UpperCAmelCase_           =   DistilBertTokenizer.from_pretrained("distilbert-base-uncased" )

         UpperCAmelCase_           =   tokenizer.encode("sequence builders"   ,			add_special_tokens=__a )
         UpperCAmelCase_           =   tokenizer.encode("multi-sequence build"   ,			add_special_tokens=__a )

         UpperCAmelCase_           =   tokenizer.build_inputs_with_special_tokens(__a )
         UpperCAmelCase_           =   tokenizer.build_inputs_with_special_tokens(__a   ,			__a )

         assert encoded_sentence == [tokenizer.cls_token_id] + text + [tokenizer.sep_token_id]
         assert encoded_pair == [tokenizer.cls_token_id] + text + [tokenizer.sep_token_id] + text_a + [
             tokenizer.sep_token_id
         ]




