




'''simple docstring'''







import unittest

from transformers import MobileBertConfig, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
    import torch

    from transformers import (
        MODEL_FOR_PRETRAINING_MAPPING,
        MobileBertForMaskedLM,
        MobileBertForMultipleChoice,
        MobileBertForNextSentencePrediction,
        MobileBertForPreTraining,
        MobileBertForQuestionAnswering,
        MobileBertForSequenceClassification,
        MobileBertForTokenClassification,
        MobileBertModel,
    )

class 	_snake_case:






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






    """simple docstring"""


    A__       =     parent
    A__       =     batch_size
    A__       =     seq_length
    A__       =     is_training
    A__       =     use_input_mask
    A__       =     use_token_type_ids
    A__       =     use_labels
    A__       =     vocab_size
    A__       =     hidden_size
    A__       =     embedding_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_labels
    A__       =     num_choices
    A__       =     scope






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






    """simple docstring"""


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

    A__       =     None
    if self.use_input_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__       =     None
    A__       =     None
    A__       =     None
    if self.use_labels:
       A__       =     ids_tensor([self.batch_size]    ,		self.type_sequence_label_size    )
       A__       =     ids_tensor([self.batch_size, self.seq_length]    ,		self.num_labels    )
       A__       =     ids_tensor([self.batch_size]    ,		self.num_choices    )

    A__       =     self.get_config()

    return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels






 def 						_UpperCamelCase (self       :  Any    )       ->   Optional[int]:






    """simple docstring"""


    return MobileBertConfig(
        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    ,		embedding_size=self.embedding_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=a    ,		initializer_range=self.initializer_range    ,		)






 def 						_UpperCamelCase (self       :  List[Any]    ,		a       :  Union[str, Any]    ,		a       :  Optional[Any]    ,		a       :  str    ,		a       :  int    ,		a       :  Union[str, Any]    ,		a       :  Dict    ,		a       :  Dict    )       ->   Union[str, Any]:






    """simple docstring"""


    A__       =     MobileBertModel(config=a    )
    model.to(a    )
    model.eval()
    A__       =     model(a    ,		attention_mask=a    ,		token_type_ids=a    )
    A__       =     model(a    ,		token_type_ids=a    )
    A__       =     model(a    )

    self.parent.assertEqual(result.last_hidden_state.shape    ,		(self.batch_size, self.seq_length, self.hidden_size)    )
    self.parent.assertEqual(result.pooler_output.shape    ,		(self.batch_size, self.hidden_size)    )






 def 						_UpperCamelCase (self       :  str    ,		a       :  str    ,		a       :  Any    ,		a       :  Optional[Any]    ,		a       :  List[str]    ,		a       :  int    ,		a       :  str    ,		a       :  Optional[Any]    )       ->   Any:






    """simple docstring"""


    A__       =     MobileBertForMaskedLM(config=a    )
    model.to(a    )
    model.eval()
    A__       =     model(a    ,		attention_mask=a    ,		token_type_ids=a    ,		labels=a    )
    self.parent.assertEqual(result.logits.shape    ,		(self.batch_size, self.seq_length, self.vocab_size)    )






 def 						_UpperCamelCase (self       :  List[Any]    ,		a       :  Optional[int]    ,		a       :  List[Any]    ,		a       :  Union[str, Any]    ,		a       :  Optional[int]    ,		a       :  List[Any]    ,		a       :  Optional[Any]    ,		a       :  Union[str, Any]    )       ->   List[str]:






    """simple docstring"""


    A__       =     MobileBertForNextSentencePrediction(config=a    )
    model.to(a    )
    model.eval()
    A__       =     model(
        a    ,		attention_mask=a    ,		token_type_ids=a    ,		labels=a    ,		)
    self.parent.assertEqual(result.logits.shape    ,		(self.batch_size, 2)    )






 def 						_UpperCamelCase (self       :  Dict    ,		a       :  int    ,		a       :  Union[str, Any]    ,		a       :  List[Any]    ,		a       :  Dict    ,		a       :  Optional[int]    ,		a       :  Optional[int]    ,		a       :  List[str]    )       ->   Optional[Any]:






    """simple docstring"""


    A__       =     MobileBertForPreTraining(config=a    )
    model.to(a    )
    model.eval()
    A__       =     model(
        a    ,		attention_mask=a    ,		token_type_ids=a    ,		labels=a    ,		next_sentence_label=a    ,		)
    self.parent.assertEqual(result.prediction_logits.shape    ,		(self.batch_size, self.seq_length, self.vocab_size)    )
    self.parent.assertEqual(result.seq_relationship_logits.shape    ,		(self.batch_size, 2)    )






 def 						_UpperCamelCase (self       :  List[str]    ,		a       :  Optional[int]    ,		a       :  str    ,		a       :  Any    ,		a       :  str    ,		a       :  int    ,		a       :  List[str]    ,		a       :  Tuple    )       ->   Tuple:






    """simple docstring"""


    A__       =     MobileBertForQuestionAnswering(config=a    )
    model.to(a    )
    model.eval()
    A__       =     model(
        a    ,		attention_mask=a    ,		token_type_ids=a    ,		start_positions=a    ,		end_positions=a    ,		)
    self.parent.assertEqual(result.start_logits.shape    ,		(self.batch_size, self.seq_length)    )
    self.parent.assertEqual(result.end_logits.shape    ,		(self.batch_size, self.seq_length)    )






 def 						_UpperCamelCase (self       :  int    ,		a       :  Union[str, Any]    ,		a       :  int    ,		a       :  Optional[Any]    ,		a       :  List[Any]    ,		a       :  Optional[Any]    ,		a       :  Tuple    ,		a       :  str    )       ->   Optional[int]:






    """simple docstring"""


    A__       =     self.num_labels
    A__       =     MobileBertForSequenceClassification(a    )
    model.to(a    )
    model.eval()
    A__       =     model(a    ,		attention_mask=a    ,		token_type_ids=a    ,		labels=a    )
    self.parent.assertEqual(result.logits.shape    ,		(self.batch_size, self.num_labels)    )






 def 						_UpperCamelCase (self       :  Optional[Any]    ,		a       :  int    ,		a       :  Dict    ,		a       :  str    ,		a       :  Dict    ,		a       :  Dict    ,		a       :  List[Any]    ,		a       :  str    )       ->   Optional[Any]:






    """simple docstring"""


    A__       =     self.num_labels
    A__       =     MobileBertForTokenClassification(config=a    )
    model.to(a    )
    model.eval()
    A__       =     model(a    ,		attention_mask=a    ,		token_type_ids=a    ,		labels=a    )
    self.parent.assertEqual(result.logits.shape    ,		(self.batch_size, self.seq_length, self.num_labels)    )






 def 						_UpperCamelCase (self       :  Union[str, Any]    ,		a       :  List[str]    ,		a       :  List[Any]    ,		a       :  List[Any]    ,		a       :  Any    ,		a       :  Dict    ,		a       :  Optional[Any]    ,		a       :  List[Any]    )       ->   int:






    """simple docstring"""


    A__       =     self.num_choices
    A__       =     MobileBertForMultipleChoice(config=a    )
    model.to(a    )
    model.eval()
    A__       =     input_ids.unsqueeze(1    ).expand(-1    ,		self.num_choices    ,		-1    ).contiguous()
    A__       =     token_type_ids.unsqueeze(1    ).expand(-1    ,		self.num_choices    ,		-1    ).contiguous()
    A__       =     input_mask.unsqueeze(1    ).expand(-1    ,		self.num_choices    ,		-1    ).contiguous()
    A__       =     model(
        a    ,		attention_mask=a    ,		token_type_ids=a    ,		labels=a    ,		)
    self.parent.assertEqual(result.logits.shape    ,		(self.batch_size, self.num_choices)    )






 def 						_UpperCamelCase (self       :  Optional[int]    )       ->   Optional[int]:






    """simple docstring"""


    A__       =     self.prepare_config_and_inputs()
    (
        (
        A__
    )  ,			(
        A__
    )  ,			(
        A__
    )  ,			(
        A__
    )  ,			(
        A__
    )  ,			(
        A__
    )  ,			(
        A__
    )  ,			
    )       =     config_and_inputs
    A__       =     {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
    return config, inputs_dict




@require_torch
class 	_snake_case(			UpperCAmelCase       , UpperCAmelCase       , unittest.TestCase      ):
 __snake_case:							Union[str, Any]						=					(
     (
         MobileBertModel,
         MobileBertForMaskedLM,
         MobileBertForMultipleChoice,
         MobileBertForNextSentencePrediction,
         MobileBertForPreTraining,
         MobileBertForQuestionAnswering,
         MobileBertForSequenceClassification,
         MobileBertForTokenClassification,
     )
     if is_torch_available()
     else ()
 )
 __snake_case:							Tuple						=					(
     {
         '''feature-extraction''': MobileBertModel,
         '''fill-mask''': MobileBertForMaskedLM,
         '''question-answering''': MobileBertForQuestionAnswering,
         '''text-classification''': MobileBertForSequenceClassification,
         '''token-classification''': MobileBertForTokenClassification,
         '''zero-shot''': MobileBertForSequenceClassification,
     }
     if is_torch_available()
     else {}
 )
 __snake_case:							Union[str, Any]						=					True






 def 						_UpperCamelCase (self       :  Any    ,		a       :  Optional[Any]    ,		a       :  str    ,		a       :  Optional[Any]=False    )       ->   Tuple:






    """simple docstring"""


    A__       =     super()._prepare_for_class(a    ,		a    ,		return_labels=a    )

    if return_labels:
       if model_class in get_values(a    ):
          A__       =     torch.zeros(
              (self.model_tester.batch_size, self.model_tester.seq_length)    ,		dtype=torch.long    ,		device=a    )
          A__       =     torch.zeros(
              self.model_tester.batch_size    ,		dtype=torch.long    ,		device=a    )
    return inputs_dict






 def 						_UpperCamelCase (self       :  Optional[Any]    )       ->   Optional[Any]:






    """simple docstring"""


    A__       =     MobileBertModelTester(self    )
    A__       =     ConfigTester(self    ,		config_class=a    ,		hidden_size=37    )






 def 						_UpperCamelCase (self       :  List[Any]    )       ->   Tuple:






    """simple docstring"""


    self.config_tester.run_common_tests()






 def 						_UpperCamelCase (self       :  Union[str, Any]    )       ->   Dict:






    """simple docstring"""


    A__       =     self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_mobilebert_model(*a    )






 def 						_UpperCamelCase (self       :  int    )       ->   Any:






    """simple docstring"""


    A__       =     self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_mobilebert_for_masked_lm(*a    )






 def 						_UpperCamelCase (self       :  Dict    )       ->   Dict:






    """simple docstring"""


    A__       =     self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_mobilebert_for_multiple_choice(*a    )






 def 						_UpperCamelCase (self       :  int    )       ->   List[Any]:






    """simple docstring"""


    A__       =     self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_mobilebert_for_next_sequence_prediction(*a    )






 def 						_UpperCamelCase (self       :  List[Any]    )       ->   Union[str, Any]:






    """simple docstring"""


    A__       =     self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_mobilebert_for_pretraining(*a    )






 def 						_UpperCamelCase (self       :  Optional[Any]    )       ->   int:






    """simple docstring"""


    A__       =     self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_mobilebert_for_question_answering(*a    )






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






    """simple docstring"""


    A__       =     self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_mobilebert_for_sequence_classification(*a    )






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






    """simple docstring"""


    A__       =     self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_mobilebert_for_token_classification(*a    )







def 						_A      ( UpperCAmelCase						):






   '''simple docstring'''







   return torch.tensor(
       UpperCAmelCase      ,dtype=torch.long      ,device=UpperCAmelCase      ,)


lowerCAmelCase_     						=				1e-3







@require_torch
@require_sentencepiece
@require_tokenizers
class 	_snake_case(			unittest.TestCase      ):






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






    """simple docstring"""


    A__       =     MobileBertModel.from_pretrained('google/mobilebert-uncased'    ).to(a    )
    A__       =     _long_tensor([[1_01, 71_10, 10_05, 10_56, 20_23, 1_13_33, 1_74_13, 10_29, 1_02]]    )
    with torch.no_grad():
       A__       =     model(a    )[0]
    A__       =     torch.Size((1, 9, 5_12)    )
    self.assertEqual(output.shape    ,		a    )
    A__       =     torch.tensor(
        [
            [
                [-2.473_6526e07, 8.269_1656e04, 1.652_1838e05],
                [-5.754_1704e-01, 3.905_6022e00, 4.401_1507e00],
                [2.604_7359e00, 1.567_7652e00, -1.732_4188e-01],
            ]
        ]    ,		device=a    ,		)

    # MobileBERT results range from 10e0 to 10e8. Even a 0.0000001% difference with a value of 10e8 results in a
    # ~1 difference, it's therefore not a good idea to measure using addition.
    # Here, we instead divide the expected result with the result in order to obtain ~1. We then check that the
    # result is held between bounds: 1 - TOLERANCE < expected_result / result < 1 + TOLERANCE
    A__       =     torch.all((expected_slice / output[..., :3, :3]) >= 1 - TOLERANCE    )
    A__       =     torch.all((expected_slice / output[..., :3, :3]) <= 1 + TOLERANCE    )

    self.assertTrue(lower_bound and upper_bound    )








'''simple docstring'''







def 						_A      ( ):






   '''simple docstring'''







   A__       =     [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

   A__       =     6
   A__       =     1
   A__       =     1901

   A__       =     0

   while year < 2001:
      day += 7

      if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
         if day > days_per_month[month - 1] and month != 2:
            month += 1
            A__       =     day - days_per_month[month - 2]
         elif day > 29 and month == 2:
            month += 1
            A__       =     day - 29
      else:
         if day > days_per_month[month - 1]:
            month += 1
            A__       =     day - days_per_month[month - 2]

      if month > 12:
         year += 1
         A__       =     1

      if year < 2001 and day == 1:
         sundays += 1
   return sundays


if __name__ == "__main__":
    print(solution())


