






'''simple docstring'''

import unittest

from transformers import BigBirdConfig, 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

     from transformers.models.big_bird.modeling_flax_big_bird import (
         FlaxBigBirdForCausalLM,
         FlaxBigBirdForMaskedLM,
         FlaxBigBirdForMultipleChoice,
         FlaxBigBirdForPreTraining,
         FlaxBigBirdForQuestionAnswering,
         FlaxBigBirdForSequenceClassification,
         FlaxBigBirdForTokenClassification,
         FlaxBigBirdModel,
     )






class        a_		(    unittest.TestCase       ):

  def __init__(   self    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE=2    ,	_SCREAMING_SNAKE_CASE=56    ,	_SCREAMING_SNAKE_CASE=True    ,	_SCREAMING_SNAKE_CASE=True    ,	_SCREAMING_SNAKE_CASE=True    ,	_SCREAMING_SNAKE_CASE=True    ,	_SCREAMING_SNAKE_CASE=99    ,	_SCREAMING_SNAKE_CASE=32    ,	_SCREAMING_SNAKE_CASE=2    ,	_SCREAMING_SNAKE_CASE=2    ,	_SCREAMING_SNAKE_CASE=7    ,	_SCREAMING_SNAKE_CASE="gelu_new"    ,	_SCREAMING_SNAKE_CASE=0.1    ,	_SCREAMING_SNAKE_CASE=0.1    ,	_SCREAMING_SNAKE_CASE=512    ,	_SCREAMING_SNAKE_CASE=16    ,	_SCREAMING_SNAKE_CASE=2    ,	_SCREAMING_SNAKE_CASE=0.0_2    ,	_SCREAMING_SNAKE_CASE=4    ,	_SCREAMING_SNAKE_CASE="block_sparse"    ,	_SCREAMING_SNAKE_CASE=True    ,	_SCREAMING_SNAKE_CASE=False    ,	_SCREAMING_SNAKE_CASE=2    ,	_SCREAMING_SNAKE_CASE=3    ,	)						->   Optional[Any]:



        """simple docstring"""






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

        UpperCamelCase       						=      rescale_embeddings
        UpperCamelCase       						=      attention_type
        UpperCamelCase       						=      use_bias
        UpperCamelCase       						=      block_size
        UpperCamelCase       						=      num_random_blocks

  def 						A__		(   self   )						->   List[Any]:



        """simple docstring"""






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

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

        UpperCamelCase       						=      None
        if self.use_token_type_ids:
              UpperCamelCase       						=      ids_tensor([self.batch_size, self.seq_length]    ,	self.type_vocab_size   )

        UpperCamelCase       						=      BigBirdConfig(
            vocab_size=self.vocab_size    ,	hidden_size=self.hidden_size    ,	num_hidden_layers=self.num_hidden_layers    ,	num_attention_heads=self.num_attention_heads    ,	intermediate_size=self.intermediate_size    ,	hidden_act=self.hidden_act    ,	hidden_dropout_prob=self.hidden_dropout_prob    ,	attention_probs_dropout_prob=self.attention_probs_dropout_prob    ,	max_position_embeddings=self.max_position_embeddings    ,	type_vocab_size=self.type_vocab_size    ,	is_decoder=_SCREAMING_SNAKE_CASE    ,	initializer_range=self.initializer_range    ,	attention_type=self.attention_type    ,	block_size=self.block_size    ,	num_random_blocks=self.num_random_blocks    ,	use_bias=self.use_bias    ,	rescale_embeddings=self.rescale_embeddings    ,	)

        return config, input_ids, token_type_ids, attention_mask


  def 						A__		(   self   )						->   Optional[int]:



        """simple docstring"""






        UpperCamelCase       						=      self.prepare_config_and_inputs()
        UpperCamelCase						,UpperCamelCase						,UpperCamelCase						,UpperCamelCase       						=      config_and_inputs
        UpperCamelCase       						=      {
            """input_ids""": input_ids,
            """token_type_ids""": token_type_ids,
            """attention_mask""": attention_mask,
        }
        return config, inputs_dict






@require_flax
class        a_		(    lowerCamelCase			, unittest.TestCase       ):
  lowercase  	=   (
      (
          FlaxBigBirdForCausalLM,
          FlaxBigBirdModel,
          FlaxBigBirdForPreTraining,
          FlaxBigBirdForMaskedLM,
          FlaxBigBirdForMultipleChoice,
          FlaxBigBirdForQuestionAnswering,
          FlaxBigBirdForSequenceClassification,
          FlaxBigBirdForTokenClassification,
      )
      if is_flax_available()
      else ()
  )

  lowercase  	=   False
  lowercase  	=   False

  def 						A__		(   self   )						->   Optional[int]:



        """simple docstring"""






        UpperCamelCase       						=      FlaxBigBirdModelTester(self   )

  @slow
  # copied from `test_modeling_flax_common` because it takes much longer than other models
  def 						A__		(   self   )						->   Union[str, Any]:



        """simple docstring"""






        super().test_from_pretrained_save_pretrained()

  @slow
  # copied from `test_modeling_flax_common` because it takes much longer than other models
  def 						A__		(   self   )						->   Union[str, Any]:



        """simple docstring"""






        super().test_from_pretrained_with_no_automatic_init()

  @slow
  # copied from `test_modeling_flax_common` because it takes much longer than other models
  def 						A__		(   self   )						->   Optional[Any]:



        """simple docstring"""






        super().test_no_automatic_init()

  @slow
  # copied from `test_modeling_flax_common` because it takes much longer than other models
  def 						A__		(   self   )						->   List[Any]:



        """simple docstring"""






        super().test_hidden_states_output()

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



        """simple docstring"""






        for model_class_name in self.all_model_classes:
              UpperCamelCase       						=      model_class_name.from_pretrained("""google/bigbird-roberta-base"""   )
              self.assertIsNotNone(_SCREAMING_SNAKE_CASE   )

  def 						A__		(   self   )						->   Tuple:



        """simple docstring"""






        if self.test_attn_probs:
              super().test_attention_outputs()

  @slow
  # copied from `test_modeling_flax_common` because it takes much longer than other models
  def 						A__		(   self   )						->   int:



        """simple docstring"""






        UpperCamelCase						,UpperCamelCase       						=      self.model_tester.prepare_config_and_inputs_for_common()

        for model_class in self.all_model_classes:
              with self.subTest(model_class.__name__   ):
                    UpperCamelCase       						=      self._prepare_for_class(_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE   )
                    UpperCamelCase       						=      model_class(_SCREAMING_SNAKE_CASE   )

                    @jax.jit
                    def model_jitted(_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE=None    ,	**_SCREAMING_SNAKE_CASE   ):
                          return model(input_ids=_SCREAMING_SNAKE_CASE    ,	attention_mask=_SCREAMING_SNAKE_CASE    ,	**_SCREAMING_SNAKE_CASE   )

                    with self.subTest("""JIT Enabled"""   ):
                          UpperCamelCase       						=      model_jitted(**_SCREAMING_SNAKE_CASE   ).to_tuple()

                    with self.subTest("""JIT Disabled"""   ):
                          with jax.disable_jit():
                                UpperCamelCase       						=      model_jitted(**_SCREAMING_SNAKE_CASE   ).to_tuple()

                    self.assertEqual(len(_SCREAMING_SNAKE_CASE   )    ,	len(_SCREAMING_SNAKE_CASE   )   )
                    for jitted_output, output in zip(_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE   ):
                          self.assertEqual(jitted_output.shape    ,	output.shape   )


  def 						A__		(   self    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE=1e-5    ,	_SCREAMING_SNAKE_CASE="outputs"    ,	_SCREAMING_SNAKE_CASE=None   )						->   Dict:



        """simple docstring"""






        if name.startswith("""outputs.attentions"""   ):
              return
        else:
              super().check_pt_flax_outputs(_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE   )








'''simple docstring'''

SCREAMING_SNAKE_CASE__											=     8.31_44_62  # Unit - J mol-1 K-1







def 					lowercase__				(   __UpperCamelCase	,		__UpperCamelCase	,		__UpperCamelCase					)->				float:
      if moles < 0 or kelvin < 0 or volume < 0:
            raise ValueError("""Invalid inputs. Enter positive value."""					)
      return moles * kelvin * UNIVERSAL_GAS_CONSTANT / volume







def 					lowercase__				(   __UpperCamelCase	,		__UpperCamelCase	,		__UpperCamelCase					)->				float:
      if moles < 0 or kelvin < 0 or pressure < 0:
            raise ValueError("""Invalid inputs. Enter positive value."""					)
      return moles * kelvin * UNIVERSAL_GAS_CONSTANT / pressure


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

     testmod()
