






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    :    Any			,		UpperCamelCase__    :    Any			,		UpperCamelCase__    :    int=1_3			,		UpperCamelCase__    :    Tuple=7			,		UpperCamelCase__    :    List[str]=True			,		UpperCamelCase__    :    Any=True			,		UpperCamelCase__    :    List[Any]=True			,		UpperCamelCase__    :    List[Any]=9_9			,		UpperCamelCase__    :    List[str]=3_2			,		UpperCamelCase__    :    Optional[Any]=5			,		UpperCamelCase__    :    Any=4			,		UpperCamelCase__    :    Optional[int]=3_7			,		UpperCamelCase__    :    Optional[int]="gelu"			,		UpperCamelCase__    :    List[str]=0.1			,		UpperCamelCase__    :    List[str]=0.1			,		UpperCamelCase__    :    List[str]=5_1_2			,		UpperCamelCase__    :    Optional[Any]=1_6			,		UpperCamelCase__    :    Optional[Any]=2			,		UpperCamelCase__    :    int=0.02			,		UpperCamelCase__    :    List[str]=3			,		UpperCamelCase__    :    Optional[int]=4			,		UpperCamelCase__    :    int=None			,		):






											'''simple docstring'''







											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 					__magic_name__							(      self    :    List[str]):






											'''simple docstring'''







											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 					__magic_name__							(      self    :    Any			,		UpperCamelCase__    :    List[str]			,		UpperCamelCase__    :    Tuple			,		UpperCamelCase__    :    Optional[Any]			,		UpperCamelCase__    :    Tuple			,		*UpperCamelCase__    :    Union[str, Any]):






											'''simple docstring'''







											snake_case__	  =       OpenAIGPTModel(config=UpperCamelCase__)
											model.to(UpperCamelCase__)
											model.eval()

											snake_case__	  =       model(UpperCamelCase__			,		token_type_ids=UpperCamelCase__			,		head_mask=UpperCamelCase__)
											snake_case__	  =       model(UpperCamelCase__			,		token_type_ids=UpperCamelCase__)
											snake_case__	  =       model(UpperCamelCase__)

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



				def 					__magic_name__							(      self    :    List[Any]			,		UpperCamelCase__    :    Optional[int]			,		UpperCamelCase__    :    str			,		UpperCamelCase__    :    Optional[int]			,		UpperCamelCase__    :    Union[str, Any]			,		*UpperCamelCase__    :    Optional[Any]):






											'''simple docstring'''







											snake_case__	  =       OpenAIGPTLMHeadModel(UpperCamelCase__)
											model.to(UpperCamelCase__)
											model.eval()

											snake_case__	  =       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 					__magic_name__							(      self    :    List[Any]			,		UpperCamelCase__    :    Optional[Any]			,		UpperCamelCase__    :    Any			,		UpperCamelCase__    :    Optional[Any]			,		UpperCamelCase__    :    List[Any]			,		*UpperCamelCase__    :    Any):






											'''simple docstring'''







											snake_case__	  =       OpenAIGPTDoubleHeadsModel(UpperCamelCase__)
											model.to(UpperCamelCase__)
											model.eval()

											snake_case__	  =       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 					__magic_name__							(      self    :    Dict			,		UpperCamelCase__    :    str			,		UpperCamelCase__    :    Union[str, Any]			,		UpperCamelCase__    :    Optional[Any]			,		UpperCamelCase__    :    List[Any]			,		*UpperCamelCase__    :    List[Any]):






											'''simple docstring'''







											snake_case__	  =       self.num_labels
											snake_case__	  =       OpenAIGPTForSequenceClassification(UpperCamelCase__)
											model.to(UpperCamelCase__)
											model.eval()

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



				def 					__magic_name__							(      self    :    List[str]):






											'''simple docstring'''







											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    _lowerCAmelCase			(		lowercase_     ,      lowercase_     ,      lowercase_     ,      unittest.TestCase      ):



				"""simple docstring"""



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



				def 					__magic_name__							(      self    :    Union[str, Any]			,		UpperCamelCase__    :    int			,		UpperCamelCase__    :    Dict			,		UpperCamelCase__    :    Optional[Any]			,		UpperCamelCase__    :    Dict			,		UpperCamelCase__    :    Union[str, Any]):






											'''simple docstring'''







											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 					__magic_name__							(      self    :    Any			,		UpperCamelCase__    :    Union[str, Any]			,		UpperCamelCase__    :    Any			,		UpperCamelCase__    :    int=False):






											'''simple docstring'''







											snake_case__	  =       super()._prepare_for_class(UpperCamelCase__			,		UpperCamelCase__			,		return_labels=UpperCamelCase__)

											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=UpperCamelCase__			,		)
																									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=UpperCamelCase__			,		)
																									snake_case__	  =       torch.zeros(
																									    self.model_tester.batch_size			,		dtype=torch.long			,		device=UpperCamelCase__)
											return inputs_dict



				def 					__magic_name__							(      self    :    List[Any]):






											'''simple docstring'''







											snake_case__	  =       OpenAIGPTModelTester(self)
											snake_case__	  =       ConfigTester(self			,		config_class=UpperCamelCase__			,		n_embd=3_7)



				def 					__magic_name__							(      self    :    int):






											'''simple docstring'''







											self.config_tester.run_common_tests()



				def 					__magic_name__							(      self    :    Dict):






											'''simple docstring'''







											snake_case__	  =       self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_openai_gpt_model(*UpperCamelCase__)



				def 					__magic_name__							(      self    :    Any):






											'''simple docstring'''







											snake_case__	  =       self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_lm_head_model(*UpperCamelCase__)



				def 					__magic_name__							(      self    :    Union[str, Any]):






											'''simple docstring'''







											snake_case__	  =       self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_double_lm_head_model(*UpperCamelCase__)



				def 					__magic_name__							(      self    :    Dict):






											'''simple docstring'''







											snake_case__	  =       self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_openai_gpt_for_sequence_classification(*UpperCamelCase__)



				@slow
				def 					__magic_name__							(      self    :    str):






											'''simple docstring'''







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


@require_torch
class    _lowerCAmelCase			(		unittest.TestCase      ):



				"""simple docstring"""



				@slow
				def 					__magic_name__							(      self    :    Optional[int]):






											'''simple docstring'''







											snake_case__	  =       OpenAIGPTLMHeadModel.from_pretrained("""openai-gpt""")
											model.to(UpperCamelCase__)
											snake_case__	  =       torch.tensor([[4_8_1, 4_7_3_5, 5_4_4]]			,		dtype=torch.long			,		device=UpperCamelCase__)  # the president is
											snake_case__	  =       [
											    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

											snake_case__	  =       model.generate(UpperCamelCase__			,		do_sample=UpperCamelCase__)
											self.assertListEqual(output_ids[0].tolist()			,		UpperCamelCase__)








import math
from collections.abc import Iterator
from itertools import takewhile

def _UpperCAmelCase   (	a						:	int ):

							if 1 < number < 4:
														# 2 and 3 are primes
														return True
							elif number < 2 or number % 2 == 0 or number % 3 == 0:
														# Negatives, 0, 1, all even numbers, all multiples of 3 are not primes
														return False

							# All primes number are in format of 6k +/- 1
							for i in range(5  ,					int(math.sqrt(a ) + 1 )  ,					6 ):
														if number % i == 0 or number % (i + 2) == 0:
																					return False
							return True

def _UpperCAmelCase   (	):
							snake_case__	  =       2
							while True:
														if is_prime(a ):
																					yield num
														num += 1

def _UpperCAmelCase   (	a						:	int = 200_0000 ):
							return sum(takewhile(lambda a : x < n  ,					prime_generator() ) )


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