


import unittest

from transformers import AlbertConfig, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import 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,
        AlbertForMaskedLM,
        AlbertForMultipleChoice,
        AlbertForPreTraining,
        AlbertForQuestionAnswering,
        AlbertForSequenceClassification,
        AlbertForTokenClassification,
        AlbertModel,
    )
    from transformers.models.albert.modeling_albert import ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST



class 							_UpperCamelCase :

   '''simple docstring'''







   def __init__(  self  : Optional[Any]       ,  _lowerCamelCase  : Union[str, Any]       ,  _lowerCamelCase  : Dict=1_3       ,  _lowerCamelCase  : Dict=7       ,  _lowerCamelCase  : str=True       ,  _lowerCamelCase  : int=True       ,  _lowerCamelCase  : Any=True       ,  _lowerCamelCase  : Optional[int]=True       ,  _lowerCamelCase  : List[Any]=9_9       ,  _lowerCamelCase  : Union[str, Any]=1_6       ,  _lowerCamelCase  : Optional[int]=3_6       ,  _lowerCamelCase  : Union[str, Any]=6       ,  _lowerCamelCase  : str=6       ,  _lowerCamelCase  : Any=6       ,  _lowerCamelCase  : Optional[Any]=3_7       ,  _lowerCamelCase  : Optional[Any]="gelu"       ,  _lowerCamelCase  : Any=0.1       ,  _lowerCamelCase  : Union[str, Any]=0.1       ,  _lowerCamelCase  : Optional[int]=5_1_2       ,  _lowerCamelCase  : Tuple=1_6       ,  _lowerCamelCase  : Optional[int]=2       ,  _lowerCamelCase  : str=0.02       ,  _lowerCamelCase  : List[str]=3       ,  _lowerCamelCase  : str=4       ,  _lowerCamelCase  : Optional[int]=None       ,  ):






         '''simple docstring'''



         __lowerCamelCase     :      Tuple       						=						parent
         __lowerCamelCase     :      str       						=						batch_size
         __lowerCamelCase     :      List[Any]       						=						seq_length
         __lowerCamelCase     :      str       						=						is_training
         __lowerCamelCase     :      Tuple       						=						use_input_mask
         __lowerCamelCase     :      Dict       						=						use_token_type_ids
         __lowerCamelCase     :      Optional[Any]       						=						use_labels
         __lowerCamelCase     :      List[Any]       						=						vocab_size
         __lowerCamelCase     :      List[Any]       						=						embedding_size
         __lowerCamelCase     :      Optional[Any]       						=						hidden_size
         __lowerCamelCase     :      Tuple       						=						num_hidden_layers
         __lowerCamelCase     :      Optional[int]       						=						num_hidden_groups
         __lowerCamelCase     :      Any       						=						num_attention_heads
         __lowerCamelCase     :      Optional[int]       						=						intermediate_size
         __lowerCamelCase     :      Optional[Any]       						=						hidden_act
         __lowerCamelCase     :      Optional[int]       						=						hidden_dropout_prob
         __lowerCamelCase     :      Union[str, Any]       						=						attention_probs_dropout_prob
         __lowerCamelCase     :      List[Any]       						=						max_position_embeddings
         __lowerCamelCase     :      int       						=						type_vocab_size
         __lowerCamelCase     :      List[Any]       						=						type_sequence_label_size
         __lowerCamelCase     :      Optional[Any]       						=						initializer_range
         __lowerCamelCase     :      str       						=						num_labels
         __lowerCamelCase     :      Union[str, Any]       						=						num_choices
         __lowerCamelCase     :      Dict       						=						scope

   def   _snake_case    (  self  : Union[str, Any]							):






         '''simple docstring'''



         __lowerCamelCase     :      Tuple       						=						ids_tensor([self.batch_size, self.seq_length]       ,  self.vocab_size							)

         __lowerCamelCase     :      str       						=						None
         if self.use_input_mask:
               __lowerCamelCase     :      Dict       						=						random_attention_mask([self.batch_size, self.seq_length]							)

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

         __lowerCamelCase     :      Optional[Any]       						=						None
         __lowerCamelCase     :      Any       						=						None
         __lowerCamelCase     :      List[str]       						=						None
         if self.use_labels:
               __lowerCamelCase     :      Any       						=						ids_tensor([self.batch_size]       ,  self.type_sequence_label_size							)
               __lowerCamelCase     :      str       						=						ids_tensor([self.batch_size, self.seq_length]       ,  self.num_labels							)
               __lowerCamelCase     :      Tuple       						=						ids_tensor([self.batch_size]       ,  self.num_choices							)

         __lowerCamelCase     :      Optional[int]       						=						self.get_config()

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

   def   _snake_case    (  self  : int							):






         '''simple docstring'''



         return AlbertConfig(
             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       ,  initializer_range=self.initializer_range       ,  num_hidden_groups=self.num_hidden_groups       ,  )

   def   _snake_case    (  self  : Optional[Any]       ,  _lowerCamelCase  : Any       ,  _lowerCamelCase  : int       ,  _lowerCamelCase  : List[str]       ,  _lowerCamelCase  : Union[str, Any]       ,  _lowerCamelCase  : int       ,  _lowerCamelCase  : List[Any]       ,  _lowerCamelCase  : Any							):






         '''simple docstring'''



         __lowerCamelCase     :      Union[str, Any]       						=						AlbertModel(config=_lowerCamelCase							)
         model.to(_lowerCamelCase							)
         model.eval()
         __lowerCamelCase     :      List[str]       						=						model(_lowerCamelCase       ,  attention_mask=_lowerCamelCase       ,  token_type_ids=_lowerCamelCase							)
         __lowerCamelCase     :      int       						=						model(_lowerCamelCase       ,  token_type_ids=_lowerCamelCase							)
         __lowerCamelCase     :      str       						=						model(_lowerCamelCase							)
         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   _snake_case    (  self  : int       ,  _lowerCamelCase  : Any       ,  _lowerCamelCase  : Tuple       ,  _lowerCamelCase  : Dict       ,  _lowerCamelCase  : Any       ,  _lowerCamelCase  : Optional[int]       ,  _lowerCamelCase  : Optional[int]       ,  _lowerCamelCase  : List[Any]							):






         '''simple docstring'''



         __lowerCamelCase     :      Dict       						=						AlbertForPreTraining(config=_lowerCamelCase							)
         model.to(_lowerCamelCase							)
         model.eval()
         __lowerCamelCase     :      Optional[Any]       						=						model(
             _lowerCamelCase       ,  attention_mask=_lowerCamelCase       ,  token_type_ids=_lowerCamelCase       ,  labels=_lowerCamelCase       ,  sentence_order_label=_lowerCamelCase       ,  )
         self.parent.assertEqual(result.prediction_logits.shape       ,  (self.batch_size, self.seq_length, self.vocab_size)							)
         self.parent.assertEqual(result.sop_logits.shape       ,  (self.batch_size, config.num_labels)							)

   def   _snake_case    (  self  : Tuple       ,  _lowerCamelCase  : Tuple       ,  _lowerCamelCase  : Optional[int]       ,  _lowerCamelCase  : List[str]       ,  _lowerCamelCase  : Tuple       ,  _lowerCamelCase  : List[Any]       ,  _lowerCamelCase  : Union[str, Any]       ,  _lowerCamelCase  : Optional[int]							):






         '''simple docstring'''



         __lowerCamelCase     :      List[Any]       						=						AlbertForMaskedLM(config=_lowerCamelCase							)
         model.to(_lowerCamelCase							)
         model.eval()
         __lowerCamelCase     :      Union[str, Any]       						=						model(_lowerCamelCase       ,  attention_mask=_lowerCamelCase       ,  token_type_ids=_lowerCamelCase       ,  labels=_lowerCamelCase							)
         self.parent.assertEqual(result.logits.shape       ,  (self.batch_size, self.seq_length, self.vocab_size)							)

   def   _snake_case    (  self  : Optional[int]       ,  _lowerCamelCase  : int       ,  _lowerCamelCase  : Tuple       ,  _lowerCamelCase  : Dict       ,  _lowerCamelCase  : Optional[Any]       ,  _lowerCamelCase  : Union[str, Any]       ,  _lowerCamelCase  : Dict       ,  _lowerCamelCase  : List[str]							):






         '''simple docstring'''



         __lowerCamelCase     :      Dict       						=						AlbertForQuestionAnswering(config=_lowerCamelCase							)
         model.to(_lowerCamelCase							)
         model.eval()
         __lowerCamelCase     :      Dict       						=						model(
             _lowerCamelCase       ,  attention_mask=_lowerCamelCase       ,  token_type_ids=_lowerCamelCase       ,  start_positions=_lowerCamelCase       ,  end_positions=_lowerCamelCase       ,  )
         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   _snake_case    (  self  : str       ,  _lowerCamelCase  : Optional[Any]       ,  _lowerCamelCase  : str       ,  _lowerCamelCase  : Dict       ,  _lowerCamelCase  : Optional[int]       ,  _lowerCamelCase  : Optional[int]       ,  _lowerCamelCase  : int       ,  _lowerCamelCase  : Optional[int]							):






         '''simple docstring'''



         __lowerCamelCase     :      Tuple       						=						self.num_labels
         __lowerCamelCase     :      int       						=						AlbertForSequenceClassification(_lowerCamelCase							)
         model.to(_lowerCamelCase							)
         model.eval()
         __lowerCamelCase     :      Optional[int]       						=						model(_lowerCamelCase       ,  attention_mask=_lowerCamelCase       ,  token_type_ids=_lowerCamelCase       ,  labels=_lowerCamelCase							)
         self.parent.assertEqual(result.logits.shape       ,  (self.batch_size, self.num_labels)							)

   def   _snake_case    (  self  : List[str]       ,  _lowerCamelCase  : str       ,  _lowerCamelCase  : Any       ,  _lowerCamelCase  : Any       ,  _lowerCamelCase  : Optional[Any]       ,  _lowerCamelCase  : List[str]       ,  _lowerCamelCase  : int       ,  _lowerCamelCase  : List[str]							):






         '''simple docstring'''



         __lowerCamelCase     :      Dict       						=						self.num_labels
         __lowerCamelCase     :      Tuple       						=						AlbertForTokenClassification(config=_lowerCamelCase							)
         model.to(_lowerCamelCase							)
         model.eval()
         __lowerCamelCase     :      Dict       						=						model(_lowerCamelCase       ,  attention_mask=_lowerCamelCase       ,  token_type_ids=_lowerCamelCase       ,  labels=_lowerCamelCase							)
         self.parent.assertEqual(result.logits.shape       ,  (self.batch_size, self.seq_length, self.num_labels)							)

   def   _snake_case    (  self  : Any       ,  _lowerCamelCase  : str       ,  _lowerCamelCase  : Union[str, Any]       ,  _lowerCamelCase  : Any       ,  _lowerCamelCase  : Dict       ,  _lowerCamelCase  : Any       ,  _lowerCamelCase  : Tuple       ,  _lowerCamelCase  : Optional[Any]							):






         '''simple docstring'''



         __lowerCamelCase     :      Tuple       						=						self.num_choices
         __lowerCamelCase     :      Union[str, Any]       						=						AlbertForMultipleChoice(config=_lowerCamelCase							)
         model.to(_lowerCamelCase							)
         model.eval()
         __lowerCamelCase     :      Union[str, Any]       						=						input_ids.unsqueeze(1							).expand(-1       ,  self.num_choices       ,  -1							).contiguous()
         __lowerCamelCase     :      str       						=						token_type_ids.unsqueeze(1							).expand(-1       ,  self.num_choices       ,  -1							).contiguous()
         __lowerCamelCase     :      List[str]       						=						input_mask.unsqueeze(1							).expand(-1       ,  self.num_choices       ,  -1							).contiguous()
         __lowerCamelCase     :      int       						=						model(
             _lowerCamelCase       ,  attention_mask=_lowerCamelCase       ,  token_type_ids=_lowerCamelCase       ,  labels=_lowerCamelCase       ,  )
         self.parent.assertEqual(result.logits.shape       ,  (self.batch_size, self.num_choices)							)


   def   _snake_case    (  self  : int							):






         '''simple docstring'''



         __lowerCamelCase     :      Union[str, Any]       						=						self.prepare_config_and_inputs()
         (
             (
             __lowerCamelCase
         )						, (
             __lowerCamelCase
         )						, (
             __lowerCamelCase
         )						, (
             __lowerCamelCase
         )						, (
             __lowerCamelCase
         )						, (
             __lowerCamelCase
         )						, (
             __lowerCamelCase
         )						, 
         )     :      Union[str, Any]       						=						config_and_inputs
         __lowerCamelCase     :      Tuple       						=						{"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
         return config, inputs_dict



@require_torch
class 							_UpperCamelCase (						A,A,unittest.TestCase						):

   '''simple docstring'''







   a_				:							Optional[Any]    = (
       (
           AlbertModel,
           AlbertForPreTraining,
           AlbertForMaskedLM,
           AlbertForMultipleChoice,
           AlbertForSequenceClassification,
           AlbertForTokenClassification,
           AlbertForQuestionAnswering,
       )
       if is_torch_available()
       else ()
   )
   a_				:							Optional[int]    = (
       {
           "feature-extraction": AlbertModel,
           "fill-mask": AlbertForMaskedLM,
           "question-answering": AlbertForQuestionAnswering,
           "text-classification": AlbertForSequenceClassification,
           "token-classification": AlbertForTokenClassification,
           "zero-shot": AlbertForSequenceClassification,
       }
       if is_torch_available()
       else {}
   )
   a_				:							Optional[int]    = True

   def   _snake_case    (  self  : str       ,  _lowerCamelCase  : Optional[int]       ,  _lowerCamelCase  : Optional[int]       ,  _lowerCamelCase  : Any=False							):






         '''simple docstring'''



         __lowerCamelCase     :      Optional[Any]       						=						super()._prepare_for_class(_lowerCamelCase       ,  _lowerCamelCase       ,  return_labels=_lowerCamelCase							)

         if return_labels:
               if model_class in get_values(_lowerCamelCase							):
                     __lowerCamelCase     :      List[Any]       						=						torch.zeros(
                         (self.model_tester.batch_size, self.model_tester.seq_length)       ,  dtype=torch.long       ,  device=_lowerCamelCase							)
                     __lowerCamelCase     :      Any       						=						torch.zeros(
                         self.model_tester.batch_size       ,  dtype=torch.long       ,  device=_lowerCamelCase							)
         return inputs_dict

   def   _snake_case    (  self  : List[Any]							):






         '''simple docstring'''



         __lowerCamelCase     :      int       						=						AlbertModelTester(self							)
         __lowerCamelCase     :      Optional[Any]       						=						ConfigTester(self       ,  config_class=_lowerCamelCase       ,  hidden_size=3_7							)

   def   _snake_case    (  self  : List[str]							):






         '''simple docstring'''



         self.config_tester.run_common_tests()

   def   _snake_case    (  self  : Union[str, Any]							):






         '''simple docstring'''



         __lowerCamelCase     :      Any       						=						self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_model(*_lowerCamelCase							)

   def   _snake_case    (  self  : Optional[int]							):






         '''simple docstring'''



         __lowerCamelCase     :      Union[str, Any]       						=						self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_pretraining(*_lowerCamelCase							)

   def   _snake_case    (  self  : List[str]							):






         '''simple docstring'''



         __lowerCamelCase     :      Optional[Any]       						=						self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_masked_lm(*_lowerCamelCase							)

   def   _snake_case    (  self  : int							):






         '''simple docstring'''



         __lowerCamelCase     :      List[str]       						=						self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_multiple_choice(*_lowerCamelCase							)

   def   _snake_case    (  self  : Optional[int]							):






         '''simple docstring'''



         __lowerCamelCase     :      Dict       						=						self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_question_answering(*_lowerCamelCase							)

   def   _snake_case    (  self  : Optional[int]							):






         '''simple docstring'''



         __lowerCamelCase     :      Tuple       						=						self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_for_sequence_classification(*_lowerCamelCase							)

   def   _snake_case    (  self  : Any							):






         '''simple docstring'''



         __lowerCamelCase     :      Union[str, Any]       						=						self.model_tester.prepare_config_and_inputs()
         for type in ["absolute", "relative_key", "relative_key_query"]:
               __lowerCamelCase     :      Dict       						=						type
               self.model_tester.create_and_check_model(*_lowerCamelCase							)


   @slow
   def   _snake_case    (  self  : str							):






         '''simple docstring'''



         for model_name in ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
               __lowerCamelCase     :      str       						=						AlbertModel.from_pretrained(_lowerCamelCase							)
               self.assertIsNotNone(_lowerCamelCase							)



@require_torch
class 							_UpperCamelCase (						unittest.TestCase						):

   '''simple docstring'''







   @slow
   def   _snake_case    (  self  : List[Any]							):






         '''simple docstring'''



         __lowerCamelCase     :      Optional[int]       						=						AlbertModel.from_pretrained("""albert-base-v2"""							)
         __lowerCamelCase     :      Optional[int]       						=						torch.tensor([[0, 3_4_5, 2_3_2, 3_2_8, 7_4_0, 1_4_0, 1_6_9_5, 6_9, 6_0_7_8, 1_5_8_8, 2]]							)
         __lowerCamelCase     :      Union[str, Any]       						=						torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]							)
         with torch.no_grad():
               __lowerCamelCase     :      Union[str, Any]       						=						model(_lowerCamelCase       ,  attention_mask=_lowerCamelCase							)[0]
         __lowerCamelCase     :      Dict       						=						torch.Size((1, 1_1, 7_6_8)							)
         self.assertEqual(output.shape       ,  _lowerCamelCase							)
         __lowerCamelCase     :      str       						=						torch.tensor(
             [[[-0.6_513, 1.5_035, -0.2_766], [-0.6_515, 1.5_046, -0.2_780], [-0.6_512, 1.5_049, -0.2_784]]]							)

         self.assertTrue(torch.allclose(output[:, 1:4, 1:4]       ,  _lowerCamelCase       ,  atol=1E-4							)							)







def   _UpperCAmelCase       (     UpperCAmelCase      :			int = 4_000_000      ):
      """simple docstring"""




      __lowerCamelCase     :      Union[str, Any]       						=						[0, 1]
      __lowerCamelCase     :      Dict       						=						0
      while fib[i] <= n:
            fib.append(fib[i] + fib[i + 1]      )
            if fib[i + 2] > n:
                  break
            i += 1
      __lowerCamelCase     :      Any       						=						0
      for j in range(len(UpperCAmelCase      ) - 1      ):
            if fib[j] % 2 == 0:
                  total += fib[j]

      return total


if __name__ == "__main__":
    print(F'''{solution() = }''')



