






from __future__ import annotations

import unittest

from transformers import AlbertConfig, is_tf_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
   import tensorflow as tf

   from transformers import TF_MODEL_FOR_PRETRAINING_MAPPING
   from transformers.models.albert.modeling_tf_albert import (
       TF_ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
       TFAlbertForMaskedLM,
       TFAlbertForMultipleChoice,
       TFAlbertForPreTraining,
       TFAlbertForQuestionAnswering,
       TFAlbertForSequenceClassification,
       TFAlbertForTokenClassification,
       TFAlbertModel,
   )




class        _lowerCAmelCase:





       """simple docstring"""







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





       def     _a					(      self							):
         UpperCamelCase_:      int					   =       ids_tensor([self.batch_size, self.seq_length]						,    self.vocab_size							)

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

         UpperCamelCase_:      List[str]					   =       None
         if self.use_token_type_ids:
           UpperCamelCase_:      List[Any]					   =       ids_tensor([self.batch_size, self.seq_length]						,    self.type_vocab_size							)

         UpperCamelCase_:      Any					   =       None
         UpperCamelCase_:      Dict					   =       None
         UpperCamelCase_:      str					   =       None
         if self.use_labels:
           UpperCamelCase_:      Union[str, Any]					   =       ids_tensor([self.batch_size]						,    self.type_sequence_label_size							)
           UpperCamelCase_:      Union[str, Any]					   =       ids_tensor([self.batch_size, self.seq_length]						,    self.num_labels							)
           UpperCamelCase_:      Any					   =       ids_tensor([self.batch_size]						,    self.num_choices							)

         UpperCamelCase_:      List[Any]					   =       AlbertConfig(
             vocab_size=self.vocab_size						,    hidden_size=self.hidden_size						,    embedding_size=self.embedding_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						,    )

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





       def     _a					(      self						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase							):
         UpperCamelCase_:      int					   =       TFAlbertModel(config=_lowerCamelCase							)
         # inputs = {'input_ids': input_ids,
         #           'attention_mask': input_mask,
         #           'token_type_ids': token_type_ids}
         # sequence_output, pooled_output = model(**inputs)
         UpperCamelCase_:      Any					   =       {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
         UpperCamelCase_:      Dict					   =       model(_lowerCamelCase							)

         UpperCamelCase_:      str					   =       [input_ids, input_mask]
         UpperCamelCase_:      Dict					   =       model(_lowerCamelCase							)

         UpperCamelCase_:      Optional[Any]					   =       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     _a					(      self						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase							):
         UpperCamelCase_:      str					   =       self.num_labels
         UpperCamelCase_:      List[Any]					   =       TFAlbertForPreTraining(config=_lowerCamelCase							)
         UpperCamelCase_:      Dict					   =       {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
         UpperCamelCase_:      List[str]					   =       model(_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, self.num_labels)							)





       def     _a					(      self						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase							):
         UpperCamelCase_:      Optional[int]					   =       TFAlbertForMaskedLM(config=_lowerCamelCase							)
         UpperCamelCase_:      List[str]					   =       {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
         UpperCamelCase_:      Any					   =       model(_lowerCamelCase							)
         self.parent.assertEqual(result.logits.shape						,    (self.batch_size, self.seq_length, self.vocab_size)							)





       def     _a					(      self						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase							):
         UpperCamelCase_:      Dict					   =       self.num_labels
         UpperCamelCase_:      Optional[Any]					   =       TFAlbertForSequenceClassification(config=_lowerCamelCase							)
         UpperCamelCase_:      str					   =       {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
         UpperCamelCase_:      str					   =       model(_lowerCamelCase							)
         self.parent.assertEqual(result.logits.shape						,    (self.batch_size, self.num_labels)							)





       def     _a					(      self						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase							):
         UpperCamelCase_:      List[Any]					   =       TFAlbertForQuestionAnswering(config=_lowerCamelCase							)
         UpperCamelCase_:      Tuple					   =       {'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
         UpperCamelCase_:      Dict					   =       model(_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     _a					(      self						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase							):
         UpperCamelCase_:      Union[str, Any]					   =       self.num_choices
         UpperCamelCase_:      str					   =       TFAlbertForMultipleChoice(config=_lowerCamelCase							)
         UpperCamelCase_:      Union[str, Any]					   =       tf.tile(tf.expand_dims(_lowerCamelCase						,    1							)						,    (1, self.num_choices, 1)							)
         UpperCamelCase_:      Tuple					   =       tf.tile(tf.expand_dims(_lowerCamelCase						,    1							)						,    (1, self.num_choices, 1)							)
         UpperCamelCase_:      int					   =       tf.tile(tf.expand_dims(_lowerCamelCase						,    1							)						,    (1, self.num_choices, 1)							)
         UpperCamelCase_:      Any					   =       {
             'input_ids': multiple_choice_inputs_ids,
             'attention_mask': multiple_choice_input_mask,
             'token_type_ids': multiple_choice_token_type_ids,
         }
         UpperCamelCase_:      Optional[int]					   =       model(_lowerCamelCase							)
         self.parent.assertListEqual(list(result['logits'].shape							)						,    [self.batch_size, self.num_choices]							)





       def     _a					(      self						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase							):
         UpperCamelCase_:      int					   =       self.num_labels
         UpperCamelCase_:      Dict					   =       TFAlbertForTokenClassification(config=_lowerCamelCase							)
         UpperCamelCase_:      Tuple					   =       {
             'input_ids': input_ids,
             'attention_mask': input_mask,
             'token_type_ids': token_type_ids,
         }
         UpperCamelCase_:      int					   =       model(_lowerCamelCase							)
         self.parent.assertListEqual(list(result['logits'].shape							)						,    [self.batch_size, self.seq_length, self.num_labels]							)





       def     _a					(      self							):
         UpperCamelCase_:      List[Any]					   =       self.prepare_config_and_inputs()
         (
             (
             UpperCamelCase_
         )   ,(
             UpperCamelCase_
         )   ,(
             UpperCamelCase_
         )   ,(
             UpperCamelCase_
         )   ,(
             UpperCamelCase_
         )   ,(
             UpperCamelCase_
         )   ,(
             UpperCamelCase_
         )   ,
         ):      List[Any]					   =       config_and_inputs
         UpperCamelCase_:      Optional[Any]					   =       {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
         return config, inputs_dict







@require_tf
class        _lowerCAmelCase( lowercase_							,			lowercase_							,			unittest.TestCase      ):





       """simple docstring"""







       a       :	Dict								=(
           (
               TFAlbertModel,
               TFAlbertForPreTraining,
               TFAlbertForMaskedLM,
               TFAlbertForSequenceClassification,
               TFAlbertForQuestionAnswering,
               TFAlbertForTokenClassification,
               TFAlbertForMultipleChoice,
           )
           if is_tf_available()
           else ()
       )
       a       :	Union[str, Any]								=(
           {
               """feature-extraction""": TFAlbertModel,
               """fill-mask""": TFAlbertForMaskedLM,
               """question-answering""": TFAlbertForQuestionAnswering,
               """text-classification""": TFAlbertForSequenceClassification,
               """token-classification""": TFAlbertForTokenClassification,
               """zero-shot""": TFAlbertForSequenceClassification,
           }
           if is_tf_available()
           else {}
       )
       a       :	str								=False
       a       :	Optional[Any]								=False





       def     _a					(      self						,    _lowerCamelCase						,    _lowerCamelCase						,    _lowerCamelCase=False							):
         UpperCamelCase_:      Any					   =       super()._prepare_for_class(_lowerCamelCase						,    _lowerCamelCase						,    return_labels=_lowerCamelCase							)

         if return_labels:
           if model_class in get_values(_lowerCamelCase							):
             UpperCamelCase_:      str					   =       tf.zeros(self.model_tester.batch_size						,    dtype=tf.intaa							)

         return inputs_dict





       def     _a					(      self							):
         UpperCamelCase_:      List[str]					   =       TFAlbertModelTester(self							)
         UpperCamelCase_:      Tuple					   =       ConfigTester(self						,    config_class=_lowerCamelCase						,    hidden_size=3_7							)





       def     _a					(      self							):
         self.config_tester.run_common_tests()





       def     _a					(      self							):
         UpperCamelCase_:      int					   =       self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_albert_model(*_lowerCamelCase							)





       def     _a					(      self							):
         UpperCamelCase_:      List[Any]					   =       self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_albert_for_pretraining(*_lowerCamelCase							)





       def     _a					(      self							):
         UpperCamelCase_:      Union[str, Any]					   =       self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_albert_for_masked_lm(*_lowerCamelCase							)





       def     _a					(      self							):
         UpperCamelCase_:      Optional[int]					   =       self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_albert_for_multiple_choice(*_lowerCamelCase							)





       def     _a					(      self							):
         UpperCamelCase_:      Union[str, Any]					   =       self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_albert_for_sequence_classification(*_lowerCamelCase							)





       def     _a					(      self							):
         UpperCamelCase_:      int					   =       self.model_tester.prepare_config_and_inputs()
         self.model_tester.create_and_check_albert_for_question_answering(*_lowerCamelCase							)





       @slow
       def     _a					(      self							):







         for model_name in TF_ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
           UpperCamelCase_:      Dict					   =       TFAlbertModel.from_pretrained(_lowerCamelCase							)
           self.assertIsNotNone(_lowerCamelCase							)







@require_tf
class        _lowerCAmelCase( unittest.TestCase      ):





       """simple docstring"""







       @slow
       def     _a					(      self							):
         UpperCamelCase_:      str					   =       TFAlbertForPreTraining.from_pretrained('albert-base-v2'							)
         UpperCamelCase_:      List[Any]					   =       tf.constant([[0, 1, 2, 3, 4, 5]]							)
         UpperCamelCase_:      int					   =       model(_lowerCamelCase							)[0]

         UpperCamelCase_:      Optional[Any]					   =       [1, 6, 3_0_0_0_0]
         self.assertEqual(output.shape						,    _lowerCamelCase							)

         UpperCamelCase_:      Union[str, Any]					   =       tf.constant(
             [
                 [
                     [4.5_9_5_6_6_8, 0.7_4_4_6_2_7_5_4, -1.8_1_8_1_4_7],
                     [4.5_9_5_4_3_4_7, 0.7_4_5_4_1_8_4, -1.8_1_8_8_2_5_8],
                     [4.5_9_5_4_9_0_5, 0.7_4_4_8_2_3_5, -1.8_1_8_2_3_1_6],
                 ]
             ]							)
         tf.debugging.assert_near(output[:, :3, :3]						,    _lowerCamelCase						,    atol=1e-4							)







def 						snake_case      (UpperCAmelCase__ = 4_0_0_0_0_0_0						) ->       int:

  if n <= 1:
    return 0
  UpperCamelCase_:      Dict					   =       0
  UpperCamelCase_:      Union[str, Any]					   =       2
  UpperCamelCase_:      int					   =       0
  while 4 * b + a <= n:
    UpperCamelCase_   ,UpperCamelCase_:      List[str]					   =       b, 4 * b + a
    count += a
  return count + b


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