




'''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 						a				:


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


				def   A_ (		self    :					Dict					):
									snake_case_									=				ids_tensor([self.batch_size, self.seq_length]       ,				self.vocab_size					)

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

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

									snake_case_									=				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       ,				)

									snake_case_									=				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    :					Dict       ,				lowercase_    :					Optional[Any]       ,				lowercase_    :					str       ,				lowercase_    :					List[str]       ,				lowercase_    :					Any       ,				*lowercase_    :					Dict					):
									snake_case_									=				OpenAIGPTModel(config=lowercase_					)
									model.to(lowercase_					)
									model.eval()

									snake_case_									=				model(lowercase_       ,				token_type_ids=lowercase_       ,				head_mask=lowercase_					)
									snake_case_									=				model(lowercase_       ,				token_type_ids=lowercase_					)
									snake_case_									=				model(lowercase_					)

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


				def   A_ (		self    :					Optional[Any]       ,				lowercase_    :					Optional[Any]       ,				lowercase_    :					str       ,				lowercase_    :					str       ,				lowercase_    :					Dict       ,				*lowercase_    :					Union[str, Any]					):
									snake_case_									=				OpenAIGPTLMHeadModel(lowercase_					)
									model.to(lowercase_					)
									model.eval()

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

									snake_case_									=				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    :					Any       ,				lowercase_    :					str       ,				lowercase_    :					Any       ,				lowercase_    :					int       ,				lowercase_    :					Union[str, Any]       ,				*lowercase_    :					Any					):
									snake_case_									=				self.num_labels
									snake_case_									=				OpenAIGPTForSequenceClassification(lowercase_					)
									model.to(lowercase_					)
									model.eval()

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


				def   A_ (		self    :					Tuple					):
									snake_case_									=				self.prepare_config_and_inputs()
									(
									    (
									    snake_case_
									)			,(
									    snake_case_
									)			,(
									    snake_case_
									)			,(
									    snake_case_
									)			,(
									    snake_case_
									)			,(
									    snake_case_
									)			,(
									    snake_case_
									)			,
									)									=				config_and_inputs
									snake_case_									=				{
									    '''input_ids''': input_ids,
									    '''token_type_ids''': token_type_ids,
									    '''head_mask''': head_mask,
									}

									return config, inputs_dict







@require_torch
class 						a				(   _lowerCamelCase   ,     _lowerCamelCase   ,     _lowerCamelCase   ,     unittest.TestCase     ):
				snake_case_      =		(
				    (OpenAIGPTModel, OpenAIGPTLMHeadModel, OpenAIGPTDoubleHeadsModel, OpenAIGPTForSequenceClassification)
				    if is_torch_available()
				    else ()
				)
				snake_case_      =		(
				    (OpenAIGPTLMHeadModel,) if is_torch_available() else ()
				)  # TODO (PVP): Add Double HeadsModel when generate() function is changed accordingly
				snake_case_      =		(
				    {
				        "feature-extraction": OpenAIGPTModel,
				        "text-classification": OpenAIGPTForSequenceClassification,
				        "text-generation": OpenAIGPTLMHeadModel,
				        "zero-shot": OpenAIGPTForSequenceClassification,
				    }
				    if is_torch_available()
				    else {}
				)


				def   A_ (		self    :					Any       ,				lowercase_    :					List[str]       ,				lowercase_    :					str       ,				lowercase_    :					Any       ,				lowercase_    :					Optional[Any]       ,				lowercase_    :					int					):
									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    :					Optional[Any]       ,				lowercase_    :					Dict       ,				lowercase_    :					Any       ,				lowercase_    :					int=False					):
									snake_case_									=				super()._prepare_for_class(lowercase_       ,				lowercase_       ,				return_labels=lowercase_					)

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


				def   A_ (		self    :					List[str]					):
									snake_case_									=				OpenAIGPTModelTester(self					)
									snake_case_									=				ConfigTester(self       ,				config_class=lowercase_       ,				n_embd=37					)


				def   A_ (		self    :					List[Any]					):
									self.config_tester.run_common_tests()


				def   A_ (		self    :					str					):
									snake_case_									=				self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_openai_gpt_model(*lowercase_					)


				def   A_ (		self    :					Dict					):
									snake_case_									=				self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_lm_head_model(*lowercase_					)


				def   A_ (		self    :					Optional[Any]					):
									snake_case_									=				self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_double_lm_head_model(*lowercase_					)


				def   A_ (		self    :					Tuple					):
									snake_case_									=				self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_openai_gpt_for_sequence_classification(*lowercase_					)


				@slow
				def   A_ (		self    :					Optional[int]					):
									for model_name in OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
														snake_case_									=				OpenAIGPTModel.from_pretrained(lowercase_					)
														self.assertIsNotNone(lowercase_					)







@require_torch
class 						a				(   unittest.TestCase     ):


				@slow
				def   A_ (		self    :					List[str]					):
									snake_case_									=				OpenAIGPTLMHeadModel.from_pretrained('''openai-gpt'''					)
									model.to(lowercase_					)
									snake_case_									=				torch.tensor([[481, 4735, 544]]       ,				dtype=torch.long       ,				device=lowercase_					)  # the president is
									snake_case_									=				[
									    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

									snake_case_									=				model.generate(lowercase_       ,				do_sample=lowercase_					)
									self.assertListEqual(output_ids[0].tolist()       ,				lowercase_					)


"""simple docstring"""






from __future__ import annotations

from fractions import Fraction



def SCREAMING_SNAKE_CASE__			(   __UpperCAmelCase       ,    __UpperCAmelCase )  ->  bool:
   return (
       num != den and num % 1_0 == den // 1_0 and (num // 1_0) / (den % 1_0) == num / den
   )



def SCREAMING_SNAKE_CASE__			(   __UpperCAmelCase )  ->  list[str]:
   lowercase__:   str					=      []
   lowercase__:   str					=      1_1
   lowercase__:   str					=      int('''1''' + '''0''' * digit_len )
   for num in range(__UpperCAmelCase       ,    __UpperCAmelCase ):
      while den <= 9_9:
         if (num != den) and (num % 1_0 == den // 1_0) and (den % 1_0 != 0):
            if is_digit_cancelling(__UpperCAmelCase       ,    __UpperCAmelCase ):
               solutions.append(F"""{num}/{den}""" )
         den += 1
      num += 1
      lowercase__:   Dict					=      1_0
   return solutions



def SCREAMING_SNAKE_CASE__			(   __UpperCAmelCase = 2 )  ->  int:
   lowercase__:   List[str]					=      1.0
   for fraction in fraction_list(__UpperCAmelCase ):
      lowercase__:   List[str]					=      Fraction(__UpperCAmelCase )
      result *= frac.denominator / frac.numerator
   return int(__UpperCAmelCase )


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