




"""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 lowerCAmelCase__      :






			'''simple docstring'''



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

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

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

							_lowerCamelCase	:     Optional[Any]       =       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    , )

							_lowerCamelCase	:     str       =       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    , lowercase    , lowercase    , lowercase    , lowercase    , *lowercase    ):
							_lowerCamelCase	:     Dict       =       OpenAIGPTModel(config=lowercase    )
							model.to(lowercase    )
							model.eval()

							_lowerCamelCase	:     Optional[int]       =       model(lowercase    , token_type_ids=lowercase    , head_mask=lowercase    )
							_lowerCamelCase	:     Tuple       =       model(lowercase    , token_type_ids=lowercase    )
							_lowerCamelCase	:     Any       =       model(lowercase    )

							self.parent.assertEqual(result.last_hidden_state.shape    , (self.batch_size, self.seq_length, self.hidden_size)    )
			def    A_       (    self    , lowercase    , lowercase    , lowercase    , lowercase    , *lowercase    ):
							_lowerCamelCase	:     str       =       OpenAIGPTLMHeadModel(lowercase    )
							model.to(lowercase    )
							model.eval()

							_lowerCamelCase	:     str       =       model(lowercase    , token_type_ids=lowercase    , labels=lowercase    )
							self.parent.assertEqual(result.loss.shape    , ()    )
							self.parent.assertEqual(result.logits.shape    , (self.batch_size, self.seq_length, self.vocab_size)    )
			def    A_       (    self    , lowercase    , lowercase    , lowercase    , lowercase    , *lowercase    ):
							_lowerCamelCase	:     List[Any]       =       OpenAIGPTDoubleHeadsModel(lowercase    )
							model.to(lowercase    )
							model.eval()

							_lowerCamelCase	:     int       =       model(lowercase    , token_type_ids=lowercase    , labels=lowercase    )
							self.parent.assertEqual(result.loss.shape    , ()    )
							self.parent.assertEqual(result.logits.shape    , (self.batch_size, self.seq_length, self.vocab_size)    )
			def    A_       (    self    , lowercase    , lowercase    , lowercase    , lowercase    , *lowercase    ):
							_lowerCamelCase	:     Optional[int]       =       self.num_labels
							_lowerCamelCase	:     int       =       OpenAIGPTForSequenceClassification(lowercase    )
							model.to(lowercase    )
							model.eval()

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






			def    A_       (    self    ):
							_lowerCamelCase	:     Dict       =       self.prepare_config_and_inputs()
							(
							    (
							    _lowerCamelCase
							),					(
							    _lowerCamelCase
							),					(
							    _lowerCamelCase
							),					(
							    _lowerCamelCase
							),					(
							    _lowerCamelCase
							),					(
							    _lowerCamelCase
							),					(
							    _lowerCamelCase
							),					
							)	:     List[str]       =       config_and_inputs
							_lowerCamelCase	:     Union[str, Any]       =       {
							    'input_ids': input_ids,
							    'token_type_ids': token_type_ids,
							    'head_mask': head_mask,
							}

							return config, inputs_dict






@require_torch
class lowerCAmelCase__      (	lowercase,      lowercase,      lowercase,      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    , lowercase    , lowercase    , lowercase    , lowercase    , lowercase    ):
							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    , lowercase    , lowercase    , lowercase=False    ):
							_lowerCamelCase	:     Union[str, Any]       =       super()._prepare_for_class(lowercase    , lowercase    , return_labels=lowercase    )

							if return_labels:
											if model_class.__name__ == "OpenAIGPTDoubleHeadsModel":
															_lowerCamelCase	:     List[str]       =       torch.zeros(
															    (self.model_tester.batch_size, self.model_tester.num_choices, self.model_tester.seq_length)    , dtype=torch.long    , device=lowercase    , )
															_lowerCamelCase	:     Tuple       =       inputs_dict['labels']
															_lowerCamelCase	:     Optional[Any]       =       inputs_dict['labels']
															_lowerCamelCase	:     str       =       torch.zeros(
															    (self.model_tester.batch_size, self.model_tester.num_choices)    , dtype=torch.long    , device=lowercase    , )
															_lowerCamelCase	:     Any       =       torch.zeros(
															    self.model_tester.batch_size    , dtype=torch.long    , device=lowercase    )
							return inputs_dict
			def    A_       (    self    ):
							_lowerCamelCase	:     Union[str, Any]       =       OpenAIGPTModelTester(self    )
							_lowerCamelCase	:     List[str]       =       ConfigTester(self    , config_class=lowercase    , n_embd=37    )
			def    A_       (    self    ):
							self.config_tester.run_common_tests()
			def    A_       (    self    ):
							_lowerCamelCase	:     List[str]       =       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_openai_gpt_model(*lowercase    )
			def    A_       (    self    ):
							_lowerCamelCase	:     List[Any]       =       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_lm_head_model(*lowercase    )
			def    A_       (    self    ):
							_lowerCamelCase	:     Any       =       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_double_lm_head_model(*lowercase    )
			def    A_       (    self    ):
							_lowerCamelCase	:     Optional[int]       =       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_openai_gpt_for_sequence_classification(*lowercase    )






			@slow
			def    A_       (    self    ):
							for model_name in OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
											_lowerCamelCase	:     str       =       OpenAIGPTModel.from_pretrained(lowercase    )
											self.assertIsNotNone(lowercase    )






@require_torch
class lowerCAmelCase__      (	unittest.TestCase		):






			'''simple docstring'''



			@slow
			def    A_       (    self    ):
							_lowerCamelCase	:     List[str]       =       OpenAIGPTLMHeadModel.from_pretrained('openai-gpt'    )
							model.to(lowercase    )
							_lowerCamelCase	:     Dict       =       torch.tensor([[481, 4735, 544]]    , dtype=torch.long    , device=lowercase    )  # the president is
							_lowerCamelCase	:     List[str]       =       [
							    481,
							    4735,
							    544,
							    246,
							    963,
							    870,
							    762,
							    239,
							    244,
							    40477,
							    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

							_lowerCamelCase	:     int       =       model.generate(lowercase    , do_sample=lowercase    )
							self.assertListEqual(output_ids[0].tolist()    , lowercase    )





"""simple docstring"""






from __future__ import annotations

from fractions import Fraction
from math import gcd, sqrt







def 	_snake_case     (							lowercase__						):
				_lowerCamelCase	:     int       =       int(number**0.5						)
				return number == sq * sq







def 	_snake_case     (							lowercase__				,       lowercase__				,       lowercase__				,       lowercase__				,       lowercase__				,       lowercase__						):
				_lowerCamelCase	:     int       =       x_num * y_den * z_den + y_num * x_den * z_den + z_num * x_den * y_den
				_lowerCamelCase	:     int       =       x_den * y_den * z_den
				_lowerCamelCase	:     int       =       gcd(lowercase__				,       lowercase__						)
				top //= hcf
				bottom //= hcf
				return top, bottom







def 	_snake_case     (							lowercase__ = 35						):
				_lowerCamelCase	:     set       =       set()
				_lowerCamelCase	:     int
				_lowerCamelCase	:     Fraction       =       Fraction(0						)
				_lowerCamelCase	:     tuple[int, int]

				for x_num in range(1				,       order + 1						):
								for x_den in range(x_num + 1				,       order + 1						):
												for y_num in range(1				,       order + 1						):
																for y_den in range(y_num + 1				,       order + 1						):
																				# n=1
																				_lowerCamelCase	:     int       =       x_num * y_den + x_den * y_num
																				_lowerCamelCase	:     List[Any]       =       x_den * y_den
																				_lowerCamelCase	:     int       =       gcd(lowercase__				,       lowercase__						)
																				z_num //= hcf
																				z_den //= hcf
																				if 0 < z_num < z_den <= order:
																								_lowerCamelCase	:     Optional[Any]       =       add_three(
																								    lowercase__				,       lowercase__				,       lowercase__				,       lowercase__				,       lowercase__				,       lowercase__						)
																								unique_s.add(lowercase__						)

																				# n=2
																				_lowerCamelCase	:     Tuple       =       (
																				    x_num * x_num * y_den * y_den + x_den * x_den * y_num * y_num
																				)
																				_lowerCamelCase	:     Dict       =       x_den * x_den * y_den * y_den
																				if is_sq(lowercase__						) and is_sq(lowercase__						):
																								_lowerCamelCase	:     Dict       =       int(sqrt(lowercase__						)						)
																								_lowerCamelCase	:     Optional[Any]       =       int(sqrt(lowercase__						)						)
																								_lowerCamelCase	:     List[Any]       =       gcd(lowercase__				,       lowercase__						)
																								z_num //= hcf
																								z_den //= hcf
																								if 0 < z_num < z_den <= order:
																												_lowerCamelCase	:     Union[str, Any]       =       add_three(
																												    lowercase__				,       lowercase__				,       lowercase__				,       lowercase__				,       lowercase__				,       lowercase__						)
																												unique_s.add(lowercase__						)

                    # n=-1
																				_lowerCamelCase	:     List[str]       =       x_num * y_num
																				_lowerCamelCase	:     int       =       x_den * y_num + x_num * y_den
																				_lowerCamelCase	:     Dict       =       gcd(lowercase__				,       lowercase__						)
																				z_num //= hcf
																				z_den //= hcf
																				if 0 < z_num < z_den <= order:
																								_lowerCamelCase	:     List[str]       =       add_three(
																								    lowercase__				,       lowercase__				,       lowercase__				,       lowercase__				,       lowercase__				,       lowercase__						)
																								unique_s.add(lowercase__						)

																				# n=2
																				_lowerCamelCase	:     Tuple       =       x_num * x_num * y_num * y_num
																				_lowerCamelCase	:     List[str]       =       (
																				    x_den * x_den * y_num * y_num + x_num * x_num * y_den * y_den
																				)
																				if is_sq(lowercase__						) and is_sq(lowercase__						):
																								_lowerCamelCase	:     Optional[int]       =       int(sqrt(lowercase__						)						)
																								_lowerCamelCase	:     Optional[int]       =       int(sqrt(lowercase__						)						)
																								_lowerCamelCase	:     Dict       =       gcd(lowercase__				,       lowercase__						)
																								z_num //= hcf
																								z_den //= hcf
																								if 0 < z_num < z_den <= order:
																												_lowerCamelCase	:     int       =       add_three(
																												    lowercase__				,       lowercase__				,       lowercase__				,       lowercase__				,       lowercase__				,       lowercase__						)
																												unique_s.add(lowercase__						)

				for num, den in unique_s:
								total += Fraction(lowercase__				,       lowercase__						)

				return total.denominator + total.numerator


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