


'''simple docstring'''







from __future__ import annotations

import unittest

from transformers import CTRLConfig, is_tf_available
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.models.ctrl.modeling_tf_ctrl import (
       TF_CTRL_PRETRAINED_MODEL_ARCHIVE_LIST,
       TFCTRLForSequenceClassification,
       TFCTRLLMHeadModel,
       TFCTRLModel,
   )







class A__	(						UpperCAmelCase__				):






      def __init__(			self      :List[str]					,						SCREAMING_SNAKE_CASE      :Any					,						)	-> Any:




             '''simple docstring'''
             _a   :			Tuple					 =parent
             _a   :			Dict					 =1_3
             _a   :			Dict					 =7
             _a   :			List[str]					 =True
             _a   :			List[str]					 =True
             _a   :			Optional[int]					 =True
             _a   :			Optional[Any]					 =True
             _a   :			Optional[Any]					 =True
             _a   :			Dict					 =9_9
             _a   :			Dict					 =3_2
             _a   :			List[Any]					 =2
             _a   :			Union[str, Any]					 =4
             _a   :			List[str]					 =3_7
             _a   :			Optional[Any]					 ="""gelu"""
             _a   :			Tuple					 =0.1
             _a   :			Optional[Any]					 =0.1
             _a   :			List[str]					 =5_1_2
             _a   :			List[Any]					 =1_6
             _a   :			int					 =2
             _a   :			Tuple					 =0.02
             _a   :			List[str]					 =3
             _a   :			Any					 =4
             _a   :			str					 =None
             _a   :			str					 =self.vocab_size - 1






      def __UpperCAmelCase	(			self      :Dict     )	-> Optional[Any]:




             '''simple docstring'''
             _a   :			str					 =ids_tensor([self.batch_size, self.seq_length]					,						self.vocab_size     )

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

             _a   :			Optional[int]					 =None
             if self.use_token_type_ids:
                    _a   :			List[str]					 =ids_tensor([self.batch_size, self.seq_length]					,						self.type_vocab_size     )

             _a   :			Any					 =None
             if self.use_mc_token_ids:
                    _a   :			Optional[int]					 =ids_tensor([self.batch_size, self.num_choices]					,						self.seq_length     )

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

             _a   :			List[str]					 =CTRLConfig(
                 vocab_size=self.vocab_size					,						n_embd=self.hidden_size					,						n_layer=self.num_hidden_layers					,						n_head=self.num_attention_heads					,						n_positions=self.max_position_embeddings					,						pad_token_id=self.pad_token_id					,						)

             _a   :			List[str]					 =ids_tensor([self.num_hidden_layers, self.num_attention_heads]					,						2     )

             return (
                 config,
                 input_ids,
                 input_mask,
                 head_mask,
                 token_type_ids,
                 mc_token_ids,
                 sequence_labels,
                 token_labels,
                 choice_labels,
             )






      def __UpperCAmelCase	(			self      :Dict					,						SCREAMING_SNAKE_CASE      :Tuple					,						SCREAMING_SNAKE_CASE      :List[Any]					,						SCREAMING_SNAKE_CASE      :Tuple					,						SCREAMING_SNAKE_CASE      :List[Any]					,						SCREAMING_SNAKE_CASE      :Optional[Any]					,						*SCREAMING_SNAKE_CASE      :Any     )	-> Tuple:




             '''simple docstring'''
             _a   :			Dict					 =TFCTRLModel(config=SCREAMING_SNAKE_CASE     )
             _a   :			Any					 ={"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
             _a   :			int					 =model(SCREAMING_SNAKE_CASE     )

             _a   :			List[str]					 =[input_ids, None, input_mask]  # None is the input for 'past'
             _a   :			List[Any]					 =model(SCREAMING_SNAKE_CASE     )

             _a   :			Optional[int]					 =model(SCREAMING_SNAKE_CASE     )

             self.parent.assertEqual(result.last_hidden_state.shape					,						(self.batch_size, self.seq_length, self.hidden_size)     )






      def __UpperCAmelCase	(			self      :Optional[int]					,						SCREAMING_SNAKE_CASE      :Tuple					,						SCREAMING_SNAKE_CASE      :Any					,						SCREAMING_SNAKE_CASE      :str					,						SCREAMING_SNAKE_CASE      :str					,						SCREAMING_SNAKE_CASE      :Optional[int]					,						*SCREAMING_SNAKE_CASE      :int     )	-> List[str]:




             '''simple docstring'''
             _a   :			int					 =TFCTRLLMHeadModel(config=SCREAMING_SNAKE_CASE     )
             _a   :			Any					 ={"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
             _a   :			List[Any]					 =model(SCREAMING_SNAKE_CASE     )
             self.parent.assertEqual(result.logits.shape					,						(self.batch_size, self.seq_length, self.vocab_size)     )






      def __UpperCAmelCase	(			self      :Tuple					,						SCREAMING_SNAKE_CASE      :Any					,						SCREAMING_SNAKE_CASE      :Dict					,						SCREAMING_SNAKE_CASE      :List[Any]					,						SCREAMING_SNAKE_CASE      :int					,						SCREAMING_SNAKE_CASE      :str					,						*SCREAMING_SNAKE_CASE      :Optional[Any]     )	-> int:




             '''simple docstring'''
             _a   :			Dict					 =self.num_labels
             _a   :			int					 =ids_tensor([self.batch_size]					,						self.type_sequence_label_size     )
             _a   :			Optional[int]					 ={
                 """input_ids""": input_ids,
                 """token_type_ids""": token_type_ids,
                 """labels""": sequence_labels,
             }
             _a   :			Optional[Any]					 =TFCTRLForSequenceClassification(SCREAMING_SNAKE_CASE     )
             _a   :			List[str]					 =model(SCREAMING_SNAKE_CASE     )
             self.parent.assertEqual(result.logits.shape					,						(self.batch_size, self.num_labels)     )






      def __UpperCAmelCase	(			self      :Any     )	-> Dict:




             '''simple docstring'''
             _a   :			str					 =self.prepare_config_and_inputs()

             (
                 (
                 _a
             ) ,   (
                 _a
             ) ,   (
                 _a
             ) ,   (
                 _a
             ) ,   (
                 _a
             ) ,   (
                 _a
             ) ,   (
                 _a
             ) ,   (
                 _a
             ) ,   (
                 _a
             ) ,   
             )   :			Tuple					 =config_and_inputs

             _a   :			Dict					 ={"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
             return config, inputs_dict







@require_tf
class A__	(						UpperCAmelCase__			,					UpperCAmelCase__			,					unittest.TestCase				):
      __UpperCamelCase	:  Any     	=							(TFCTRLModel, TFCTRLLMHeadModel, TFCTRLForSequenceClassification) if is_tf_available() else ()
      __UpperCamelCase	:  Optional[Any]     	=							(TFCTRLLMHeadModel,) if is_tf_available() else ()
      __UpperCamelCase	:  Dict     	=							(
          {
              "feature-extraction": TFCTRLModel,
              "text-classification": TFCTRLForSequenceClassification,
              "text-generation": TFCTRLLMHeadModel,
              "zero-shot": TFCTRLForSequenceClassification,
          }
          if is_tf_available()
          else {}
      )
      __UpperCamelCase	:  Dict     	=							False
      __UpperCamelCase	:  Union[str, Any]     	=							False






      def __UpperCAmelCase	(			self      :Optional[int]					,						SCREAMING_SNAKE_CASE      :Optional[Any]					,						SCREAMING_SNAKE_CASE      :Dict					,						SCREAMING_SNAKE_CASE      :List[Any]					,						SCREAMING_SNAKE_CASE      :Optional[Any]					,						SCREAMING_SNAKE_CASE      :int     )	-> Optional[Any]:




             '''simple docstring'''
             if pipeline_test_casse_name == "ZeroShotClassificationPipelineTests":
                    # Get `tokenizer does not have a padding token` error for both fast/slow tokenizers.
                    # `CTRLConfig` was never used in pipeline tests, either because of a missing checkpoint or because a tiny
                    # config could not be created.
                    return True

             return False






      def __UpperCAmelCase	(			self      :str     )	-> List[Any]:




             '''simple docstring'''
             _a   :			Dict					 =TFCTRLModelTester(self     )
             _a   :			int					 =ConfigTester(self					,						config_class=SCREAMING_SNAKE_CASE					,						n_embd=3_7     )






      def __UpperCAmelCase	(			self      :int     )	-> List[str]:




             '''simple docstring'''
             self.config_tester.run_common_tests()






      def __UpperCAmelCase	(			self      :Optional[int]     )	-> List[str]:




             '''simple docstring'''
             _a   :			Dict					 =self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_ctrl_model(*SCREAMING_SNAKE_CASE     )






      def __UpperCAmelCase	(			self      :List[Any]     )	-> str:




             '''simple docstring'''
             _a   :			Tuple					 =self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_ctrl_lm_head(*SCREAMING_SNAKE_CASE     )






      def __UpperCAmelCase	(			self      :List[str]     )	-> Tuple:




             '''simple docstring'''
             _a   :			List[str]					 =self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_ctrl_for_sequence_classification(*SCREAMING_SNAKE_CASE     )






      def __UpperCAmelCase	(			self      :Optional[Any]     )	-> str:




             '''simple docstring'''
             _a ,   _a   :			List[str]					 =self.model_tester.prepare_config_and_inputs_for_common()
             _a   :			Any					 =[TFCTRLLMHeadModel]
             _a   :			str					 =[TFCTRLForSequenceClassification]

             for model_class in self.all_model_classes:
                    _a   :			int					 =model_class(SCREAMING_SNAKE_CASE     )
                    model.build()  # may be needed for the get_bias() call below
                    assert isinstance(model.get_input_embeddings()					,						tf.keras.layers.Layer     )

                    if model_class in list_lm_models:
                           _a   :			List[str]					 =model.get_output_embeddings()
                           assert isinstance(SCREAMING_SNAKE_CASE					,						tf.keras.layers.Layer     )
                           _a   :			List[Any]					 =model.get_bias()
                           assert isinstance(SCREAMING_SNAKE_CASE					,						SCREAMING_SNAKE_CASE     )
                           for k, v in name.items():
                                  assert isinstance(SCREAMING_SNAKE_CASE					,						tf.Variable     )
                    elif model_class in list_other_models_with_output_ebd:
                           _a   :			int					 =model.get_output_embeddings()
                           assert isinstance(SCREAMING_SNAKE_CASE					,						tf.keras.layers.Layer     )
                           _a   :			Tuple					 =model.get_bias()
                           assert name is None
                    else:
                           _a   :			Any					 =model.get_output_embeddings()
                           assert x is None
                           _a   :			Optional[Any]					 =model.get_bias()
                           assert name is None






      @slow
      def __UpperCAmelCase	(			self      :List[Any]     )	-> str:




             '''simple docstring'''
             for model_name in TF_CTRL_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                    _a   :			int					 =TFCTRLModel.from_pretrained(SCREAMING_SNAKE_CASE     )
                    self.assertIsNotNone(SCREAMING_SNAKE_CASE     )







@require_tf
class A__	(						unittest.TestCase				):






      @slow
      def __UpperCAmelCase	(			self      :Optional[Any]     )	-> str:




             '''simple docstring'''
             _a   :			Any					 =TFCTRLLMHeadModel.from_pretrained("""ctrl"""     )
             _a   :			int					 =tf.convert_to_tensor([[1_1_8_5_9, 0, 1_6_1_1, 8]]					,						dtype=tf.intaa     )  # Legal the president is
             _a   :			List[str]					 =[
                 1_1_8_5_9,
                 0,
                 1_6_1_1,
                 8,
                 5,
                 1_5_0,
                 2_6_4_4_9,
                 2,
                 1_9,
                 3_4_8,
                 4_6_9,
                 3,
                 2_5_9_5,
                 4_8,
                 2_0_7_4_0,
                 2_4_6_5_3_3,
                 2_4_6_5_3_3,
                 1_9,
                 3_0,
                 5,
             ]  # Legal the president is a good guy and I don't want to lose my job. \n \n I have a

             _a   :			List[str]					 =model.generate(SCREAMING_SNAKE_CASE					,						do_sample=SCREAMING_SNAKE_CASE     )
             self.assertListEqual(output_ids[0].numpy().tolist()					,						SCREAMING_SNAKE_CASE     )






'''simple docstring'''







import math


def      SCREAMING_SNAKE_CASE_ (  _UpperCAmelCase     :     int  )  ->      int:
       return sum(int(_UpperCAmelCase  ) for digit in str(_UpperCAmelCase  )  )


def      SCREAMING_SNAKE_CASE_ (  _UpperCAmelCase     :     int = 30  )  ->      int:
       _a   :			List[Any]					 =[]
       for digit in range(2   ,100  ):
              for power in range(2   ,100  ):
                     _a   :			Optional[Any]					 =int(math.pow(_UpperCAmelCase   ,_UpperCAmelCase  )  )
                     if digit == digit_sum(_UpperCAmelCase  ):
                            digit_to_powers.append(_UpperCAmelCase  )

       digit_to_powers.sort()
       return digit_to_powers[n - 1]


if __name__ == "__main__":
   print(solution())


