



import gc
import unittest

from transformers import CTRLConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
						import torch

						from transformers import (
						    CTRL_PRETRAINED_MODEL_ARCHIVE_LIST,
						    CTRLForSequenceClassification,
						    CTRLLMHeadModel,
						    CTRLModel,
						)

class       _SCREAMING_SNAKE_CASE	:





					def __init__(       self :							int     ,  UpperCamelCase :							Union[str, Any]     ,  UpperCamelCase :							Optional[int]=1_4     ,  UpperCamelCase :							int=7     ,  UpperCamelCase :							Optional[Any]=True     ,  UpperCamelCase :							Dict=True     ,  UpperCamelCase :							Dict=True     ,  UpperCamelCase :							str=True     ,  UpperCamelCase :							List[Any]=True     ,  UpperCamelCase :							str=9_9     ,  UpperCamelCase :							List[str]=3_2     ,  UpperCamelCase :							Any=5     ,  UpperCamelCase :							Union[str, Any]=4     ,  UpperCamelCase :							Any=3_7     ,  UpperCamelCase :							List[Any]="gelu"     ,  UpperCamelCase :							Tuple=0.1     ,  UpperCamelCase :							Tuple=0.1     ,  UpperCamelCase :							Optional[int]=5_1_2     ,  UpperCamelCase :							List[Any]=1_6     ,  UpperCamelCase :							Optional[int]=2     ,  UpperCamelCase :							Union[str, Any]=0.0_2     ,  UpperCamelCase :							Tuple=3     ,  UpperCamelCase :							Union[str, Any]=4     ,  UpperCamelCase :							str=None     ,  )->Dict:
						__SCREAMING_SNAKE_CASE       :    List[str]       =	parent
						__SCREAMING_SNAKE_CASE       :    Dict       =	batch_size
						__SCREAMING_SNAKE_CASE       :    Tuple       =	seq_length
						__SCREAMING_SNAKE_CASE       :    Union[str, Any]       =	is_training
						__SCREAMING_SNAKE_CASE       :    int       =	use_token_type_ids
						__SCREAMING_SNAKE_CASE       :    Any       =	use_input_mask
						__SCREAMING_SNAKE_CASE       :    List[str]       =	use_labels
						__SCREAMING_SNAKE_CASE       :    Optional[Any]       =	use_mc_token_ids
						__SCREAMING_SNAKE_CASE       :    Tuple       =	vocab_size
						__SCREAMING_SNAKE_CASE       :    Union[str, Any]       =	hidden_size
						__SCREAMING_SNAKE_CASE       :    Optional[int]       =	num_hidden_layers
						__SCREAMING_SNAKE_CASE       :    Any       =	num_attention_heads
						__SCREAMING_SNAKE_CASE       :    Optional[int]       =	intermediate_size
						__SCREAMING_SNAKE_CASE       :    Any       =	hidden_act
						__SCREAMING_SNAKE_CASE       :    int       =	hidden_dropout_prob
						__SCREAMING_SNAKE_CASE       :    List[Any]       =	attention_probs_dropout_prob
						__SCREAMING_SNAKE_CASE       :    Any       =	max_position_embeddings
						__SCREAMING_SNAKE_CASE       :    str       =	type_vocab_size
						__SCREAMING_SNAKE_CASE       :    List[Any]       =	type_sequence_label_size
						__SCREAMING_SNAKE_CASE       :    List[Any]       =	initializer_range
						__SCREAMING_SNAKE_CASE       :    Optional[int]       =	num_labels
						__SCREAMING_SNAKE_CASE       :    Optional[Any]       =	num_choices
						__SCREAMING_SNAKE_CASE       :    str       =	scope
						__SCREAMING_SNAKE_CASE       :    Union[str, Any]       =	self.vocab_size - 1





					def 	__snake_case    (       self :							str				)->Optional[int]:
						__SCREAMING_SNAKE_CASE       :    Tuple       =	ids_tensor([self.batch_size, self.seq_length]     ,  self.vocab_size				)

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

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

						__SCREAMING_SNAKE_CASE       :    Union[str, Any]       =	None
						if self.use_mc_token_ids:
							__SCREAMING_SNAKE_CASE       :    str       =	ids_tensor([self.batch_size, self.num_choices]     ,  self.seq_length				)

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

						__SCREAMING_SNAKE_CASE       :    List[str]       =	self.get_config()

						__SCREAMING_SNAKE_CASE       :    Optional[Any]       =	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 	__snake_case    (       self :							List[str]				)->List[Any]:
						return 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     ,  )





					def 	__snake_case    (       self :							str     ,  UpperCamelCase :							Optional[Any]     ,  UpperCamelCase :							Tuple     ,  UpperCamelCase :							Tuple     ,  UpperCamelCase :							Tuple     ,  UpperCamelCase :							Optional[int]     ,  *UpperCamelCase :							int				)->Optional[int]:
						__SCREAMING_SNAKE_CASE       :    List[Any]       =	CTRLModel(config=UpperCamelCase				)
						model.to(UpperCamelCase				)
						model.eval()

						model(UpperCamelCase     ,  token_type_ids=UpperCamelCase     ,  head_mask=UpperCamelCase				)
						model(UpperCamelCase     ,  token_type_ids=UpperCamelCase				)
						__SCREAMING_SNAKE_CASE       :    Any       =	model(UpperCamelCase				)
						self.parent.assertEqual(result.last_hidden_state.shape     ,  (self.batch_size, self.seq_length, self.hidden_size)				)
						self.parent.assertEqual(len(result.past_key_values				)     ,  config.n_layer				)





					def 	__snake_case    (       self :							Union[str, Any]     ,  UpperCamelCase :							List[str]     ,  UpperCamelCase :							List[str]     ,  UpperCamelCase :							Any     ,  UpperCamelCase :							Optional[int]     ,  UpperCamelCase :							Optional[Any]     ,  *UpperCamelCase :							Optional[Any]				)->List[Any]:
						__SCREAMING_SNAKE_CASE       :    List[str]       =	CTRLLMHeadModel(UpperCamelCase				)
						model.to(UpperCamelCase				)
						model.eval()

						__SCREAMING_SNAKE_CASE       :    Optional[int]       =	model(UpperCamelCase     ,  token_type_ids=UpperCamelCase     ,  labels=UpperCamelCase				)
						self.parent.assertEqual(result.loss.shape     ,  ()				)
						self.parent.assertEqual(result.logits.shape     ,  (self.batch_size, self.seq_length, self.vocab_size)				)





					def 	__snake_case    (       self :							Optional[int]				)->str:
						__SCREAMING_SNAKE_CASE       :    int       =	self.prepare_config_and_inputs()

						(
						    __SCREAMING_SNAKE_CASE		
						)       :    Tuple       =	config_and_inputs

						__SCREAMING_SNAKE_CASE       :    List[str]       =	{"input_ids": input_ids, "token_type_ids": token_type_ids, "head_mask": head_mask}

						return config, inputs_dict






					def 	__snake_case    (       self :							Optional[Any]     ,  UpperCamelCase :							Optional[Any]     ,  UpperCamelCase :							Union[str, Any]     ,  UpperCamelCase :							Union[str, Any]     ,  UpperCamelCase :							Optional[Any]     ,  *UpperCamelCase :							List[Any]				)->List[Any]:
						__SCREAMING_SNAKE_CASE       :    int       =	self.num_labels
						__SCREAMING_SNAKE_CASE       :    Optional[Any]       =	CTRLForSequenceClassification(UpperCamelCase				)
						model.to(UpperCamelCase				)
						model.eval()
						__SCREAMING_SNAKE_CASE       :    List[Any]       =	ids_tensor([self.batch_size]     ,  self.type_sequence_label_size				)
						__SCREAMING_SNAKE_CASE       :    str       =	model(UpperCamelCase     ,  token_type_ids=UpperCamelCase     ,  labels=UpperCamelCase				)
						self.parent.assertEqual(result.logits.shape     ,  (self.batch_size, self.num_labels)				)






@require_torch
class       _SCREAMING_SNAKE_CASE	(UpperCamelCase			,    UpperCamelCase			,    UpperCamelCase			,    unittest.TestCase ):
					lowerCAmelCase					=			(CTRLModel, CTRLLMHeadModel, CTRLForSequenceClassification) if is_torch_available() else ()
					lowerCAmelCase					=			(CTRLLMHeadModel,) if is_torch_available() else ()
					lowerCAmelCase					=			(
					    {
					        """feature-extraction""": CTRLModel,
					        """text-classification""": CTRLForSequenceClassification,
					        """text-generation""": CTRLLMHeadModel,
					        """zero-shot""": CTRLForSequenceClassification,
					    }
					    if is_torch_available()
					    else {}
					)
					lowerCAmelCase					=			True
					lowerCAmelCase					=			False
					lowerCAmelCase					=			False





					def 	__snake_case    (       self :							List[str]     ,  UpperCamelCase :							int     ,  UpperCamelCase :							Optional[int]     ,  UpperCamelCase :							str     ,  UpperCamelCase :							Any     ,  UpperCamelCase :							Optional[Any]				)->Optional[int]:
						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 	__snake_case    (       self :							List[str]				)->str:
						__SCREAMING_SNAKE_CASE       :    List[str]       =	CTRLModelTester(self				)
						__SCREAMING_SNAKE_CASE       :    Any       =	ConfigTester(self     ,  config_class=UpperCamelCase     ,  n_embd=3_7				)





					def 	__snake_case    (       self :							Union[str, Any]				)->Optional[int]:
						super().tearDown()
						# clean-up as much as possible GPU memory occupied by PyTorch
						gc.collect()
						torch.cuda.empty_cache()





					def 	__snake_case    (       self :							List[str]				)->Optional[Any]:
						self.config_tester.run_common_tests()





					def 	__snake_case    (       self :							Any				)->List[str]:
						__SCREAMING_SNAKE_CASE       :    str       =	self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_ctrl_model(*UpperCamelCase				)





					def 	__snake_case    (       self :							Optional[int]				)->Tuple:
						__SCREAMING_SNAKE_CASE       :    Union[str, Any]       =	self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_lm_head_model(*UpperCamelCase				)





					@unittest.skip("Will be fixed soon by reducing the size of the model used for common tests."				)
					def 	__snake_case    (       self :							Optional[int]				)->Any:
						pass





					@slow
					def 	__snake_case    (       self :							Optional[Any]				)->Optional[Any]:
						for model_name in CTRL_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
							__SCREAMING_SNAKE_CASE       :    Dict       =	CTRLModel.from_pretrained(UpperCamelCase				)
							self.assertIsNotNone(UpperCamelCase				)






					@unittest.skip("The model doesn't support left padding"				)  # and it's not used enough to be worth fixing :)
					def 	__snake_case    (       self :							List[Any]				)->List[str]:
						pass






@require_torch
class       _SCREAMING_SNAKE_CASE	(unittest.TestCase ):





					def 	__snake_case    (       self :							Optional[int]				)->Optional[Any]:
						super().tearDown()
						# clean-up as much as possible GPU memory occupied by PyTorch
						gc.collect()
						torch.cuda.empty_cache()






					@slow
					def 	__snake_case    (       self :							List[str]				)->Optional[int]:
						__SCREAMING_SNAKE_CASE       :    Tuple       =	CTRLLMHeadModel.from_pretrained("ctrl"				)
						model.to(UpperCamelCase				)
						__SCREAMING_SNAKE_CASE       :    Optional[Any]       =	torch.tensor(
						    [[1_1_8_5_9, 0, 1_6_1_1, 8]]     ,  dtype=torch.long     ,  device=UpperCamelCase				)  # Legal the president is
						__SCREAMING_SNAKE_CASE       :    List[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

						__SCREAMING_SNAKE_CASE       :    Optional[int]       =	model.generate(UpperCamelCase     ,  do_sample=UpperCamelCase				)
						self.assertListEqual(output_ids[0].tolist()     ,  UpperCamelCase				)











from math import sqrt






def 	_lowerCAmelCase						(				__lowerCamelCase   :     int = 1000000     ):



 """simple docstring"""





 __SCREAMING_SNAKE_CASE       :    int       =	0
 __SCREAMING_SNAKE_CASE       :    int       =	0
 __SCREAMING_SNAKE_CASE       :    int

 while num_cuboids <= limit:
  max_cuboid_size += 1
  for sum_shortest_sides in range(2		,	2 * max_cuboid_size + 1     ):
   if sqrt(sum_shortest_sides**2 + max_cuboid_size**2     ).is_integer():
    num_cuboids += (
        min(__lowerCamelCase		,	sum_shortest_sides // 2     )
        - max(1		,	sum_shortest_sides - max_cuboid_size     )
        + 1
    )

 return max_cuboid_size


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






