






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        snake_case_					(						__UpperCamelCase			):

						"""simple docstring"""



						def __init__(self:				str   ,				__UpperCAmelCase:				str   ,				)						->    str:




											'''simple docstring'''



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



						def 					UpperCAmelCase__				(self:				List[Any]      )						->    Tuple:




											'''simple docstring'''



											__a				:	List[str]			=				ids_tensor([self.batch_size, self.seq_length]   ,				self.vocab_size      )

											__a				:	Dict			=				None
											if self.use_input_mask:
																__a				:	Union[str, Any]			=				random_attention_mask([self.batch_size, self.seq_length]      )

											__a				:	List[str]			=				None
											if self.use_token_type_ids:
																__a				:	List[Any]			=				ids_tensor([self.batch_size, self.seq_length]   ,				self.type_vocab_size      )

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

											__a				:	Any			=				None
											__a				:	Optional[Any]			=				None
											__a				:	Tuple			=				None
											if self.use_labels:
																__a				:	List[Any]			=				ids_tensor([self.batch_size]   ,				self.type_sequence_label_size      )
																__a				:	Dict			=				ids_tensor([self.batch_size, self.seq_length]   ,				self.num_labels      )
																__a				:	Any			=				ids_tensor([self.batch_size]   ,				self.num_choices      )

											__a				:	Any			=				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				:	Tuple			=				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:				Optional[Any]   ,				__UpperCAmelCase:				Union[str, Any]   ,				__UpperCAmelCase:				Union[str, Any]   ,				__UpperCAmelCase:				List[Any]   ,				__UpperCAmelCase:				Union[str, Any]   ,				__UpperCAmelCase:				int   ,				*__UpperCAmelCase:				List[Any]      )						->    Optional[int]:




											'''simple docstring'''



											__a				:	List[Any]			=				TFCTRLModel(config=__UpperCAmelCase      )
											__a				:	int			=				{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
											__a				:	Optional[Any]			=				model(__UpperCAmelCase      )

											__a				:	Tuple			=				[input_ids, None, input_mask]  # None is the input for 'past'
											__a				:	Optional[int]			=				model(__UpperCAmelCase      )

											__a				:	Optional[Any]			=				model(__UpperCAmelCase      )

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



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




											'''simple docstring'''



											__a				:	List[Any]			=				TFCTRLLMHeadModel(config=__UpperCAmelCase      )
											__a				:	str			=				{"input_ids": input_ids, "attention_mask": input_mask, "token_type_ids": token_type_ids}
											__a				:	List[str]			=				model(__UpperCAmelCase      )
											self.parent.assertEqual(result.logits.shape   ,				(self.batch_size, self.seq_length, self.vocab_size)      )



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




											'''simple docstring'''



											__a				:	List[Any]			=				self.num_labels
											__a				:	int			=				ids_tensor([self.batch_size]   ,				self.type_sequence_label_size      )
											__a				:	Any			=				{
											    "input_ids": input_ids,
											    "token_type_ids": token_type_ids,
											    "labels": sequence_labels,
											}
											__a				:	Any			=				TFCTRLForSequenceClassification(__UpperCAmelCase      )
											__a				:	Optional[int]			=				model(__UpperCAmelCase      )
											self.parent.assertEqual(result.logits.shape   ,				(self.batch_size, self.num_labels)      )



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




											'''simple docstring'''



											__a				:	List[str]			=				self.prepare_config_and_inputs()

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

											__a				:	List[str]			=				{"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
											return config, inputs_dict




@require_tf
class        snake_case_					(						__UpperCamelCase		,       __UpperCamelCase		,       unittest.TestCase			):

						"""simple docstring"""



						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:				Optional[Any]   ,				__UpperCAmelCase:				Tuple   ,				__UpperCAmelCase:				str   ,				__UpperCAmelCase:				Union[str, Any]   ,				__UpperCAmelCase:				Optional[int]   ,				__UpperCAmelCase:				str      )						->    Union[str, 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:				List[str]      )						->    str:




											'''simple docstring'''



											__a				:	int			=				TFCTRLModelTester(self      )
											__a				:	List[str]			=				ConfigTester(self   ,				config_class=__UpperCAmelCase   ,				n_embd=37      )



						def 					UpperCAmelCase__				(self:				Dict      )						->    List[Any]:




											'''simple docstring'''



											self.config_tester.run_common_tests()



						def 					UpperCAmelCase__				(self:				Dict      )						->    Union[str, Any]:




											'''simple docstring'''



											__a				:	Optional[int]			=				self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_ctrl_model(*__UpperCAmelCase      )



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




											'''simple docstring'''



											__a				:	Optional[Any]			=				self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_ctrl_lm_head(*__UpperCAmelCase      )



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




											'''simple docstring'''



											__a				:	Union[str, Any]			=				self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_ctrl_for_sequence_classification(*__UpperCAmelCase      )



						def 					UpperCAmelCase__				(self:				Dict      )						->    Optional[int]:




											'''simple docstring'''



											__a			, __a				:	List[Any]			=				self.model_tester.prepare_config_and_inputs_for_common()
											__a				:	int			=				[TFCTRLLMHeadModel]
											__a				:	int			=				[TFCTRLForSequenceClassification]

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



						@slow
						def 					UpperCAmelCase__				(self:				Tuple      )						->    Optional[int]:




											'''simple docstring'''



											for model_name in TF_CTRL_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																__a				:	Optional[Any]			=				TFCTRLModel.from_pretrained(__UpperCAmelCase      )
																self.assertIsNotNone(__UpperCAmelCase      )




@require_tf
class        snake_case_					(						unittest.TestCase			):

						"""simple docstring"""



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




											'''simple docstring'''



											__a				:	Optional[int]			=				TFCTRLLMHeadModel.from_pretrained("ctrl"      )
											__a				:	List[str]			=				tf.convert_to_tensor([[11859, 0, 1611, 8]]   ,				dtype=tf.intaa      )  # Legal the president is
											__a				:	Union[str, Any]			=				[
											    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

											__a				:	Any			=				model.generate(__UpperCAmelCase   ,				do_sample=__UpperCAmelCase      )
											self.assertListEqual(output_ids[0].numpy().tolist()   ,				__UpperCAmelCase      )













import math







def 						a_      (__A			)							->	bool:



					"""simple docstring"""

					if 1 < number < 4:
										# 2 and 3 are primes
										return True
					elif number < 2 or number % 2 == 0 or number % 3 == 0:
										# Negatives, 0, 1, all even numbers, all multiples of 3 are not primes
										return False

					# All primes number are in format of 6k +/- 1
					for i in range(5							,					int(math.sqrt(__A			) + 1			)							,					6			):
										if number % i == 0 or number % (i + 2) == 0:
															return False
					return True







def 						a_      (__A = 1_000							,					__A = 1_000			)							->	int:



					"""simple docstring"""
					__a				:	Optional[int]			=				[0, 0, 0]  # length, a, b
					for a in range((a_limit * -1) + 1							,					__A			):
										for b in range(2							,					__A			):
															if is_prime(__A			):
																				__a				:	Any			=				0
																				__a				:	List[str]			=				0
																				while is_prime((n**2) + (a * n) + b			):
																									count += 1
																									n += 1
																				if count > longest[0]:
																									__a				:	Any			=				[count, a, b]
					__a				:	str			=				longest[1] * longest[2]
					return ans


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





