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    :



     def __init__(       self					,   lowerCAmelCase__					,   lowerCAmelCase__=13					,   lowerCAmelCase__=7					,   lowerCAmelCase__=True					,   lowerCAmelCase__=True					,   lowerCAmelCase__=True					,   lowerCAmelCase__=True					,   lowerCAmelCase__=99					,   lowerCAmelCase__=16					,   lowerCAmelCase__=32					,   lowerCAmelCase__=2					,   lowerCAmelCase__=4					,   lowerCAmelCase__=37					,   lowerCAmelCase__="gelu"					,   lowerCAmelCase__=0.1					,   lowerCAmelCase__=0.1					,   lowerCAmelCase__=512					,   lowerCAmelCase__=16					,   lowerCAmelCase__=2					,   lowerCAmelCase__=0.02					,   lowerCAmelCase__=3					,   lowerCAmelCase__=4					,   lowerCAmelCase__=None					,   ):
            _A=						parent
            _A=						13
            _A=						7
            _A=						True
            _A=						True
            _A=						True
            _A=						True
            _A=						99
            _A=						16
            _A=						32
            _A=						2
            _A=						4
            _A=						37
            _A=						'gelu'
            _A=						0.1
            _A=						0.1
            _A=						512
            _A=						16
            _A=						2
            _A=						0.02
            _A=						3
            _A=						4
            _A=						None



     def       a__	(       self							):
            _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=						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__							):
            _A=						TFAlbertModel(config=lowerCAmelCase__							)
            # inputs = {'input_ids': input_ids,
            #           'attention_mask': input_mask,
            #           'token_type_ids': token_type_ids}
            # sequence_output, pooled_output = model(**inputs)
            _A=						{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
            _A=						model(lowerCAmelCase__							)

            _A=						[input_ids, input_mask]
            _A=						model(lowerCAmelCase__							)

            _A=						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__							):
            _A=						self.num_labels
            _A=						TFAlbertForPreTraining(config=lowerCAmelCase__							)
            _A=						{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
            _A=						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__							):
            _A=						TFAlbertForMaskedLM(config=lowerCAmelCase__							)
            _A=						{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
            _A=						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__							):
            _A=						self.num_labels
            _A=						TFAlbertForSequenceClassification(config=lowerCAmelCase__							)
            _A=						{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
            _A=						model(lowerCAmelCase__							)
            self.parent.assertEqual(result.logits.shape					,   (self.batch_size, self.num_labels)							)



     def       a__	(       self					,   lowerCAmelCase__					,   lowerCAmelCase__					,   lowerCAmelCase__					,   lowerCAmelCase__					,   lowerCAmelCase__					,   lowerCAmelCase__					,   lowerCAmelCase__							):
            _A=						TFAlbertForQuestionAnswering(config=lowerCAmelCase__							)
            _A=						{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
            _A=						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__							):
            _A=						self.num_choices
            _A=						TFAlbertForMultipleChoice(config=lowerCAmelCase__							)
            _A=						tf.tile(tf.expand_dims(lowerCAmelCase__					,   1							)					,   (1, self.num_choices, 1)							)
            _A=						tf.tile(tf.expand_dims(lowerCAmelCase__					,   1							)					,   (1, self.num_choices, 1)							)
            _A=						tf.tile(tf.expand_dims(lowerCAmelCase__					,   1							)					,   (1, self.num_choices, 1)							)
            _A=						{
                'input_ids': multiple_choice_inputs_ids,
                'attention_mask': multiple_choice_input_mask,
                'token_type_ids': multiple_choice_token_type_ids,
            }
            _A=						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__							):
            _A=						self.num_labels
            _A=						TFAlbertForTokenClassification(config=lowerCAmelCase__							)
            _A=						{
                'input_ids': input_ids,
                'attention_mask': input_mask,
                'token_type_ids': token_type_ids,
            }
            _A=						model(lowerCAmelCase__							)
            self.parent.assertListEqual(list(result['logits'].shape							)					,   [self.batch_size, self.seq_length, self.num_labels]							)





     def       a__	(       self							):
            _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_tf
class   lowerCAmelCase    (       _a      ,		_a      ,		unittest.TestCase      ):
     _SCREAMING_SNAKE_CASE  :  Union[str, Any]		=(
         (
             TFAlbertModel,
             TFAlbertForPreTraining,
             TFAlbertForMaskedLM,
             TFAlbertForSequenceClassification,
             TFAlbertForQuestionAnswering,
             TFAlbertForTokenClassification,
             TFAlbertForMultipleChoice,
         )
         if is_tf_available()
         else ()
     )
     _SCREAMING_SNAKE_CASE  :  Any		=(
         {
             """feature-extraction""": TFAlbertModel,
             """fill-mask""": TFAlbertForMaskedLM,
             """question-answering""": TFAlbertForQuestionAnswering,
             """text-classification""": TFAlbertForSequenceClassification,
             """token-classification""": TFAlbertForTokenClassification,
             """zero-shot""": TFAlbertForSequenceClassification,
         }
         if is_tf_available()
         else {}
     )
     _SCREAMING_SNAKE_CASE  :  str		=False
     _SCREAMING_SNAKE_CASE  :  Optional[int]		=False



     def       a__	(       self					,   lowerCAmelCase__					,   lowerCAmelCase__					,   lowerCAmelCase__=False							):
            _A=						super()._prepare_for_class(lowerCAmelCase__					,   lowerCAmelCase__					,   return_labels=lowerCAmelCase__							)

            if return_labels:
                   if model_class in get_values(lowerCAmelCase__							):
                          _A=						tf.zeros(self.model_tester.batch_size					,   dtype=tf.intaa							)

            return inputs_dict



     def       a__	(       self							):
            _A=						TFAlbertModelTester(self							)
            _A=						ConfigTester(self					,   config_class=lowerCAmelCase__					,   hidden_size=37							)



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



     def       a__	(       self							):
            _A=						self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_albert_model(*lowerCAmelCase__							)



     def       a__	(       self							):
            _A=						self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_albert_for_pretraining(*lowerCAmelCase__							)



     def       a__	(       self							):
            _A=						self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_albert_for_masked_lm(*lowerCAmelCase__							)



     def       a__	(       self							):
            _A=						self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_albert_for_multiple_choice(*lowerCAmelCase__							)



     def       a__	(       self							):
            _A=						self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_albert_for_sequence_classification(*lowerCAmelCase__							)



     def       a__	(       self							):
            _A=						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]:
                   _A=						TFAlbertModel.from_pretrained(lowerCAmelCase__							)
                   self.assertIsNotNone(lowerCAmelCase__							)





@require_tf
class   lowerCAmelCase    (       unittest.TestCase      ):



     @slow
     def       a__	(       self							):
            _A=						TFAlbertForPreTraining.from_pretrained('albert-base-v2'							)
            _A=						tf.constant([[0, 1, 2, 3, 4, 5]]							)
            _A=						model(lowerCAmelCase__							)[0]

            _A=						[1, 6, 30000]
            self.assertEqual(output.shape					,   lowerCAmelCase__							)

            _A=						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]					,   lowerCAmelCase__					,   atol=1E-4							)
from __future__ import annotations

def 				UpperCamelCase					(     lowerCAmelCase_ )		->    set[int]:




       '''simple docstring'''






       _A=						{1}
       _A=						[1]
       for _ in range(2							,       depth + 1 ):
              _A=						[*previous_coefficients, 0]
              _A=						[0, *previous_coefficients]
              _A=						[]
              for x, y in zip(lowerCAmelCase_							,       lowerCAmelCase_ ):
                     coefficients.add(x + y )
                     previous_coefficients.append(x + y )
       return coefficients

def 				UpperCamelCase					(     lowerCAmelCase_ )		->    set[int]:




       '''simple docstring'''






       _A=						set()
       for number in unique_coefficients:
              _A=						2
              _A=						number
              while divisor**2 <= copy_number:
                     _A=						0
                     while copy_number % divisor == 0:
                            copy_number //= divisor
                            multiplicity += 1
                     if multiplicity >= 2:
                            non_squarefrees.add(lowerCAmelCase_ )
                            break
                     divisor += 1

       return unique_coefficients.difference(lowerCAmelCase_ )

def 				UpperCamelCase					(     lowerCAmelCase_ = 51 )		->    int:




       '''simple docstring'''






       _A=						get_pascal_triangle_unique_coefficients(lowerCAmelCase_ )
       _A=						get_squarefrees(lowerCAmelCase_ )
       return sum(lowerCAmelCase_ )


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