



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

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


    """simple docstring"""






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

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


    """simple docstring"""






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

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

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

    a						=		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 		A							(      self			:       Dict							)       ->				Optional[int]:


    """simple docstring"""






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




   def 		A							(      self			:       Tuple							)       ->				Union[str, Any]:


    """simple docstring"""






    a						=		self.prepare_config_and_inputs()
    a		,  a		,  a		,  a						=		config_and_inputs

    a						=		True
    a						=		floats_tensor([self.batch_size, self.seq_length, self.hidden_size]							)
    a						=		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 		_lowercase		(       UpperCAmelCase__,   unittest.TestCase	):
   _UpperCAmelCase     	=			True

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

   def 		A							(      self			:       Tuple							)       ->				str:


    """simple docstring"""






    a						=		FlaxRobertaModelTester(self							)




   @slow
   def 		A							(      self			:       Dict							)       ->				Any:


    """simple docstring"""






    for model_class_name in self.all_model_classes:
     a						=		model_class_name.from_pretrained("roberta-base"							,   from_pt=__lowerCAmelCase							)
     a						=		model(np.ones((1, 1)							)							)
     self.assertIsNotNone(__lowerCAmelCase							)






A_		:     Any        =     [4, 1, 7, 4, 2, 6, 4, 1, 5, 3, 7, 5]
A_		:     Tuple        =     [3, 7, 7, 4, 2, 6, 4, 1, 5, 3, 7, 5]
A_		:     Optional[int]        =     {
    0: '''Sunday''',
    1: '''Monday''',
    2: '''Tuesday''',
    3: '''Wednesday''',
    4: '''Thursday''',
    5: '''Friday''',
    6: '''Saturday''',
}


def 	UpperCAmelCase__      (      UpperCAmelCase__ :int ,					UpperCAmelCase__ :int ,					UpperCAmelCase__ :int					):






 '''simple docstring'''

 assert len(str(UpperCAmelCase__					)					) > 2, "year should be in YYYY format"
 assert 1 <= month <= 12, "month should be between 1 to 12"
 assert 1 <= day <= 31, "day should be between 1 to 31"

 # Doomsday algorithm:
 a						=		year // 1_00
 a						=		(5 * (century % 4) + 2) % 7
 a						=		year % 1_00
 a						=		centurian % 12
 a						=		(
     (centurian // 12) + centurian_m + (centurian_m // 4) + century_anchor
 ) % 7
 a						=		(
     DOOMSDAY_NOT_LEAP[month - 1]
     if (year % 4 != 0) or (centurian == 0 and (year % 4_00) == 0)
     else DOOMSDAY_LEAP[month - 1]
 )
 a						=		(dooms_day + day - day_anchor) % 7
 return WEEK_DAY_NAMES[week_day]


if __name__ == "__main__":
     import doctest

     doctest.testmod()

