



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



       def __init__(				self     ,UpperCAmelCase_     ,UpperCAmelCase_=13     ,UpperCAmelCase_=7     ,UpperCAmelCase_=True     ,UpperCAmelCase_=True     ,UpperCAmelCase_=True     ,UpperCAmelCase_=True     ,UpperCAmelCase_=99     ,UpperCAmelCase_=32     ,UpperCAmelCase_=5     ,UpperCAmelCase_=4     ,UpperCAmelCase_=37     ,UpperCAmelCase_="gelu"     ,UpperCAmelCase_=0.1     ,UpperCAmelCase_=0.1     ,UpperCAmelCase_=512     ,UpperCAmelCase_=16     ,UpperCAmelCase_=2     ,UpperCAmelCase_=0.02     ,UpperCAmelCase_=4     ,)  ->							int:
           lowercase__		       =						parent
           lowercase__		       =						batch_size
           lowercase__		       =						seq_length
           lowercase__		       =						is_training
           lowercase__		       =						use_attention_mask
           lowercase__		       =						use_token_type_ids
           lowercase__		       =						use_labels
           lowercase__		       =						vocab_size
           lowercase__		       =						hidden_size
           lowercase__		       =						num_hidden_layers
           lowercase__		       =						num_attention_heads
           lowercase__		       =						intermediate_size
           lowercase__		       =						hidden_act
           lowercase__		       =						hidden_dropout_prob
           lowercase__		       =						attention_probs_dropout_prob
           lowercase__		       =						max_position_embeddings
           lowercase__		       =						type_vocab_size
           lowercase__		       =						type_sequence_label_size
           lowercase__		       =						initializer_range
           lowercase__		       =						num_choices



       def 							_a      (				self      )  ->							List[str]:
           lowercase__		       =						ids_tensor([self.batch_size, self.seq_length]     ,self.vocab_size      )

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

           lowercase__		       =						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_=lowerCamelCase__     ,)

           return config, input_ids, attention_mask







       def 							_a      (				self      )  ->							Tuple:
           lowercase__		       =						self.prepare_config_and_inputs()
           lowercase__		       =						config_and_inputs
           lowercase__		       =						{'''input_ids''': input_ids, '''attention_mask''': attention_mask}
           return config, inputs_dict





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



       def 							_a      (				self      )  ->							Optional[Any]:
           lowercase__		       =						FlaxDistilBertModelTester(self      )







       @slow
       def 							_a      (				self      )  ->							int:






           for model_class_name in self.all_model_classes:
               lowercase__		       =						model_class_name.from_pretrained("distilbert-base-uncased"      )
               lowercase__		       =						model(np.ones((1, 1)      )      )
               self.assertIsNotNone(lowerCamelCase__      )





@require_flax
class 				snake_case (unittest.TestCase   ):



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









'''simple docstring'''





def        lowerCamelCase  (				_snake_case  :						int     ,_snake_case  :						float     ,_snake_case  :						float       ):





    '''simple docstring'''


    return round(float(moles / volume       ) * nfactor       )




def        lowerCamelCase  (				_snake_case  :						float     ,_snake_case  :						float     ,_snake_case  :						float       ):





    '''simple docstring'''


    return round(float((moles * 0.0_821 * temperature) / (volume)       )       )




def        lowerCamelCase  (				_snake_case  :						float     ,_snake_case  :						float     ,_snake_case  :						float       ):





    '''simple docstring'''


    return round(float((moles * 0.0_821 * temperature) / (pressure)       )       )




def        lowerCamelCase  (				_snake_case  :						float     ,_snake_case  :						float     ,_snake_case  :						float       ):





    '''simple docstring'''


    return round(float((pressure * volume) / (0.0_821 * moles)       )       )


if __name__ == "__main__":
 import doctest

 doctest.testmod()




