





'''simple docstring'''


import unittest

from transformers import 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
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
				import torch

				from transformers import (
				    OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST,
				    OpenAIGPTConfig,
				    OpenAIGPTDoubleHeadsModel,
				    OpenAIGPTForSequenceClassification,
				    OpenAIGPTLMHeadModel,
				    OpenAIGPTModel,
				)



class 							__UpperCAmelCase     :







		'''simple docstring'''







		def __init__(self  :					Any					,					_lowerCAmelCase  :					List[str]					,					_lowerCAmelCase  :					Union[str, Any]=13					,					_lowerCAmelCase  :					Optional[int]=7					,					_lowerCAmelCase  :					Tuple=True					,					_lowerCAmelCase  :					Dict=True					,					_lowerCAmelCase  :					str=True					,					_lowerCAmelCase  :					Optional[Any]=99					,					_lowerCAmelCase  :					Optional[Any]=32					,					_lowerCAmelCase  :					List[str]=5					,					_lowerCAmelCase  :					Optional[Any]=4					,					_lowerCAmelCase  :					Optional[Any]=37					,					_lowerCAmelCase  :					List[str]="gelu"					,					_lowerCAmelCase  :					Dict=0.1					,					_lowerCAmelCase  :					int=0.1					,					_lowerCAmelCase  :					List[Any]=512					,					_lowerCAmelCase  :					Dict=16					,					_lowerCAmelCase  :					str=2					,					_lowerCAmelCase  :					List[str]=0.02					,					_lowerCAmelCase  :					Union[str, Any]=3					,					_lowerCAmelCase  :					List[str]=4					,					_lowerCAmelCase  :					str=None					,					):
			A							     =					parent
			A							     =					batch_size
			A							     =					seq_length
			A							     =					is_training
			A							     =					use_token_type_ids
			A							     =					use_labels
			A							     =					vocab_size
			A							     =					hidden_size
			A							     =					num_hidden_layers
			A							     =					num_attention_heads
			A							     =					intermediate_size
			A							     =					hidden_act
			A							     =					hidden_dropout_prob
			A							     =					attention_probs_dropout_prob
			A							     =					max_position_embeddings
			A							     =					type_vocab_size
			A							     =					type_sequence_label_size
			A							     =					initializer_range
			A							     =					num_labels
			A							     =					num_choices
			A							     =					scope
			A							     =					self.vocab_size - 1







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

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

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

			A							     =					OpenAIGPTConfig(
			    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							     =					ids_tensor([self.num_hidden_layers, self.num_attention_heads]					,					2					)

			return (
			    config,
			    input_ids,
			    head_mask,
			    token_type_ids,
			    sequence_labels,
			    token_labels,
			    choice_labels,
			)







		def 				A   (self  :					List[Any]					,					_lowerCAmelCase  :					Optional[Any]					,					_lowerCAmelCase  :					Dict					,					_lowerCAmelCase  :					List[Any]					,					_lowerCAmelCase  :					str					,					*_lowerCAmelCase  :					Dict					):
			A							     =					OpenAIGPTModel(config=__lowerCAmelCase					)
			model.to(__lowerCAmelCase					)
			model.eval()

			A							     =					model(__lowerCAmelCase					,					token_type_ids=__lowerCAmelCase					,					head_mask=__lowerCAmelCase					)
			A							     =					model(__lowerCAmelCase					,					token_type_ids=__lowerCAmelCase					)
			A							     =					model(__lowerCAmelCase					)

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







		def 				A   (self  :					Dict					,					_lowerCAmelCase  :					str					,					_lowerCAmelCase  :					Dict					,					_lowerCAmelCase  :					List[Any]					,					_lowerCAmelCase  :					str					,					*_lowerCAmelCase  :					List[str]					):
			A							     =					OpenAIGPTLMHeadModel(__lowerCAmelCase					)
			model.to(__lowerCAmelCase					)
			model.eval()

			A							     =					model(__lowerCAmelCase					,					token_type_ids=__lowerCAmelCase					,					labels=__lowerCAmelCase					)
			self.parent.assertEqual(result.loss.shape					,					()					)
			self.parent.assertEqual(result.logits.shape					,					(self.batch_size, self.seq_length, self.vocab_size)					)







		def 				A   (self  :					str					,					_lowerCAmelCase  :					Optional[Any]					,					_lowerCAmelCase  :					List[str]					,					_lowerCAmelCase  :					List[str]					,					_lowerCAmelCase  :					Dict					,					*_lowerCAmelCase  :					Union[str, Any]					):
			A							     =					OpenAIGPTDoubleHeadsModel(__lowerCAmelCase					)
			model.to(__lowerCAmelCase					)
			model.eval()

			A							     =					model(__lowerCAmelCase					,					token_type_ids=__lowerCAmelCase					,					labels=__lowerCAmelCase					)
			self.parent.assertEqual(result.loss.shape					,					()					)
			self.parent.assertEqual(result.logits.shape					,					(self.batch_size, self.seq_length, self.vocab_size)					)







		def 				A   (self  :					Optional[Any]					,					_lowerCAmelCase  :					Optional[Any]					,					_lowerCAmelCase  :					Union[str, Any]					,					_lowerCAmelCase  :					Optional[int]					,					_lowerCAmelCase  :					str					,					*_lowerCAmelCase  :					Tuple					):
			A							     =					self.num_labels
			A							     =					OpenAIGPTForSequenceClassification(__lowerCAmelCase					)
			model.to(__lowerCAmelCase					)
			model.eval()

			A							     =					ids_tensor([self.batch_size]					,					self.type_sequence_label_size					)
			A							     =					model(__lowerCAmelCase					,					token_type_ids=__lowerCAmelCase					,					labels=__lowerCAmelCase					)
			self.parent.assertEqual(result.logits.shape					,					(self.batch_size, self.num_labels)					)







		def 				A   (self  :					int					):
			A							     =					self.prepare_config_and_inputs()
			(
			    (
			    A     
			)     ,			(
			    A     
			)     ,			(
			    A     
			)     ,			(
			    A     
			)     ,			(
			    A     
			)     ,			(
			    A     
			)     ,			(
			    A     
			)     ,			     
			)							     =					config_and_inputs
			A							     =					{
			    """input_ids""": input_ids,
			    """token_type_ids""": token_type_ids,
			    """head_mask""": head_mask,
			}

			return config, inputs_dict






@require_torch
class 							__UpperCAmelCase     (				lowerCAmelCase__						,    lowerCAmelCase__						,    lowerCAmelCase__						,    unittest.TestCase  ):







		'''simple docstring'''







		__lowerCAmelCase        =			(
		    (OpenAIGPTModel, OpenAIGPTLMHeadModel, OpenAIGPTDoubleHeadsModel, OpenAIGPTForSequenceClassification)
		    if is_torch_available()
		    else ()
		)
		__lowerCAmelCase        =			(
		    (OpenAIGPTLMHeadModel,) if is_torch_available() else ()
		)  # TODO (PVP): Add Double HeadsModel when generate() function is changed accordingly
		__lowerCAmelCase        =			(
		    {
		        '''feature-extraction''': OpenAIGPTModel,
		        '''text-classification''': OpenAIGPTForSequenceClassification,
		        '''text-generation''': OpenAIGPTLMHeadModel,
		        '''zero-shot''': OpenAIGPTForSequenceClassification,
		    }
		    if is_torch_available()
		    else {}
		)







		def 				A   (self  :					Any					,					_lowerCAmelCase  :					List[Any]					,					_lowerCAmelCase  :					Optional[Any]					,					_lowerCAmelCase  :					int					,					_lowerCAmelCase  :					Tuple					,					_lowerCAmelCase  :					str					):


			if pipeline_test_casse_name == "ZeroShotClassificationPipelineTests":
				# Get `tokenizer does not have a padding token` error for both fast/slow tokenizers.
				# `OpenAIGPTConfig` 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 				A   (self  :					str					,					_lowerCAmelCase  :					Any					,					_lowerCAmelCase  :					Optional[int]					,					_lowerCAmelCase  :					Optional[Any]=False					):
			A							     =					super()._prepare_for_class(__lowerCAmelCase					,					__lowerCAmelCase					,					return_labels=__lowerCAmelCase					)

			if return_labels:
				if model_class.__name__ == "OpenAIGPTDoubleHeadsModel":
					A							     =					torch.zeros(
					    (self.model_tester.batch_size, self.model_tester.num_choices, self.model_tester.seq_length)					,					dtype=torch.long					,					device=__lowerCAmelCase					,					)
					A							     =					inputs_dict["""labels"""]
					A							     =					inputs_dict["""labels"""]
					A							     =					torch.zeros(
					    (self.model_tester.batch_size, self.model_tester.num_choices)					,					dtype=torch.long					,					device=__lowerCAmelCase					,					)
					A							     =					torch.zeros(
					    self.model_tester.batch_size					,					dtype=torch.long					,					device=__lowerCAmelCase					)
			return inputs_dict







		def 				A   (self  :					Any					):
			A							     =					OpenAIGPTModelTester(self					)
			A							     =					ConfigTester(self					,					config_class=__lowerCAmelCase					,					n_embd=37					)







		def 				A   (self  :					Any					):
			self.config_tester.run_common_tests()







		def 				A   (self  :					str					):
			A							     =					self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_openai_gpt_model(*__lowerCAmelCase					)







		def 				A   (self  :					Optional[int]					):
			A							     =					self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_lm_head_model(*__lowerCAmelCase					)







		def 				A   (self  :					List[str]					):
			A							     =					self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_double_lm_head_model(*__lowerCAmelCase					)







		def 				A   (self  :					Optional[int]					):
			A							     =					self.model_tester.prepare_config_and_inputs()
			self.model_tester.create_and_check_openai_gpt_for_sequence_classification(*__lowerCAmelCase					)







		@slow
		def 				A   (self  :					str					):


			for model_name in OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
				A							     =					OpenAIGPTModel.from_pretrained(__lowerCAmelCase					)
				self.assertIsNotNone(__lowerCAmelCase					)






@require_torch
class 							__UpperCAmelCase     (				unittest.TestCase  ):







		'''simple docstring'''







		@slow
		def 				A   (self  :					List[Any]					):
			A							     =					OpenAIGPTLMHeadModel.from_pretrained("""openai-gpt"""					)
			model.to(__lowerCAmelCase					)
			A							     =					torch.tensor([[481, 4735, 544]]					,					dtype=torch.long					,					device=__lowerCAmelCase					)  # the president is
			A							     =					[
			    481,
			    4735,
			    544,
			    246,
			    963,
			    870,
			    762,
			    239,
			    244,
			    4_0477,
			    244,
			    249,
			    719,
			    881,
			    487,
			    544,
			    240,
			    244,
			    603,
			    481,
			]  # the president is a very good man. " \n " i\'m sure he is, " said the

			A							     =					model.generate(__lowerCAmelCase					,					do_sample=__lowerCAmelCase					)
			self.assertListEqual(output_ids[0].tolist()					,					__lowerCAmelCase					)


'''simple docstring'''




from math import sqrt






def 				snake_case__							(			_A:					int = 1000000 )    ->	int:

		'''simple docstring'''


		lowerCAmelCase   					=  0
		lowerCAmelCase   					=  0
		lowerCAmelCase   					=  42

		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(_A      ,   sum_shortest_sides // 2 )
								    - max(1      ,   sum_shortest_sides - max_cuboid_size )
								    + 1
								)

		return max_cuboid_size


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




