
import unittest

import numpy as np

from transformers import RobertaConfig, is_flax_available
from transformers.testing_utils import require_flax, slow

from ...test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask


if is_flax_available():
   from transformers.models.roberta.modeling_flax_roberta import (
       FlaxRobertaForCausalLM,
       FlaxRobertaForMaskedLM,
       FlaxRobertaForMultipleChoice,
       FlaxRobertaForQuestionAnswering,
       FlaxRobertaForSequenceClassification,
       FlaxRobertaForTokenClassification,
       FlaxRobertaModel,
   )






class   UpperCAmelCase		(						unittest.TestCase ):



   def __init__(self		:					Optional[Any]    ,						snake_case__		:					Optional[Any]    ,						snake_case__		:					Optional[Any]=13    ,						snake_case__		:					Dict=7    ,						snake_case__		:					List[str]=True    ,						snake_case__		:					List[Any]=True    ,						snake_case__		:					List[str]=True    ,						snake_case__		:					Optional[Any]=True    ,						snake_case__		:					int=99    ,						snake_case__		:					List[str]=32    ,						snake_case__		:					Optional[Any]=5    ,						snake_case__		:					List[Any]=4    ,						snake_case__		:					Dict=37    ,						snake_case__		:					Optional[int]="gelu"    ,						snake_case__		:					List[str]=0.1    ,						snake_case__		:					List[Any]=0.1    ,						snake_case__		:					Union[str, Any]=5_12    ,						snake_case__		:					Any=16    ,						snake_case__		:					str=2    ,						snake_case__		:					Optional[Any]=0.02    ,						snake_case__		:					Dict=4    ,						)		->	Dict:


          '''simple docstring'''


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



   def 				_SCREAMING_SNAKE_CASE   (self		:					Optional[int] )		->	List[str]:


          '''simple docstring'''


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

          snake_case       :   Optional[int]							=      None
          if self.use_attention_mask:
                 snake_case       :   Dict							=      random_attention_mask([self.batch_size, self.seq_length] )

          snake_case       :   Union[str, Any]							=      None
          if self.use_token_type_ids:
                 snake_case       :   str							=      ids_tensor([self.batch_size, self.seq_length]    ,						self.type_vocab_size )

          snake_case       :   List[str]							=      RobertaConfig(
              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=snake_case__    ,						initializer_range=self.initializer_range    ,						)

          return config, input_ids, token_type_ids, attention_mask



   def 				_SCREAMING_SNAKE_CASE   (self		:					Optional[Any] )		->	List[str]:


          '''simple docstring'''


          snake_case       :   Union[str, Any]							=      self.prepare_config_and_inputs()
          snake_case				,					snake_case				,					snake_case				,					snake_case       :   Union[str, Any]							=      config_and_inputs
          snake_case       :   Optional[int]							=      {"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": attention_mask}
          return config, inputs_dict



   def 				_SCREAMING_SNAKE_CASE   (self		:					Dict )		->	int:


          '''simple docstring'''


          snake_case       :   str							=      self.prepare_config_and_inputs()
          snake_case				,					snake_case				,					snake_case				,					snake_case       :   Dict							=      config_and_inputs

          snake_case       :   Any							=      True
          snake_case       :   List[Any]							=      floats_tensor([self.batch_size, self.seq_length, self.hidden_size] )
          snake_case       :   Union[str, Any]							=      ids_tensor([self.batch_size, self.seq_length]    ,						vocab_size=2 )

          return (
              config,
              input_ids,
              token_type_ids,
              encoder_hidden_states,
              encoder_attention_mask,
          )






@require_flax
class   UpperCAmelCase		(						A_       ,unittest.TestCase ):
   A__					:		List[str]						     =     True

   A__					:		Union[str, Any]						     =     (
       (
           FlaxRobertaModel,
           FlaxRobertaForCausalLM,
           FlaxRobertaForMaskedLM,
           FlaxRobertaForSequenceClassification,
           FlaxRobertaForTokenClassification,
           FlaxRobertaForMultipleChoice,
           FlaxRobertaForQuestionAnswering,
       )
       if is_flax_available()
       else ()
   )



   def 				_SCREAMING_SNAKE_CASE   (self		:					Dict )		->	Any:


          '''simple docstring'''


          snake_case       :   Tuple							=      FlaxRobertaModelTester(self )



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


          '''simple docstring'''


          for model_class_name in self.all_model_classes:
                 snake_case       :   List[str]							=      model_class_name.from_pretrained("roberta-base"    ,						from_pt=snake_case__ )
                 snake_case       :   Dict							=      model(np.ones((1, 1) ) )
                 self.assertIsNotNone(snake_case__ )







from ...configuration_utils import PretrainedConfig
from ...utils import logging


__lowerCamelCase							=       logging.get_logger(__name__)

__lowerCamelCase							=       {
    # See all MEGATRON_BERT models at https://huggingface.co/models?filter=bert
}






class   UpperCAmelCase		(						A_ ):
   A__					:		List[str]						     =     "megatron-bert"



   def __init__(self		:					Optional[int]    ,						snake_case__		:					List[str]=2_90_56    ,						snake_case__		:					List[Any]=10_24    ,						snake_case__		:					str=24    ,						snake_case__		:					Tuple=16    ,						snake_case__		:					Union[str, Any]=40_96    ,						snake_case__		:					str="gelu"    ,						snake_case__		:					str=0.1    ,						snake_case__		:					Optional[int]=0.1    ,						snake_case__		:					Tuple=5_12    ,						snake_case__		:					Union[str, Any]=2    ,						snake_case__		:					Dict=0.02    ,						snake_case__		:					List[Any]=1e-12    ,						snake_case__		:					int=0    ,						snake_case__		:					Tuple="absolute"    ,						snake_case__		:					Any=True    ,						**snake_case__		:					Union[str, Any]    ,						)		->	Optional[Any]:


          '''simple docstring'''


          super().__init__(pad_token_id=snake_case__    ,						**snake_case__ )

          snake_case       :   Tuple							=      vocab_size
          snake_case       :   str							=      hidden_size
          snake_case       :   str							=      num_hidden_layers
          snake_case       :   str							=      num_attention_heads
          snake_case       :   Optional[int]							=      hidden_act
          snake_case       :   int							=      intermediate_size
          snake_case       :   List[str]							=      hidden_dropout_prob
          snake_case       :   Union[str, Any]							=      attention_probs_dropout_prob
          snake_case       :   Dict							=      max_position_embeddings
          snake_case       :   List[str]							=      type_vocab_size
          snake_case       :   List[str]							=      initializer_range
          snake_case       :   Tuple							=      layer_norm_eps
          snake_case       :   int							=      position_embedding_type
          snake_case       :   str							=      use_cache





