"""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        __SCREAMING_SNAKE_CASE     (   __lowerCamelCase							):







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




									"""simple docstring"""



									lowerCamelCase__		:   List[Any]  				=					parent
									lowerCamelCase__		:   Optional[int]  				=					13
									lowerCamelCase__		:   Tuple  				=					7
									lowerCamelCase__		:   int  				=					True
									lowerCamelCase__		:   Dict  				=					True
									lowerCamelCase__		:   str  				=					True
									lowerCamelCase__		:   int  				=					True
									lowerCamelCase__		:   Optional[Any]  				=					True
									lowerCamelCase__		:   int  				=					99
									lowerCamelCase__		:   List[Any]  				=					32
									lowerCamelCase__		:   Tuple  				=					2
									lowerCamelCase__		:   List[str]  				=					4
									lowerCamelCase__		:   Optional[int]  				=					37
									lowerCamelCase__		:   List[Any]  				=					'gelu'
									lowerCamelCase__		:   Union[str, Any]  				=					0.1
									lowerCamelCase__		:   str  				=					0.1
									lowerCamelCase__		:   Dict  				=					5_12
									lowerCamelCase__		:   Any  				=					16
									lowerCamelCase__		:   Optional[int]  				=					2
									lowerCamelCase__		:   Union[str, Any]  				=					0.02
									lowerCamelCase__		:   List[str]  				=					3
									lowerCamelCase__		:   Dict  				=					4
									lowerCamelCase__		:   Optional[int]  				=					None
									lowerCamelCase__		:   Tuple  				=					self.vocab_size - 1







				def   lowercase_		(    self    :str  )      ->					Tuple:




									"""simple docstring"""



									lowerCamelCase__		:   Tuple  				=					ids_tensor([self.batch_size, self.seq_length]      ,self.vocab_size  )

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

									lowerCamelCase__		:   Any  				=					None
									if self.use_token_type_ids:
														lowerCamelCase__		:   Optional[int]  				=					ids_tensor([self.batch_size, self.seq_length]      ,self.type_vocab_size  )

									lowerCamelCase__		:   Tuple  				=					None
									if self.use_mc_token_ids:
														lowerCamelCase__		:   Any  				=					ids_tensor([self.batch_size, self.num_choices]      ,self.seq_length  )

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

									lowerCamelCase__		:   int  				=					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      ,)

									lowerCamelCase__		:   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   lowercase_		(    self    :List[str]      ,__UpperCAmelCase    :List[str]      ,__UpperCAmelCase    :str      ,__UpperCAmelCase    :Dict      ,__UpperCAmelCase    :List[str]      ,__UpperCAmelCase    :str      ,*__UpperCAmelCase    :Optional[Any]  )      ->					Any:




									"""simple docstring"""



									lowerCamelCase__		:   Optional[Any]  				=					TFCTRLModel(config=lowerCamelCase_  )
									lowerCamelCase__		:   Any  				=					{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
									lowerCamelCase__		:   Optional[int]  				=					model(lowerCamelCase_  )

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

									lowerCamelCase__		:   Union[str, Any]  				=					model(lowerCamelCase_  )

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







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




									"""simple docstring"""



									lowerCamelCase__		:   Optional[int]  				=					TFCTRLLMHeadModel(config=lowerCamelCase_  )
									lowerCamelCase__		:   Dict  				=					{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
									lowerCamelCase__		:   Any  				=					model(lowerCamelCase_  )
									self.parent.assertEqual(result.logits.shape      ,(self.batch_size, self.seq_length, self.vocab_size)  )







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




									"""simple docstring"""



									lowerCamelCase__		:   Union[str, Any]  				=					self.num_labels
									lowerCamelCase__		:   Tuple  				=					ids_tensor([self.batch_size]      ,self.type_sequence_label_size  )
									lowerCamelCase__		:   Tuple  				=					{
									    'input_ids': input_ids,
									    'token_type_ids': token_type_ids,
									    'labels': sequence_labels,
									}
									lowerCamelCase__		:   Union[str, Any]  				=					TFCTRLForSequenceClassification(lowerCamelCase_  )
									lowerCamelCase__		:   Optional[Any]  				=					model(lowerCamelCase_  )
									self.parent.assertEqual(result.logits.shape      ,(self.batch_size, self.num_labels)  )







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




									"""simple docstring"""



									lowerCamelCase__		:   Dict  				=					self.prepare_config_and_inputs()

									(
									    lowerCamelCase__   
									)		:   Optional[int]  				=					config_and_inputs

									lowerCamelCase__		:   List[Any]  				=					{'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
									return config, inputs_dict





@require_tf
class        __SCREAMING_SNAKE_CASE     (   __lowerCamelCase						,       __lowerCamelCase						,       unittest.TestCase							):
				UpperCAmelCase	=      (TFCTRLModel, TFCTRLLMHeadModel, TFCTRLForSequenceClassification) if is_tf_available() else ()
				UpperCAmelCase	=      (TFCTRLLMHeadModel,) if is_tf_available() else ()
				UpperCAmelCase	=      (
				    {
				        '''feature-extraction''': TFCTRLModel,
				        '''text-classification''': TFCTRLForSequenceClassification,
				        '''text-generation''': TFCTRLLMHeadModel,
				        '''zero-shot''': TFCTRLForSequenceClassification,
				    }
				    if is_tf_available()
				    else {}
				)
				UpperCAmelCase	=      False
				UpperCAmelCase	=      False







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




									"""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   lowercase_		(    self    :Optional[Any]  )      ->					Optional[int]:




									"""simple docstring"""



									lowerCamelCase__		:   Dict  				=					TFCTRLModelTester(self  )
									lowerCamelCase__		:   Tuple  				=					ConfigTester(self      ,config_class=lowerCamelCase_      ,n_embd=37  )







				def   lowercase_		(    self    :Any  )      ->					Optional[Any]:




									"""simple docstring"""



									self.config_tester.run_common_tests()







				def   lowercase_		(    self    :Dict  )      ->					List[str]:




									"""simple docstring"""



									lowerCamelCase__		:   List[str]  				=					self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_ctrl_model(*lowerCamelCase_  )







				def   lowercase_		(    self    :str  )      ->					str:




									"""simple docstring"""



									lowerCamelCase__		:   Optional[int]  				=					self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_ctrl_lm_head(*lowerCamelCase_  )







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




									"""simple docstring"""



									lowerCamelCase__		:   int  				=					self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_ctrl_for_sequence_classification(*lowerCamelCase_  )







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




									"""simple docstring"""



									lowerCamelCase__		:   Optional[int]  				=					self.model_tester.prepare_config_and_inputs_for_common()
									lowerCamelCase__		:   Optional[int]  				=					[TFCTRLLMHeadModel]
									lowerCamelCase__		:   Optional[Any]  				=					[TFCTRLForSequenceClassification]

									for model_class in self.all_model_classes:
														lowerCamelCase__		:   Union[str, Any]  				=					model_class(lowerCamelCase_  )
														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:
																			lowerCamelCase__		:   Tuple  				=					model.get_output_embeddings()
																			assert isinstance(lowerCamelCase_      ,tf.keras.layers.Layer  )
																			lowerCamelCase__		:   Dict  				=					model.get_bias()
																			assert isinstance(lowerCamelCase_      ,lowerCamelCase_  )
																			for k, v in name.items():
																								assert isinstance(lowerCamelCase_      ,tf.Variable  )
														elif model_class in list_other_models_with_output_ebd:
																			lowerCamelCase__		:   int  				=					model.get_output_embeddings()
																			assert isinstance(lowerCamelCase_      ,tf.keras.layers.Layer  )
																			lowerCamelCase__		:   Dict  				=					model.get_bias()
																			assert name is None
														else:
																			lowerCamelCase__		:   Optional[Any]  				=					model.get_output_embeddings()
																			assert x is None
																			lowerCamelCase__		:   Tuple  				=					model.get_bias()
																			assert name is None







				@slow
				def   lowercase_		(    self    :Optional[int]  )      ->					str:




									"""simple docstring"""



									for model_name in TF_CTRL_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
														lowerCamelCase__		:   Optional[int]  				=					TFCTRLModel.from_pretrained(lowerCamelCase_  )
														self.assertIsNotNone(lowerCamelCase_  )





@require_tf
class        __SCREAMING_SNAKE_CASE     (   unittest.TestCase							):







				@slow
				def   lowercase_		(    self    :Dict  )      ->					int:




									"""simple docstring"""



									lowerCamelCase__		:   Any  				=					TFCTRLLMHeadModel.from_pretrained('''ctrl'''  )
									lowerCamelCase__		:   str  				=					tf.convert_to_tensor([[1_18_59, 0, 16_11, 8]]      ,dtype=tf.intaa  )  # Legal the president is
									lowerCamelCase__		:   Optional[Any]  				=					[
									    1_18_59,
									    0,
									    16_11,
									    8,
									    5,
									    1_50,
									    2_64_49,
									    2,
									    19,
									    3_48,
									    4_69,
									    3,
									    25_95,
									    48,
									    2_07_40,
									    24_65_33,
									    24_65_33,
									    19,
									    30,
									    5,
									]  # Legal the president is a good guy and I don't want to lose my job. \n \n I have a

									lowerCamelCase__		:   Union[str, Any]  				=					model.generate(lowerCamelCase_      ,do_sample=lowerCamelCase_  )
									self.assertListEqual(output_ids[0].numpy().tolist()      ,lowerCamelCase_  )







"""simple docstring"""







def   __lowerCAmelCase(		__UpperCAmelCase  ,__UpperCAmelCase      ):






	"""simple docstring"""





	if n == 0:
		return 1

	elif n % 2 == 1:
		return binary_exponentiation(__UpperCAmelCase  ,n - 1      ) * a

	else:
		_lowercase			:     Dict      					=				binary_exponentiation(__UpperCAmelCase  ,n / 2      )
		return b * b


if __name__ == "__main__":
						try:
												SCREAMING_SNAKE_CASE						=    int(input('Enter Base : ').strip())
												SCREAMING_SNAKE_CASE						=    int(input('Enter Power : ').strip())
						except ValueError:
												print('Invalid literal for integer')

						SCREAMING_SNAKE_CASE						=    binary_exponentiation(BASE, POWER)
						print(f"""{BASE}^({POWER}) : {RESULT}""")



