


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


							"""simple docstring"""






							def __init__(						self :     Union[str, Any]		, lowerCamelCase_ :     Tuple		, ):
													UpperCAmelCase__		=    parent
													UpperCAmelCase__		=    13
													UpperCAmelCase__		=    7
													UpperCAmelCase__		=    True
													UpperCAmelCase__		=    True
													UpperCAmelCase__		=    True
													UpperCAmelCase__		=    True
													UpperCAmelCase__		=    True
													UpperCAmelCase__		=    99
													UpperCAmelCase__		=    32
													UpperCAmelCase__		=    2
													UpperCAmelCase__		=    4
													UpperCAmelCase__		=    37
													UpperCAmelCase__		=    '''gelu'''
													UpperCAmelCase__		=    0.1
													UpperCAmelCase__		=    0.1
													UpperCAmelCase__		=    512
													UpperCAmelCase__		=    16
													UpperCAmelCase__		=    2
													UpperCAmelCase__		=    0.02
													UpperCAmelCase__		=    3
													UpperCAmelCase__		=    4
													UpperCAmelCase__		=    None
													UpperCAmelCase__		=    self.vocab_size - 1






							def 					lowerCAmelCase     (						self :     Dict				):
													UpperCAmelCase__		=    ids_tensor([self.batch_size, self.seq_length]		, self.vocab_size				)

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

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

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

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

													UpperCAmelCase__		=    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		, )

													UpperCAmelCase__		=    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 					lowerCAmelCase     (						self :     Union[str, Any]		, lowerCamelCase_ :     Dict		, lowerCamelCase_ :     Optional[Any]		, lowerCamelCase_ :     Optional[Any]		, lowerCamelCase_ :     Union[str, Any]		, lowerCamelCase_ :     Union[str, Any]		, *lowerCamelCase_ :     Optional[int]				):
													UpperCAmelCase__		=    TFCTRLModel(config=lowerCamelCase_				)
													UpperCAmelCase__		=    {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
													UpperCAmelCase__		=    model(lowerCamelCase_				)

													UpperCAmelCase__		=    [input_ids, None, input_mask]  # None is the input for 'past'
													UpperCAmelCase__		=    model(lowerCamelCase_				)

													UpperCAmelCase__		=    model(lowerCamelCase_				)

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






							def 					lowerCAmelCase     (						self :     Dict		, lowerCamelCase_ :     Tuple		, lowerCamelCase_ :     List[Any]		, lowerCamelCase_ :     Tuple		, lowerCamelCase_ :     Tuple		, lowerCamelCase_ :     str		, *lowerCamelCase_ :     List[str]				):
													UpperCAmelCase__		=    TFCTRLLMHeadModel(config=lowerCamelCase_				)
													UpperCAmelCase__		=    {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}
													UpperCAmelCase__		=    model(lowerCamelCase_				)
													self.parent.assertEqual(result.logits.shape		, (self.batch_size, self.seq_length, self.vocab_size)				)






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






							def 					lowerCAmelCase     (						self :     Tuple				):
													UpperCAmelCase__		=    self.prepare_config_and_inputs()

													(
													    (
													    UpperCAmelCase__
													)	,				(
													    UpperCAmelCase__
													)	,				(
													    UpperCAmelCase__
													)	,				(
													    UpperCAmelCase__
													)	,				(
													    UpperCAmelCase__
													)	,				(
													    UpperCAmelCase__
													)	,				(
													    UpperCAmelCase__
													)	,				(
													    UpperCAmelCase__
													)	,				(
													    UpperCAmelCase__
													)	,				
													)		=    config_and_inputs

													UpperCAmelCase__		=    {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
													return config, inputs_dict




@require_tf
class 							lowerCamelCase       (			__SCREAMING_SNAKE_CASE				,					__SCREAMING_SNAKE_CASE				,					unittest.TestCase ):


							"""simple docstring"""
							SCREAMING_SNAKE_CASE										=      (TFCTRLModel, TFCTRLLMHeadModel, TFCTRLForSequenceClassification) if is_tf_available() else ()
							SCREAMING_SNAKE_CASE										=      (TFCTRLLMHeadModel,) if is_tf_available() else ()
							SCREAMING_SNAKE_CASE										=      (
							    {
							        """feature-extraction""": TFCTRLModel,
							        """text-classification""": TFCTRLForSequenceClassification,
							        """text-generation""": TFCTRLLMHeadModel,
							        """zero-shot""": TFCTRLForSequenceClassification,
							    }
							    if is_tf_available()
							    else {}
							)
							SCREAMING_SNAKE_CASE										=      False
							SCREAMING_SNAKE_CASE										=      False






							def 					lowerCAmelCase     (						self :     Tuple		, lowerCamelCase_ :     str		, lowerCamelCase_ :     Any		, lowerCamelCase_ :     Tuple		, lowerCamelCase_ :     Optional[int]		, lowerCamelCase_ :     str				):
													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 					lowerCAmelCase     (						self :     Optional[int]				):
													UpperCAmelCase__		=    TFCTRLModelTester(self				)
													UpperCAmelCase__		=    ConfigTester(self		, config_class=lowerCamelCase_		, n_embd=37				)






							def 					lowerCAmelCase     (						self :     Optional[Any]				):
													self.config_tester.run_common_tests()






							def 					lowerCAmelCase     (						self :     Optional[Any]				):
													UpperCAmelCase__		=    self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_ctrl_model(*lowerCamelCase_				)






							def 					lowerCAmelCase     (						self :     Optional[Any]				):
													UpperCAmelCase__		=    self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_ctrl_lm_head(*lowerCamelCase_				)






							def 					lowerCAmelCase     (						self :     str				):
													UpperCAmelCase__		=    self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_ctrl_for_sequence_classification(*lowerCamelCase_				)






							def 					lowerCAmelCase     (						self :     List[str]				):
													UpperCAmelCase__	,				UpperCAmelCase__		=    self.model_tester.prepare_config_and_inputs_for_common()
													UpperCAmelCase__		=    [TFCTRLLMHeadModel]
													UpperCAmelCase__		=    [TFCTRLForSequenceClassification]

													for model_class in self.all_model_classes:
																			UpperCAmelCase__		=    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:
																									UpperCAmelCase__		=    model.get_output_embeddings()
																									assert isinstance(lowerCamelCase_		, tf.keras.layers.Layer				)
																									UpperCAmelCase__		=    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:
																									UpperCAmelCase__		=    model.get_output_embeddings()
																									assert isinstance(lowerCamelCase_		, tf.keras.layers.Layer				)
																									UpperCAmelCase__		=    model.get_bias()
																									assert name is None
																			else:
																									UpperCAmelCase__		=    model.get_output_embeddings()
																									assert x is None
																									UpperCAmelCase__		=    model.get_bias()
																									assert name is None






							@slow
							def 					lowerCAmelCase     (						self :     Dict				):
													for model_name in TF_CTRL_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																			UpperCAmelCase__		=    TFCTRLModel.from_pretrained(lowerCamelCase_				)
																			self.assertIsNotNone(lowerCamelCase_				)




@require_tf
class 							lowerCamelCase       (			unittest.TestCase ):


							"""simple docstring"""






							@slow
							def 					lowerCAmelCase     (						self :     List[str]				):
													UpperCAmelCase__		=    TFCTRLLMHeadModel.from_pretrained('''ctrl'''				)
													UpperCAmelCase__		=    tf.convert_to_tensor([[11859, 0, 1611, 8]]		, dtype=tf.intaa				)  # Legal the president is
													UpperCAmelCase__		=    [
													    11859,
													    0,
													    1611,
													    8,
													    5,
													    150,
													    26449,
													    2,
													    19,
													    348,
													    469,
													    3,
													    2595,
													    48,
													    20740,
													    246533,
													    246533,
													    19,
													    30,
													    5,
													]  # Legal the president is a good guy and I don't want to lose my job. \n \n I have a

													UpperCAmelCase__		=    model.generate(lowerCamelCase_		, do_sample=lowerCamelCase_				)
													self.assertListEqual(output_ids[0].numpy().tolist()		, lowerCamelCase_				)



"""simple docstring"""







from collections import defaultdict






def 					a__ (       _UpperCamelCase = 5 ):





						"""simple docstring"""

						UpperCAmelCase__		=    defaultdict(_UpperCamelCase )
						UpperCAmelCase__		=    0

						while True:
												UpperCAmelCase__		=    get_digits(_UpperCamelCase )
												freqs[digits].append(_UpperCamelCase )

												if len(freqs[digits] ) == max_base:
																		UpperCAmelCase__		=    freqs[digits][0] ** 3
																		return base

												num += 1






def 					a__ (       _UpperCamelCase ):





						"""simple docstring"""

						return "".join(sorted(str(num**3 ) ) )


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