


'''simple docstring'''



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





    """simple docstring"""






    def __init__(							self			,     SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_=13			,     SCREAMING_SNAKE_CASE_=7			,     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_=5			,     SCREAMING_SNAKE_CASE_=4			,     SCREAMING_SNAKE_CASE_=37			,     SCREAMING_SNAKE_CASE_="gelu"			,     SCREAMING_SNAKE_CASE_=0.1			,     SCREAMING_SNAKE_CASE_=0.1			,     SCREAMING_SNAKE_CASE_=5_12			,     SCREAMING_SNAKE_CASE_=16			,     SCREAMING_SNAKE_CASE_=2			,     SCREAMING_SNAKE_CASE_=0.0_2			,     SCREAMING_SNAKE_CASE_=4			,     )				->     Optional[Any]:
         __lowerCamelCase   :	List[Any]								=		parent
         __lowerCamelCase   :	Optional[int]								=		batch_size
         __lowerCamelCase   :	Union[str, Any]								=		seq_length
         __lowerCamelCase   :	List[str]								=		is_training
         __lowerCamelCase   :	List[str]								=		use_attention_mask
         __lowerCamelCase   :	Union[str, Any]								=		use_token_type_ids
         __lowerCamelCase   :	Dict								=		use_labels
         __lowerCamelCase   :	Tuple								=		vocab_size
         __lowerCamelCase   :	Optional[int]								=		hidden_size
         __lowerCamelCase   :	Any								=		num_hidden_layers
         __lowerCamelCase   :	str								=		num_attention_heads
         __lowerCamelCase   :	List[str]								=		intermediate_size
         __lowerCamelCase   :	Union[str, Any]								=		hidden_act
         __lowerCamelCase   :	int								=		hidden_dropout_prob
         __lowerCamelCase   :	Any								=		attention_probs_dropout_prob
         __lowerCamelCase   :	Tuple								=		max_position_embeddings
         __lowerCamelCase   :	Any								=		type_vocab_size
         __lowerCamelCase   :	Union[str, Any]								=		type_sequence_label_size
         __lowerCamelCase   :	Tuple								=		initializer_range
         __lowerCamelCase   :	Optional[Any]								=		num_choices







    def       lowercase_				(							self	)				->     Optional[int]:
         __lowerCamelCase   :	str								=		ids_tensor([self.batch_size, self.seq_length]			,     self.vocab_size	)

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

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

         __lowerCamelCase   :	List[Any]								=		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=SCREAMING_SNAKE_CASE_			,     initializer_range=self.initializer_range			,     )

         return config, input_ids, token_type_ids, attention_mask







    def       lowercase_				(							self	)				->     Any:
         __lowerCamelCase   :	str								=		self.prepare_config_and_inputs()
         __lowerCamelCase				,       __lowerCamelCase				,       __lowerCamelCase				,       __lowerCamelCase   :	str								=		config_and_inputs
         __lowerCamelCase   :	Optional[Any]								=		{'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': attention_mask}
         return config, inputs_dict







    def       lowercase_				(							self	)				->     Any:
         __lowerCamelCase   :	str								=		self.prepare_config_and_inputs()
         __lowerCamelCase				,       __lowerCamelCase				,       __lowerCamelCase				,       __lowerCamelCase   :	List[str]								=		config_and_inputs

         __lowerCamelCase   :	str								=		True
         __lowerCamelCase   :	Optional[int]								=		floats_tensor([self.batch_size, self.seq_length, self.hidden_size]	)
         __lowerCamelCase   :	Optional[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_  (_UpperCAmelCase					,		unittest.TestCase  ):





    """simple docstring"""






    lowerCamelCase  :					Dict							     =			True

    lowerCamelCase  :					Dict							     =			(
        (
            FlaxRobertaModel,
            FlaxRobertaForCausalLM,
            FlaxRobertaForMaskedLM,
            FlaxRobertaForSequenceClassification,
            FlaxRobertaForTokenClassification,
            FlaxRobertaForMultipleChoice,
            FlaxRobertaForQuestionAnswering,
        )
        if is_flax_available()
        else ()
    )







    def       lowercase_				(							self	)				->     Tuple:
         __lowerCamelCase   :	Optional[int]								=		FlaxRobertaModelTester(self	)







    @slow
    def       lowercase_				(							self	)				->     int:
         for model_class_name in self.all_model_classes:
              __lowerCamelCase   :	List[str]								=		model_class_name.from_pretrained('roberta-base'			,     from_pt=SCREAMING_SNAKE_CASE_	)
              __lowerCamelCase   :	Union[str, Any]								=		model(np.ones((1, 1)	)	)
              self.assertIsNotNone(SCREAMING_SNAKE_CASE_	)










'''simple docstring'''



from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


A__		:					List[Any]												=  {
    """configuration_megatron_bert""": ["""MEGATRON_BERT_PRETRAINED_CONFIG_ARCHIVE_MAP""", """MegatronBertConfig"""],
}

try:
      if not is_torch_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      A__		:					int												=  [
          """MEGATRON_BERT_PRETRAINED_MODEL_ARCHIVE_LIST""",
          """MegatronBertForCausalLM""",
          """MegatronBertForMaskedLM""",
          """MegatronBertForMultipleChoice""",
          """MegatronBertForNextSentencePrediction""",
          """MegatronBertForPreTraining""",
          """MegatronBertForQuestionAnswering""",
          """MegatronBertForSequenceClassification""",
          """MegatronBertForTokenClassification""",
          """MegatronBertModel""",
          """MegatronBertPreTrainedModel""",
      ]

if TYPE_CHECKING:
      from .configuration_megatron_bert import MEGATRON_BERT_PRETRAINED_CONFIG_ARCHIVE_MAP, MegatronBertConfig

      try:
            if not is_torch_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_megatron_bert import (
                MEGATRON_BERT_PRETRAINED_MODEL_ARCHIVE_LIST,
                MegatronBertForCausalLM,
                MegatronBertForMaskedLM,
                MegatronBertForMultipleChoice,
                MegatronBertForNextSentencePrediction,
                MegatronBertForPreTraining,
                MegatronBertForQuestionAnswering,
                MegatronBertForSequenceClassification,
                MegatronBertForTokenClassification,
                MegatronBertModel,
                MegatronBertPreTrainedModel,
            )

else:
      import sys

      A__		:					List[Any]												=  _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)






