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 			__snake_case   :
 def __init__(  self		,   snake_case__		,   snake_case__=13		,   snake_case__=7		,   snake_case__=True		,   snake_case__=True		,   snake_case__=True		,   snake_case__=True		,   snake_case__=99		,   snake_case__=16		,   snake_case__=32		,   snake_case__=2		,   snake_case__=4		,   snake_case__=37		,   snake_case__="gelu"		,   snake_case__=0.1		,   snake_case__=0.1		,   snake_case__=512		,   snake_case__=16		,   snake_case__=2		,   snake_case__=0.02		,   snake_case__=3		,   snake_case__=4		,   snake_case__=None		,   )	->							Any:
       '''simple docstring'''





       UpperCAmelCase    : Tuple      =parent
       UpperCAmelCase    : Dict      =13
       UpperCAmelCase    : Any      =7
       UpperCAmelCase    : Any      =True
       UpperCAmelCase    : List[Any]      =True
       UpperCAmelCase    : int      =True
       UpperCAmelCase    : List[str]      =True
       UpperCAmelCase    : Optional[int]      =99
       UpperCAmelCase    : List[str]      =16
       UpperCAmelCase    : Dict      =32
       UpperCAmelCase    : Optional[Any]      =2
       UpperCAmelCase    : str      =4
       UpperCAmelCase    : List[Any]      =37
       UpperCAmelCase    : Optional[int]      ='''gelu'''
       UpperCAmelCase    : List[str]      =0.1
       UpperCAmelCase    : Optional[Any]      =0.1
       UpperCAmelCase    : Dict      =512
       UpperCAmelCase    : Tuple      =16
       UpperCAmelCase    : Optional[int]      =2
       UpperCAmelCase    : Dict      =0.02
       UpperCAmelCase    : List[Any]      =3
       UpperCAmelCase    : Union[str, Any]      =4
       UpperCAmelCase    : str      =None
 def 	UpperCAmelCase__       (  self						)	->							str:
       '''simple docstring'''





       UpperCAmelCase    : Optional[int]      =ids_tensor([self.batch_size, self.seq_length]		,   self.vocab_size						)

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

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

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

       UpperCAmelCase    : Union[str, 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 	UpperCAmelCase__       (  self		,   snake_case__		,   snake_case__		,   snake_case__		,   snake_case__		,   snake_case__		,   snake_case__		,   snake_case__						)	->							Optional[int]:
       '''simple docstring'''





       UpperCAmelCase    : Union[str, Any]      =TFAlbertModel(config=snake_case__						)
       # inputs = {'input_ids': input_ids,
       #           'attention_mask': input_mask,
       #           'token_type_ids': token_type_ids}
       # sequence_output, pooled_output = model(**inputs)
       UpperCAmelCase    : Tuple      ={'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
       UpperCAmelCase    : List[Any]      =model(snake_case__						)

       UpperCAmelCase    : Tuple      =[input_ids, input_mask]
       UpperCAmelCase    : Optional[int]      =model(snake_case__						)

       UpperCAmelCase    : Optional[int]      =model(snake_case__						)

       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		,   snake_case__		,   snake_case__		,   snake_case__		,   snake_case__		,   snake_case__		,   snake_case__		,   snake_case__						)	->							Optional[Any]:
       '''simple docstring'''





       UpperCAmelCase    : Union[str, Any]      =self.num_labels
       UpperCAmelCase    : Optional[int]      =TFAlbertForPreTraining(config=snake_case__						)
       UpperCAmelCase    : str      ={'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
       UpperCAmelCase    : List[str]      =model(snake_case__						)
       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 	UpperCAmelCase__       (  self		,   snake_case__		,   snake_case__		,   snake_case__		,   snake_case__		,   snake_case__		,   snake_case__		,   snake_case__						)	->							Union[str, Any]:
       '''simple docstring'''





       UpperCAmelCase    : Union[str, Any]      =TFAlbertForMaskedLM(config=snake_case__						)
       UpperCAmelCase    : Optional[Any]      ={'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
       UpperCAmelCase    : Dict      =model(snake_case__						)
       self.parent.assertEqual(result.logits.shape		,   (self.batch_size, self.seq_length, self.vocab_size)						)
 def 	UpperCAmelCase__       (  self		,   snake_case__		,   snake_case__		,   snake_case__		,   snake_case__		,   snake_case__		,   snake_case__		,   snake_case__						)	->							Dict:
       '''simple docstring'''





       UpperCAmelCase    : Any      =self.num_labels
       UpperCAmelCase    : Union[str, Any]      =TFAlbertForSequenceClassification(config=snake_case__						)
       UpperCAmelCase    : Any      ={'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
       UpperCAmelCase    : Dict      =model(snake_case__						)
       self.parent.assertEqual(result.logits.shape		,   (self.batch_size, self.num_labels)						)
 def 	UpperCAmelCase__       (  self		,   snake_case__		,   snake_case__		,   snake_case__		,   snake_case__		,   snake_case__		,   snake_case__		,   snake_case__						)	->							Tuple:
       '''simple docstring'''





       UpperCAmelCase    : int      =TFAlbertForQuestionAnswering(config=snake_case__						)
       UpperCAmelCase    : Dict      ={'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
       UpperCAmelCase    : Tuple      =model(snake_case__						)
       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		,   snake_case__		,   snake_case__		,   snake_case__		,   snake_case__		,   snake_case__		,   snake_case__		,   snake_case__						)	->							List[str]:
       '''simple docstring'''





       UpperCAmelCase    : List[str]      =self.num_choices
       UpperCAmelCase    : Dict      =TFAlbertForMultipleChoice(config=snake_case__						)
       UpperCAmelCase    : Union[str, Any]      =tf.tile(tf.expand_dims(snake_case__		,   1						)		,   (1, self.num_choices, 1)						)
       UpperCAmelCase    : Optional[int]      =tf.tile(tf.expand_dims(snake_case__		,   1						)		,   (1, self.num_choices, 1)						)
       UpperCAmelCase    : List[Any]      =tf.tile(tf.expand_dims(snake_case__		,   1						)		,   (1, self.num_choices, 1)						)
       UpperCAmelCase    : int      ={
           '''input_ids''': multiple_choice_inputs_ids,
           '''attention_mask''': multiple_choice_input_mask,
           '''token_type_ids''': multiple_choice_token_type_ids,
       }
       UpperCAmelCase    : List[Any]      =model(snake_case__						)
       self.parent.assertListEqual(list(result['''logits'''].shape						)		,   [self.batch_size, self.num_choices]						)
 def 	UpperCAmelCase__       (  self		,   snake_case__		,   snake_case__		,   snake_case__		,   snake_case__		,   snake_case__		,   snake_case__		,   snake_case__						)	->							Optional[int]:
       '''simple docstring'''





       UpperCAmelCase    : List[str]      =self.num_labels
       UpperCAmelCase    : Optional[int]      =TFAlbertForTokenClassification(config=snake_case__						)
       UpperCAmelCase    : Dict      ={
           '''input_ids''': input_ids,
           '''attention_mask''': input_mask,
           '''token_type_ids''': token_type_ids,
       }
       UpperCAmelCase    : Tuple      =model(snake_case__						)
       self.parent.assertListEqual(list(result['''logits'''].shape						)		,   [self.batch_size, self.seq_length, self.num_labels]						)






 def 	UpperCAmelCase__       (  self						)	->							List[Any]:
       '''simple docstring'''





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







@require_tf
class 			__snake_case   (     lowerCamelCase__					,   lowerCamelCase__					,   unittest.TestCase   ):
 __lowerCamelCase    :   str     =      (
     (
         TFAlbertModel,
         TFAlbertForPreTraining,
         TFAlbertForMaskedLM,
         TFAlbertForSequenceClassification,
         TFAlbertForQuestionAnswering,
         TFAlbertForTokenClassification,
         TFAlbertForMultipleChoice,
     )
     if is_tf_available()
     else ()
 )
 __lowerCamelCase    :   List[str]     =      (
     {
         """feature-extraction""": TFAlbertModel,
         """fill-mask""": TFAlbertForMaskedLM,
         """question-answering""": TFAlbertForQuestionAnswering,
         """text-classification""": TFAlbertForSequenceClassification,
         """token-classification""": TFAlbertForTokenClassification,
         """zero-shot""": TFAlbertForSequenceClassification,
     }
     if is_tf_available()
     else {}
 )
 __lowerCamelCase    :   int     =      False
 __lowerCamelCase    :   Any     =      False
 def 	UpperCAmelCase__       (  self		,   snake_case__		,   snake_case__		,   snake_case__=False						)	->							Optional[Any]:
       '''simple docstring'''





       UpperCAmelCase    : List[Any]      =super()._prepare_for_class(snake_case__		,   snake_case__		,   return_labels=snake_case__						)

       if return_labels:
             if model_class in get_values(snake_case__						):
                   UpperCAmelCase    : int      =tf.zeros(self.model_tester.batch_size		,   dtype=tf.intaa						)

       return inputs_dict
 def 	UpperCAmelCase__       (  self						)	->							List[Any]:
       '''simple docstring'''





       UpperCAmelCase    : Optional[int]      =TFAlbertModelTester(self						)
       UpperCAmelCase    : str      =ConfigTester(self		,   config_class=snake_case__		,   hidden_size=37						)
 def 	UpperCAmelCase__       (  self						)	->							Union[str, Any]:
       '''simple docstring'''





       self.config_tester.run_common_tests()
 def 	UpperCAmelCase__       (  self						)	->							Dict:
       '''simple docstring'''





       UpperCAmelCase    : List[str]      =self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_albert_model(*snake_case__						)
 def 	UpperCAmelCase__       (  self						)	->							Dict:
       '''simple docstring'''





       UpperCAmelCase    : str      =self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_albert_for_pretraining(*snake_case__						)
 def 	UpperCAmelCase__       (  self						)	->							List[str]:
       '''simple docstring'''





       UpperCAmelCase    : Dict      =self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_albert_for_masked_lm(*snake_case__						)
 def 	UpperCAmelCase__       (  self						)	->							Any:
       '''simple docstring'''





       UpperCAmelCase    : List[Any]      =self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_albert_for_multiple_choice(*snake_case__						)
 def 	UpperCAmelCase__       (  self						)	->							Any:
       '''simple docstring'''





       UpperCAmelCase    : str      =self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_albert_for_sequence_classification(*snake_case__						)
 def 	UpperCAmelCase__       (  self						)	->							Dict:
       '''simple docstring'''





       UpperCAmelCase    : Union[str, Any]      =self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_albert_for_question_answering(*snake_case__						)






 @slow
 def 	UpperCAmelCase__       (  self						)	->							str:
       '''simple docstring'''





       for model_name in TF_ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
             UpperCAmelCase    : Union[str, Any]      =TFAlbertModel.from_pretrained(snake_case__						)
             self.assertIsNotNone(snake_case__						)







@require_tf
class 			__snake_case   (     unittest.TestCase   ):
 @slow
 def 	UpperCAmelCase__       (  self						)	->							List[Any]:
       '''simple docstring'''





       UpperCAmelCase    : Optional[Any]      =TFAlbertForPreTraining.from_pretrained('''albert-base-v2'''						)
       UpperCAmelCase    : Optional[Any]      =tf.constant([[0, 1, 2, 3, 4, 5]]						)
       UpperCAmelCase    : List[str]      =model(snake_case__						)[0]

       UpperCAmelCase    : Optional[Any]      =[1, 6, 3_0000]
       self.assertEqual(output.shape		,   snake_case__						)

       UpperCAmelCase    : int      =tf.constant(
           [
               [
                   [4.59_5668, 0.7446_2754, -1.81_8147],
                   [4.595_4347, 0.745_4184, -1.818_8258],
                   [4.595_4905, 0.744_8235, -1.818_2316],
               ]
           ]						)
       tf.debugging.assert_near(output[:, :3, :3]		,   snake_case__		,   atol=1e-4						)

from collections import defaultdict





def   lowerCAmelCase_ (				__lowerCAmelCase = 5						)->  int:






      '''simple docstring'''





      UpperCAmelCase    : List[str]      =defaultdict(__lowerCAmelCase						)
      UpperCAmelCase    : Tuple      =0

      while True:
            UpperCAmelCase    : Any      =get_digits(__lowerCAmelCase						)
            freqs[digits].append(__lowerCAmelCase						)

            if len(freqs[digits]						) == max_base:
                  UpperCAmelCase    : Optional[int]      =freqs[digits][0] ** 3
                  return base

            num += 1





def   lowerCAmelCase_ (				__lowerCAmelCase						)->  str:






      '''simple docstring'''





      return "".join(sorted(str(num**3						)						)						)


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