
'''simple docstring'''





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        UpperCAmelCase_       :

 '''simple docstring'''







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



   '''simple docstring'''




   UpperCAmelCase__			:				Optional[int]												=       parent
   UpperCAmelCase__			:				List[Any]												=       13
   UpperCAmelCase__			:				int												=       7
   UpperCAmelCase__			:				List[Any]												=       True
   UpperCAmelCase__			:				Dict												=       True
   UpperCAmelCase__			:				List[Any]												=       True
   UpperCAmelCase__			:				Any												=       True
   UpperCAmelCase__			:				Union[str, Any]												=       99
   UpperCAmelCase__			:				Dict												=       16
   UpperCAmelCase__			:				List[str]												=       32
   UpperCAmelCase__			:				Any												=       2
   UpperCAmelCase__			:				str												=       4
   UpperCAmelCase__			:				List[Any]												=       37
   UpperCAmelCase__			:				List[str]												=       "gelu"
   UpperCAmelCase__			:				Tuple												=       0.1
   UpperCAmelCase__			:				str												=       0.1
   UpperCAmelCase__			:				Dict												=       5_12
   UpperCAmelCase__			:				Dict												=       16
   UpperCAmelCase__			:				str												=       2
   UpperCAmelCase__			:				List[str]												=       0.02
   UpperCAmelCase__			:				Tuple												=       3
   UpperCAmelCase__			:				Union[str, Any]												=       4
   UpperCAmelCase__			:				Dict												=       None







 def        UpperCamelCase     (				self		:     Optional[int]   ):



   '''simple docstring'''




   UpperCAmelCase__			:				List[Any]												=       ids_tensor([self.batch_size, self.seq_length] ,							self.vocab_size   )

   UpperCAmelCase__			:				Tuple												=       None
   if self.use_input_mask:
     UpperCAmelCase__			:				List[Any]												=       random_attention_mask([self.batch_size, self.seq_length]   )

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

   UpperCAmelCase__			:				Dict												=       None
   UpperCAmelCase__			:				Optional[int]												=       None
   UpperCAmelCase__			:				Any												=       None
   if self.use_labels:
     UpperCAmelCase__			:				int												=       ids_tensor([self.batch_size] ,							self.type_sequence_label_size   )
     UpperCAmelCase__			:				Dict												=       ids_tensor([self.batch_size, self.seq_length] ,							self.num_labels   )
     UpperCAmelCase__			:				Dict												=       ids_tensor([self.batch_size] ,							self.num_choices   )

   UpperCAmelCase__			:				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		:     List[Any] ,							snake_case__		:     List[Any] ,							snake_case__		:     Dict ,							snake_case__		:     Union[str, Any] ,							snake_case__		:     str ,							snake_case__		:     List[str] ,							snake_case__		:     Tuple ,							snake_case__		:     Tuple   ):



   '''simple docstring'''




   UpperCAmelCase__			:				int												=       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__			:				Optional[int]												=       {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
   UpperCAmelCase__			:				Dict												=       model(snake_case__   )

   UpperCAmelCase__			:				Optional[Any]												=       [input_ids, input_mask]
   UpperCAmelCase__			:				List[str]												=       model(snake_case__   )

   UpperCAmelCase__			:				Dict												=       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		:     Tuple ,							snake_case__		:     int ,							snake_case__		:     Union[str, Any] ,							snake_case__		:     int ,							snake_case__		:     List[str] ,							snake_case__		:     Dict ,							snake_case__		:     int ,							snake_case__		:     List[str]   ):



   '''simple docstring'''




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



   '''simple docstring'''




   UpperCAmelCase__			:				List[Any]												=       TFAlbertForMaskedLM(config=snake_case__   )
   UpperCAmelCase__			:				Union[str, Any]												=       {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
   UpperCAmelCase__			:				Optional[Any]												=       model(snake_case__   )
   self.parent.assertEqual(result.logits.shape ,							(self.batch_size, self.seq_length, self.vocab_size)   )







 def        UpperCamelCase     (				self		:     str ,							snake_case__		:     List[Any] ,							snake_case__		:     Optional[Any] ,							snake_case__		:     List[Any] ,							snake_case__		:     int ,							snake_case__		:     Dict ,							snake_case__		:     List[Any] ,							snake_case__		:     str   ):



   '''simple docstring'''




   UpperCAmelCase__			:				List[Any]												=       self.num_labels
   UpperCAmelCase__			:				Tuple												=       TFAlbertForSequenceClassification(config=snake_case__   )
   UpperCAmelCase__			:				List[str]												=       {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
   UpperCAmelCase__			:				Optional[int]												=       model(snake_case__   )
   self.parent.assertEqual(result.logits.shape ,							(self.batch_size, self.num_labels)   )







 def        UpperCamelCase     (				self		:     Union[str, Any] ,							snake_case__		:     Any ,							snake_case__		:     List[Any] ,							snake_case__		:     Any ,							snake_case__		:     List[Any] ,							snake_case__		:     Optional[Any] ,							snake_case__		:     Tuple ,							snake_case__		:     List[Any]   ):



   '''simple docstring'''




   UpperCAmelCase__			:				Optional[Any]												=       TFAlbertForQuestionAnswering(config=snake_case__   )
   UpperCAmelCase__			:				Tuple												=       {"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
   UpperCAmelCase__			:				int												=       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		:     List[str] ,							snake_case__		:     Union[str, Any] ,							snake_case__		:     int ,							snake_case__		:     Any ,							snake_case__		:     Any ,							snake_case__		:     int ,							snake_case__		:     Optional[int] ,							snake_case__		:     List[str]   ):



   '''simple docstring'''




   UpperCAmelCase__			:				Dict												=       self.num_choices
   UpperCAmelCase__			:				Optional[int]												=       TFAlbertForMultipleChoice(config=snake_case__   )
   UpperCAmelCase__			:				List[str]												=       tf.tile(tf.expand_dims(snake_case__ ,							1   ) ,							(1, self.num_choices, 1)   )
   UpperCAmelCase__			:				int												=       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__			:				int												=       {
       "input_ids": multiple_choice_inputs_ids,
       "attention_mask": multiple_choice_input_mask,
       "token_type_ids": multiple_choice_token_type_ids,
   }
   UpperCAmelCase__			:				Optional[Any]												=       model(snake_case__   )
   self.parent.assertListEqual(list(result["logits"].shape   ) ,							[self.batch_size, self.num_choices]   )







 def        UpperCamelCase     (				self		:     List[str] ,							snake_case__		:     str ,							snake_case__		:     Any ,							snake_case__		:     str ,							snake_case__		:     int ,							snake_case__		:     Tuple ,							snake_case__		:     int ,							snake_case__		:     Any   ):



   '''simple docstring'''




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







 def        UpperCamelCase     (				self		:     Tuple   ):



   '''simple docstring'''




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






@require_tf
class        UpperCAmelCase_       (						A				,							A				,							unittest.TestCase							):

 '''simple docstring'''
 lowercase_				:						Optional[Any]				=       (
     (
         TFAlbertModel,
         TFAlbertForPreTraining,
         TFAlbertForMaskedLM,
         TFAlbertForSequenceClassification,
         TFAlbertForQuestionAnswering,
         TFAlbertForTokenClassification,
         TFAlbertForMultipleChoice,
     )
     if is_tf_available()
     else ()
 )
 lowercase_				:						int				=       (
     {
         "feature-extraction": TFAlbertModel,
         "fill-mask": TFAlbertForMaskedLM,
         "question-answering": TFAlbertForQuestionAnswering,
         "text-classification": TFAlbertForSequenceClassification,
         "token-classification": TFAlbertForTokenClassification,
         "zero-shot": TFAlbertForSequenceClassification,
     }
     if is_tf_available()
     else {}
 )
 lowercase_				:						Tuple				=       False
 lowercase_				:						Tuple				=       False







 def        UpperCamelCase     (				self		:     List[str] ,							snake_case__		:     Optional[int] ,							snake_case__		:     Any ,							snake_case__		:     Optional[int]=False   ):



   '''simple docstring'''




   UpperCAmelCase__			:				int												=       super()._prepare_for_class(snake_case__ ,							snake_case__ ,							return_labels=snake_case__   )

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

   return inputs_dict







 def        UpperCamelCase     (				self		:     List[Any]   ):



   '''simple docstring'''




   UpperCAmelCase__			:				str												=       TFAlbertModelTester(self   )
   UpperCAmelCase__			:				Union[str, Any]												=       ConfigTester(self ,							config_class=snake_case__ ,							hidden_size=37   )







 def        UpperCamelCase     (				self		:     Optional[int]   ):



   '''simple docstring'''




   self.config_tester.run_common_tests()







 def        UpperCamelCase     (				self		:     str   ):



   '''simple docstring'''




   UpperCAmelCase__			:				Optional[Any]												=       self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_albert_model(*snake_case__   )







 def        UpperCamelCase     (				self		:     Optional[int]   ):



   '''simple docstring'''




   UpperCAmelCase__			:				Union[str, Any]												=       self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_albert_for_pretraining(*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_masked_lm(*snake_case__   )







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



   '''simple docstring'''




   UpperCAmelCase__			:				Optional[Any]												=       self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_albert_for_multiple_choice(*snake_case__   )







 def        UpperCamelCase     (				self		:     Tuple   ):



   '''simple docstring'''




   UpperCAmelCase__			:				Optional[int]												=       self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_albert_for_sequence_classification(*snake_case__   )







 def        UpperCamelCase     (				self		:     List[Any]   ):



   '''simple docstring'''




   UpperCAmelCase__			:				Any												=       self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_albert_for_question_answering(*snake_case__   )







 @slow
 def        UpperCamelCase     (				self		:     Dict   ):



   '''simple docstring'''




   for model_name in TF_ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
     UpperCAmelCase__			:				List[str]												=       TFAlbertModel.from_pretrained(snake_case__   )
     self.assertIsNotNone(snake_case__   )






@require_tf
class        UpperCAmelCase_       (						unittest.TestCase							):

 '''simple docstring'''







 @slow
 def        UpperCamelCase     (				self		:     Tuple   ):



   '''simple docstring'''




   UpperCAmelCase__			:				Tuple												=       TFAlbertForPreTraining.from_pretrained("albert-base-v2"   )
   UpperCAmelCase__			:				int												=       tf.constant([[0, 1, 2, 3, 4, 5]]   )
   UpperCAmelCase__			:				Optional[int]												=       model(snake_case__   )[0]

   UpperCAmelCase__			:				List[str]												=       [1, 6, 3_00_00]
   self.assertEqual(output.shape ,							snake_case__   )

   UpperCAmelCase__			:				Dict												=       tf.constant(
       [
           [
               [4.595668, 0.74462754, -1.818147],
               [4.5954347, 0.7454184, -1.8188258],
               [4.5954905, 0.7448235, -1.8182316],
           ]
       ]   )
   tf.debugging.assert_near(output[:, :3, :3] ,							snake_case__ ,							atol=1e-4   )





'''simple docstring'''





from doctest import testmod
from math import sqrt







def snake_case_    (				lowercase__		):
  UpperCAmelCase__			:				list[int]												=       []
  if num < 1:
    return facs
  facs.append(1		)
  if num == 1:
    return facs
  facs.append(lowercase__		)
  for i in range(2      ,					int(sqrt(lowercase__		)		) + 1		):
    if num % i == 0:  # If i is a factor of num
      facs.append(lowercase__		)
      UpperCAmelCase__			:				Tuple												=       num // i  # num//i is the other factor of num
      if d != i:  # If d and i are distinct
        facs.append(lowercase__		)  # we have found another factor
  facs.sort()
  return facs


if __name__ == "__main__":
      testmod(name="""factors_of_a_number""", verbose=True)



