


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


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







     '''simple docstring'''







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


  def 							_lowercase					(			self:						str    ):







     '''simple docstring'''







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

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

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

     _lowerCamelCase   :				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=__lowerCAmelCase							,initializer_range=self.initializer_range							,)

     return config, input_ids, token_type_ids, attention_mask


  def 							_lowercase					(			self:						Optional[int]    ):







     '''simple docstring'''







     _lowerCamelCase   :				Dict							=     self.prepare_config_and_inputs()
     _lowerCamelCase,					_lowerCamelCase,					_lowerCamelCase,					_lowerCamelCase   :				str							=     config_and_inputs
     _lowerCamelCase   :				Any							=     {"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": attention_mask}
     return config, inputs_dict






  def 							_lowercase					(			self:						List[str]    ):







     '''simple docstring'''







     _lowerCamelCase   :				Dict							=     self.prepare_config_and_inputs()
     _lowerCamelCase,					_lowerCamelCase,					_lowerCamelCase,					_lowerCamelCase   :				List[str]							=     config_and_inputs

     _lowerCamelCase   :				int							=     True
     _lowerCamelCase   :				Optional[int]							=     floats_tensor([self.batch_size, self.seq_length, self.hidden_size]    )
     _lowerCamelCase   :				Dict							=     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_      (       _a     ,	unittest.TestCase ):
  lowerCAmelCase__      			=	True

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


  def 							_lowercase					(			self:						Dict    ):







     '''simple docstring'''







     _lowerCamelCase   :				Optional[int]							=     FlaxRobertaModelTester(self    )






  @slow
  def 							_lowercase					(			self:						Optional[Any]    ):







     '''simple docstring'''







     for model_class_name in self.all_model_classes:
        _lowerCamelCase   :				List[Any]							=     model_class_name.from_pretrained("roberta-base"							,from_pt=__lowerCAmelCase    )
        _lowerCamelCase   :				int							=     model(np.ones((1, 1)    )    )
        self.assertIsNotNone(__lowerCAmelCase    )



from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


__UpperCamelCase     		=							{
    'configuration_xlm_roberta_xl': [
        'XLM_ROBERTA_XL_PRETRAINED_CONFIG_ARCHIVE_MAP',
        'XLMRobertaXLConfig',
        'XLMRobertaXLOnnxConfig',
    ],
}

try:
						if not is_torch_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						__UpperCamelCase     		=							[
						    'XLM_ROBERTA_XL_PRETRAINED_MODEL_ARCHIVE_LIST',
						    'XLMRobertaXLForCausalLM',
						    'XLMRobertaXLForMaskedLM',
						    'XLMRobertaXLForMultipleChoice',
						    'XLMRobertaXLForQuestionAnswering',
						    'XLMRobertaXLForSequenceClassification',
						    'XLMRobertaXLForTokenClassification',
						    'XLMRobertaXLModel',
						    'XLMRobertaXLPreTrainedModel',
						]

if TYPE_CHECKING:
						from .configuration_xlm_roberta_xl import (
						    XLM_ROBERTA_XL_PRETRAINED_CONFIG_ARCHIVE_MAP,
						    XLMRobertaXLConfig,
						    XLMRobertaXLOnnxConfig,
						)

						try:
												if not is_torch_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_xlm_roberta_xl import (
												    XLM_ROBERTA_XL_PRETRAINED_MODEL_ARCHIVE_LIST,
												    XLMRobertaXLForCausalLM,
												    XLMRobertaXLForMaskedLM,
												    XLMRobertaXLForMultipleChoice,
												    XLMRobertaXLForQuestionAnswering,
												    XLMRobertaXLForSequenceClassification,
												    XLMRobertaXLForTokenClassification,
												    XLMRobertaXLModel,
												    XLMRobertaXLPreTrainedModel,
												)

else:
						import sys

						__UpperCamelCase     		=							_LazyModule(__name__, globals()['__file__'], _import_structure)


