


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




      '''simple docstring'''


      def __init__(							self:			List[str]		, a:			Any		, a:			Optional[int]=13		, a:			List[str]=7		, a:			Optional[int]=True		, a:			Any=True		, a:			Optional[Any]=True		, a:			int=True		, a:			Tuple=99		, a:			Union[str, Any]=32		, a:			List[Any]=5		, a:			Tuple=4		, a:			Optional[int]=37		, a:			int="gelu"		, a:			Tuple=0.1		, a:			Optional[Any]=0.1		, a:			str=512		, a:			Optional[Any]=16		, a:			int=2		, a:			Tuple=0.0_2		, a:			Dict=4		, ):
       __lowerCamelCase						:				List[str]						   =		parent
       __lowerCamelCase						:				Dict						   =		batch_size
       __lowerCamelCase						:				List[str]						   =		seq_length
       __lowerCamelCase						:				Any						   =		is_training
       __lowerCamelCase						:				List[Any]						   =		use_attention_mask
       __lowerCamelCase						:				str						   =		use_token_type_ids
       __lowerCamelCase						:				Dict						   =		use_labels
       __lowerCamelCase						:				int						   =		vocab_size
       __lowerCamelCase						:				Optional[Any]						   =		hidden_size
       __lowerCamelCase						:				Tuple						   =		num_hidden_layers
       __lowerCamelCase						:				Tuple						   =		num_attention_heads
       __lowerCamelCase						:				Dict						   =		intermediate_size
       __lowerCamelCase						:				Tuple						   =		hidden_act
       __lowerCamelCase						:				int						   =		hidden_dropout_prob
       __lowerCamelCase						:				Any						   =		attention_probs_dropout_prob
       __lowerCamelCase						:				Any						   =		max_position_embeddings
       __lowerCamelCase						:				str						   =		type_vocab_size
       __lowerCamelCase						:				Dict						   =		type_sequence_label_size
       __lowerCamelCase						:				List[Any]						   =		initializer_range
       __lowerCamelCase						:				int						   =		num_choices




      def 	_snake_case      (							self:			List[Any]							):
       __lowerCamelCase						:				Dict						   =		ids_tensor([self.batch_size, self.seq_length]		, self.vocab_size							)

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

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

       __lowerCamelCase						:				Optional[int]						   =		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=__lowerCamelCase		, initializer_range=self.initializer_range		, )

       return config, input_ids, token_type_ids, attention_mask




      def 	_snake_case      (							self:			Optional[int]							):
       __lowerCamelCase						:				Tuple						   =		self.prepare_config_and_inputs()
       __lowerCamelCase   ,	__lowerCamelCase   ,	__lowerCamelCase   ,	__lowerCamelCase						:				Optional[Any]						   =		config_and_inputs
       __lowerCamelCase						:				Optional[int]						   =		{'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': attention_mask}
       return config, inputs_dict




      def 	_snake_case      (							self:			Optional[Any]							):
       __lowerCamelCase						:				Union[str, Any]						   =		self.prepare_config_and_inputs()
       __lowerCamelCase   ,	__lowerCamelCase   ,	__lowerCamelCase   ,	__lowerCamelCase						:				List[str]						   =		config_and_inputs

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




      '''simple docstring'''


      __snake_case   			=  True

      __snake_case   			=  (
          (
              FlaxRobertaModel,
              FlaxRobertaForCausalLM,
              FlaxRobertaForMaskedLM,
              FlaxRobertaForSequenceClassification,
              FlaxRobertaForTokenClassification,
              FlaxRobertaForMultipleChoice,
              FlaxRobertaForQuestionAnswering,
          )
          if is_flax_available()
          else ()
      )




      def 	_snake_case      (							self:			Tuple							):
       __lowerCamelCase						:				int						   =		FlaxRobertaModelTester(self							)




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








from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_torch_available,
)


a__: str							   =						{
    'configuration_mega': ['MEGA_PRETRAINED_CONFIG_ARCHIVE_MAP', 'MegaConfig', 'MegaOnnxConfig'],
}

try:
       if not is_torch_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       a__: Union[str, Any]							   =						[
           'MEGA_PRETRAINED_MODEL_ARCHIVE_LIST',
           'MegaForCausalLM',
           'MegaForMaskedLM',
           'MegaForMultipleChoice',
           'MegaForQuestionAnswering',
           'MegaForSequenceClassification',
           'MegaForTokenClassification',
           'MegaModel',
           'MegaPreTrainedModel',
       ]

if TYPE_CHECKING:
       from .configuration_mega import MEGA_PRETRAINED_CONFIG_ARCHIVE_MAP, MegaConfig, MegaOnnxConfig

       try:
              if not is_torch_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_mega import (
                  MEGA_PRETRAINED_MODEL_ARCHIVE_LIST,
                  MegaForCausalLM,
                  MegaForMaskedLM,
                  MegaForMultipleChoice,
                  MegaForQuestionAnswering,
                  MegaForSequenceClassification,
                  MegaForTokenClassification,
                  MegaModel,
                  MegaPreTrainedModel,
              )

else:
       import sys

       a__: Union[str, Any]							   =						_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)





