



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       _SCREAMING_SNAKE_CASE	:





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





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

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

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

      __SCREAMING_SNAKE_CASE       :    List[str]       =	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     ,  )

      __SCREAMING_SNAKE_CASE       :    Tuple       =	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 	__snake_case    (       self :							Any     ,  UpperCamelCase :							Optional[Any]     ,  UpperCamelCase :							List[Any]     ,  UpperCamelCase :							Tuple     ,  UpperCamelCase :							Tuple     ,  *UpperCamelCase :							Dict				)->List[str]:
      __SCREAMING_SNAKE_CASE       :    Union[str, Any]       =	OpenAIGPTModel(config=UpperCamelCase				)
      model.to(UpperCamelCase				)
      model.eval()

      __SCREAMING_SNAKE_CASE       :    Optional[Any]       =	model(UpperCamelCase     ,  token_type_ids=UpperCamelCase     ,  head_mask=UpperCamelCase				)
      __SCREAMING_SNAKE_CASE       :    int       =	model(UpperCamelCase     ,  token_type_ids=UpperCamelCase				)
      __SCREAMING_SNAKE_CASE       :    int       =	model(UpperCamelCase				)

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





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

      __SCREAMING_SNAKE_CASE       :    Dict       =	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 :							Union[str, Any]     ,  UpperCamelCase :							str     ,  UpperCamelCase :							str     ,  UpperCamelCase :							int     ,  UpperCamelCase :							str     ,  *UpperCamelCase :							List[Any]				)->Any:
      __SCREAMING_SNAKE_CASE       :    Optional[Any]       =	OpenAIGPTDoubleHeadsModel(UpperCamelCase				)
      model.to(UpperCamelCase				)
      model.eval()

      __SCREAMING_SNAKE_CASE       :    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 :							Any     ,  UpperCamelCase :							Union[str, Any]     ,  UpperCamelCase :							Any     ,  UpperCamelCase :							str     ,  UpperCamelCase :							Any     ,  *UpperCamelCase :							List[str]				)->str:
      __SCREAMING_SNAKE_CASE       :    List[Any]       =	self.num_labels
      __SCREAMING_SNAKE_CASE       :    Tuple       =	OpenAIGPTForSequenceClassification(UpperCamelCase				)
      model.to(UpperCamelCase				)
      model.eval()

      __SCREAMING_SNAKE_CASE       :    Any       =	ids_tensor([self.batch_size]     ,  self.type_sequence_label_size				)
      __SCREAMING_SNAKE_CASE       :    int       =	model(UpperCamelCase     ,  token_type_ids=UpperCamelCase     ,  labels=UpperCamelCase				)
      self.parent.assertEqual(result.logits.shape     ,  (self.batch_size, self.num_labels)				)






     def 	__snake_case    (       self :							Union[str, Any]				)->Union[str, Any]:
      __SCREAMING_SNAKE_CASE       :    str       =	self.prepare_config_and_inputs()
      (
          (
          __SCREAMING_SNAKE_CASE
      ),		(
          __SCREAMING_SNAKE_CASE
      ),		(
          __SCREAMING_SNAKE_CASE
      ),		(
          __SCREAMING_SNAKE_CASE
      ),		(
          __SCREAMING_SNAKE_CASE
      ),		(
          __SCREAMING_SNAKE_CASE
      ),		(
          __SCREAMING_SNAKE_CASE
      ),		
      )       :    Dict       =	config_and_inputs
      __SCREAMING_SNAKE_CASE       :    List[Any]       =	{
          "input_ids": input_ids,
          "token_type_ids": token_type_ids,
          "head_mask": head_mask,
      }

      return config, inputs_dict






@require_torch
class       _SCREAMING_SNAKE_CASE	(UpperCamelCase			,    UpperCamelCase			,    UpperCamelCase			,    unittest.TestCase ):
     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 	__snake_case    (       self :							Optional[Any]     ,  UpperCamelCase :							Union[str, Any]     ,  UpperCamelCase :							Tuple     ,  UpperCamelCase :							Union[str, Any]     ,  UpperCamelCase :							Any     ,  UpperCamelCase :							str				)->List[Any]:
      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 	__snake_case    (       self :							Union[str, Any]     ,  UpperCamelCase :							Any     ,  UpperCamelCase :							List[Any]     ,  UpperCamelCase :							Tuple=False				)->List[str]:
      __SCREAMING_SNAKE_CASE       :    Dict       =	super()._prepare_for_class(UpperCamelCase     ,  UpperCamelCase     ,  return_labels=UpperCamelCase				)

      if return_labels:
       if model_class.__name__ == "OpenAIGPTDoubleHeadsModel":
        __SCREAMING_SNAKE_CASE       :    Union[str, Any]       =	torch.zeros(
            (self.model_tester.batch_size, self.model_tester.num_choices, self.model_tester.seq_length)     ,  dtype=torch.long     ,  device=UpperCamelCase     ,  )
        __SCREAMING_SNAKE_CASE       :    Tuple       =	inputs_dict["labels"]
        __SCREAMING_SNAKE_CASE       :    List[Any]       =	inputs_dict["labels"]
        __SCREAMING_SNAKE_CASE       :    Tuple       =	torch.zeros(
            (self.model_tester.batch_size, self.model_tester.num_choices)     ,  dtype=torch.long     ,  device=UpperCamelCase     ,  )
        __SCREAMING_SNAKE_CASE       :    Union[str, Any]       =	torch.zeros(
            self.model_tester.batch_size     ,  dtype=torch.long     ,  device=UpperCamelCase				)
      return inputs_dict





     def 	__snake_case    (       self :							Optional[int]				)->Dict:
      __SCREAMING_SNAKE_CASE       :    str       =	OpenAIGPTModelTester(self				)
      __SCREAMING_SNAKE_CASE       :    int       =	ConfigTester(self     ,  config_class=UpperCamelCase     ,  n_embd=3_7				)





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





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





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





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





     def 	__snake_case    (       self :							Tuple				)->List[str]:
      __SCREAMING_SNAKE_CASE       :    Optional[int]       =	self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_openai_gpt_for_sequence_classification(*UpperCamelCase				)






     @slow
     def 	__snake_case    (       self :							int				)->Union[str, Any]:
      for model_name in OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
       __SCREAMING_SNAKE_CASE       :    List[Any]       =	OpenAIGPTModel.from_pretrained(UpperCamelCase				)
       self.assertIsNotNone(UpperCamelCase				)






@require_torch
class       _SCREAMING_SNAKE_CASE	(unittest.TestCase ):





     @slow
     def 	__snake_case    (       self :							Union[str, Any]				)->Dict:
      __SCREAMING_SNAKE_CASE       :    List[str]       =	OpenAIGPTLMHeadModel.from_pretrained("openai-gpt"				)
      model.to(UpperCamelCase				)
      __SCREAMING_SNAKE_CASE       :    Tuple       =	torch.tensor([[4_8_1, 4_7_3_5, 5_4_4]]     ,  dtype=torch.long     ,  device=UpperCamelCase				)  # the president is
      __SCREAMING_SNAKE_CASE       :    Optional[Any]       =	[
          4_8_1,
          4_7_3_5,
          5_4_4,
          2_4_6,
          9_6_3,
          8_7_0,
          7_6_2,
          2_3_9,
          2_4_4,
          4_0_4_7_7,
          2_4_4,
          2_4_9,
          7_1_9,
          8_8_1,
          4_8_7,
          5_4_4,
          2_4_0,
          2_4_4,
          6_0_3,
          4_8_1,
      ]  # the president is a very good man. " \n " i\'m sure he is, " said the

      __SCREAMING_SNAKE_CASE       :    Union[str, Any]       =	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() = }''')






