



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




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




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

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

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

									lowerCAmelCase_			:     int									= 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_			:     Union[str, Any]									= 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    UpperCAmelCase__			(       self     :       Any				,				A_     :       Dict				,				A_     :       List[str]				,				A_     :       Tuple				,				A_     :       Any				,				*A_     :       List[Any]):
									lowerCAmelCase_			:     Union[str, Any]									= OpenAIGPTModel(config=A_)
									model.to(A_)
									model.eval()

									lowerCAmelCase_			:     str									= model(A_				,				token_type_ids=A_				,				head_mask=A_)
									lowerCAmelCase_			:     Optional[int]									= model(A_				,				token_type_ids=A_)
									lowerCAmelCase_			:     Any									= model(A_)

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




							def    UpperCAmelCase__			(       self     :       Dict				,				A_     :       Union[str, Any]				,				A_     :       Optional[Any]				,				A_     :       int				,				A_     :       Dict				,				*A_     :       Any):
									lowerCAmelCase_			:     List[Any]									= OpenAIGPTLMHeadModel(A_)
									model.to(A_)
									model.eval()

									lowerCAmelCase_			:     str									= model(A_				,				token_type_ids=A_				,				labels=A_)
									self.parent.assertEqual(result.loss.shape				,				())
									self.parent.assertEqual(result.logits.shape				,				(self.batch_size, self.seq_length, self.vocab_size))




							def    UpperCAmelCase__			(       self     :       Optional[int]				,				A_     :       int				,				A_     :       Tuple				,				A_     :       Optional[Any]				,				A_     :       Dict				,				*A_     :       int):
									lowerCAmelCase_			:     Optional[int]									= OpenAIGPTDoubleHeadsModel(A_)
									model.to(A_)
									model.eval()

									lowerCAmelCase_			:     List[str]									= model(A_				,				token_type_ids=A_				,				labels=A_)
									self.parent.assertEqual(result.loss.shape				,				())
									self.parent.assertEqual(result.logits.shape				,				(self.batch_size, self.seq_length, self.vocab_size))




							def    UpperCAmelCase__			(       self     :       Dict				,				A_     :       List[Any]				,				A_     :       Tuple				,				A_     :       List[Any]				,				A_     :       Optional[int]				,				*A_     :       int):
									lowerCAmelCase_			:     Any									= self.num_labels
									lowerCAmelCase_			:     Optional[Any]									= OpenAIGPTForSequenceClassification(A_)
									model.to(A_)
									model.eval()

									lowerCAmelCase_			:     str									= ids_tensor([self.batch_size]				,				self.type_sequence_label_size)
									lowerCAmelCase_			:     int									= model(A_				,				token_type_ids=A_				,				labels=A_)
									self.parent.assertEqual(result.logits.shape				,				(self.batch_size, self.num_labels))







							def    UpperCAmelCase__			(       self     :       Union[str, Any]):
									lowerCAmelCase_			:     Dict									= self.prepare_config_and_inputs()
									(
									    lowerCAmelCase_   
									)			:     Tuple									= config_and_inputs
									lowerCAmelCase_			:     Optional[Any]									= {
									    """input_ids""": input_ids,
									    """token_type_ids""": token_type_ids,
									    """head_mask""": head_mask,
									}

									return config, inputs_dict





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




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

									if return_labels:
											if model_class.__name__ == "OpenAIGPTDoubleHeadsModel":
													lowerCAmelCase_			:     Optional[Any]									= torch.zeros(
													    (self.model_tester.batch_size, self.model_tester.num_choices, self.model_tester.seq_length)				,				dtype=torch.long				,				device=A_				,				)
													lowerCAmelCase_			:     List[Any]									= inputs_dict["""labels"""]
													lowerCAmelCase_			:     int									= inputs_dict["""labels"""]
													lowerCAmelCase_			:     Optional[int]									= torch.zeros(
													    (self.model_tester.batch_size, self.model_tester.num_choices)				,				dtype=torch.long				,				device=A_				,				)
													lowerCAmelCase_			:     Dict									= torch.zeros(
													    self.model_tester.batch_size				,				dtype=torch.long				,				device=A_)
									return inputs_dict




							def    UpperCAmelCase__			(       self     :       List[Any]):
									lowerCAmelCase_			:     str									= OpenAIGPTModelTester(self)
									lowerCAmelCase_			:     Dict									= ConfigTester(self				,				config_class=A_				,				n_embd=3_7)




							def    UpperCAmelCase__			(       self     :       Optional[Any]):
									self.config_tester.run_common_tests()




							def    UpperCAmelCase__			(       self     :       List[Any]):
									lowerCAmelCase_			:     Any									= self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_openai_gpt_model(*A_)




							def    UpperCAmelCase__			(       self     :       str):
									lowerCAmelCase_			:     str									= self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_lm_head_model(*A_)




							def    UpperCAmelCase__			(       self     :       Dict):
									lowerCAmelCase_			:     str									= self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_double_lm_head_model(*A_)




							def    UpperCAmelCase__			(       self     :       int):
									lowerCAmelCase_			:     str									= self.model_tester.prepare_config_and_inputs()
									self.model_tester.create_and_check_openai_gpt_for_sequence_classification(*A_)







							@slow
							def    UpperCAmelCase__			(       self     :       Optional[Any]):
									for model_name in OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
											lowerCAmelCase_			:     List[Any]									= OpenAIGPTModel.from_pretrained(A_)
											self.assertIsNotNone(A_)





@require_torch
class 				__snake_case						(     unittest.TestCase						):




							@slow
							def    UpperCAmelCase__			(       self     :       Optional[Any]):
									lowerCAmelCase_			:     Optional[Any]									= OpenAIGPTLMHeadModel.from_pretrained('''openai-gpt''')
									model.to(A_)
									lowerCAmelCase_			:     int									= torch.tensor([[4_8_1, 4_7_3_5, 5_4_4]]				,				dtype=torch.long				,				device=A_)  # the president is
									lowerCAmelCase_			:     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

									lowerCAmelCase_			:     List[Any]									= model.generate(A_				,				do_sample=A_)
									self.assertListEqual(output_ids[0].tolist()				,				A_)












import math







def 			A__							(    SCREAMING_SNAKE_CASE__)   ->    bool:

  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(SCREAMING_SNAKE_CASE__) + 1)					,					6):
    if number % i == 0 or number % (i + 2) == 0:
      return False
  return True







def 			A__							(    SCREAMING_SNAKE_CASE__ = 1_0001)   ->    int:

  try:
    __snake_case:						List[str]   =						int(SCREAMING_SNAKE_CASE__)
  except (TypeError, ValueError):
    raise TypeError("""Parameter nth must be int or castable to int.""") from None
  if nth <= 0:
    raise ValueError("""Parameter nth must be greater than or equal to one.""")
  __snake_case:						list[int]   =						[]
  __snake_case:						List[str]   =						2
  while len(SCREAMING_SNAKE_CASE__) < nth:
    if is_prime(SCREAMING_SNAKE_CASE__):
      primes.append(SCREAMING_SNAKE_CASE__)
      num += 1
    else:
      num += 1
  return primes[len(SCREAMING_SNAKE_CASE__) - 1]


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






