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







				def __init__(			self     :							Any      ,       lowerCamelCase_     :							Union[str, Any]      ,       ):

					"""simple docstring"""






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







				def 				__UpperCAmelCase       (			self     :							str    ):

					"""simple docstring"""






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

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

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

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

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

					_lowercase			:     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      ,       )

					_lowercase			:     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     :							List[str]      ,       lowerCamelCase_     :							List[str]      ,       lowerCamelCase_     :							str      ,       lowerCamelCase_     :							Dict      ,       lowerCamelCase_     :							List[str]      ,       lowerCamelCase_     :							str      ,       *lowerCamelCase_     :							Optional[Any]    ):

					"""simple docstring"""






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

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

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

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







				def 				__UpperCAmelCase       (			self     :							Tuple      ,       lowerCamelCase_     :							Union[str, Any]      ,       lowerCamelCase_     :							Optional[Any]      ,       lowerCamelCase_     :							List[Any]      ,       lowerCamelCase_     :							List[str]      ,       lowerCamelCase_     :							List[Any]      ,       *lowerCamelCase_     :							List[Any]    ):

					"""simple docstring"""






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







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

					"""simple docstring"""






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







				def 				__UpperCAmelCase       (			self     :							str    ):

					"""simple docstring"""






					_lowercase			:     Dict      					=				self.prepare_config_and_inputs()

					(
					    (
					    _lowercase
					)					,   (
					    _lowercase
					)					,   (
					    _lowercase
					)					,   (
					    _lowercase
					)					,   (
					    _lowercase
					)					,   (
					    _lowercase
					)					,   (
					    _lowercase
					)					,   (
					    _lowercase
					)					,   (
					    _lowercase
					)					,   
					)			:     Optional[int]      					=				config_and_inputs

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



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







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

					"""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     :							Optional[Any]    ):

					"""simple docstring"""






					_lowercase			:     Dict      					=				TFCTRLModelTester(self    )
					_lowercase			:     Tuple      					=				ConfigTester(self      ,       config_class=lowerCamelCase_      ,       n_embd=3_7    )







				def 				__UpperCAmelCase       (			self     :							Any    ):

					"""simple docstring"""






					self.config_tester.run_common_tests()







				def 				__UpperCAmelCase       (			self     :							Dict    ):

					"""simple docstring"""






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







				def 				__UpperCAmelCase       (			self     :							str    ):

					"""simple docstring"""






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







				def 				__UpperCAmelCase       (			self     :							Optional[Any]    ):

					"""simple docstring"""






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







				def 				__UpperCAmelCase       (			self     :							str    ):

					"""simple docstring"""






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

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







				@slow
				def 				__UpperCAmelCase       (			self     :							Optional[int]    ):

					"""simple docstring"""






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



@require_tf
class 			_lowerCamelCase      (unittest.TestCase  ):







				@slow
				def 				__UpperCAmelCase       (			self     :							Dict    ):

					"""simple docstring"""






					_lowercase			:     Any      					=				TFCTRLLMHeadModel.from_pretrained('ctrl'    )
					_lowercase			:     str      					=				tf.convert_to_tensor([[1_1_8_5_9, 0, 1_6_1_1, 8]]      ,       dtype=tf.intaa    )  # Legal the president is
					_lowercase			:     Optional[Any]      					=				[
					    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

					_lowercase			:     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}""")



