





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       :




      """simple docstring"""







      def __init__(		self      ,							a__      ,							a__=13      ,							a__=7      ,							a__=True      ,							a__=True      ,							a__=True      ,							a__=99      ,							a__=32      ,							a__=5      ,							a__=4      ,							a__=37      ,							a__="gelu"      ,							a__=0.1      ,							a__=0.1      ,							a__=512      ,							a__=16      ,							a__=2      ,							a__=0.02      ,							a__=3      ,							a__=4      ,							a__=None      ,							):



             """simple docstring"""





             _lowerCamelCase							:     Dict	=		parent
             _lowerCamelCase							:     List[Any]	=		batch_size
             _lowerCamelCase							:     int	=		seq_length
             _lowerCamelCase							:     Optional[Any]	=		is_training
             _lowerCamelCase							:     List[str]	=		use_token_type_ids
             _lowerCamelCase							:     int	=		use_labels
             _lowerCamelCase							:     Dict	=		vocab_size
             _lowerCamelCase							:     Any	=		hidden_size
             _lowerCamelCase							:     List[Any]	=		num_hidden_layers
             _lowerCamelCase							:     List[Any]	=		num_attention_heads
             _lowerCamelCase							:     Optional[int]	=		intermediate_size
             _lowerCamelCase							:     List[Any]	=		hidden_act
             _lowerCamelCase							:     List[Any]	=		hidden_dropout_prob
             _lowerCamelCase							:     Dict	=		attention_probs_dropout_prob
             _lowerCamelCase							:     Tuple	=		max_position_embeddings
             _lowerCamelCase							:     Tuple	=		type_vocab_size
             _lowerCamelCase							:     int	=		type_sequence_label_size
             _lowerCamelCase							:     str	=		initializer_range
             _lowerCamelCase							:     str	=		num_labels
             _lowerCamelCase							:     int	=		num_choices
             _lowerCamelCase							:     str	=		scope
             _lowerCamelCase							:     Union[str, Any]	=		self.vocab_size - 1


      def 				__snake_case			(		self):



             """simple docstring"""





             _lowerCamelCase							:     Union[str, Any]	=		ids_tensor([self.batch_size, self.seq_length]      ,							self.vocab_size)

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

             _lowerCamelCase							:     List[Any]	=		None
             _lowerCamelCase							:     int	=		None
             _lowerCamelCase							:     Optional[int]	=		None
             if self.use_labels:
                    _lowerCamelCase							:     Tuple	=		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							:     Any	=		ids_tensor([self.batch_size]      ,							self.num_choices)

             _lowerCamelCase							:     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							:     Optional[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 				__snake_case			(		self      ,							a__      ,							a__      ,							a__      ,							a__      ,							*a__):



             """simple docstring"""





             _lowerCamelCase							:     Tuple	=		OpenAIGPTModel(config=lowerCAmelCase__)
             model.to(lowerCAmelCase__)
             model.eval()

             _lowerCamelCase							:     List[str]	=		model(lowerCAmelCase__      ,							token_type_ids=lowerCAmelCase__      ,							head_mask=lowerCAmelCase__)
             _lowerCamelCase							:     Optional[int]	=		model(lowerCAmelCase__      ,							token_type_ids=lowerCAmelCase__)
             _lowerCamelCase							:     Optional[int]	=		model(lowerCAmelCase__)

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


      def 				__snake_case			(		self      ,							a__      ,							a__      ,							a__      ,							a__      ,							*a__):



             """simple docstring"""





             _lowerCamelCase							:     Any	=		OpenAIGPTLMHeadModel(lowerCAmelCase__)
             model.to(lowerCAmelCase__)
             model.eval()

             _lowerCamelCase							:     List[str]	=		model(lowerCAmelCase__      ,							token_type_ids=lowerCAmelCase__      ,							labels=lowerCAmelCase__)
             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      ,							a__      ,							a__      ,							a__      ,							a__      ,							*a__):



             """simple docstring"""





             _lowerCamelCase							:     Tuple	=		OpenAIGPTDoubleHeadsModel(lowerCAmelCase__)
             model.to(lowerCAmelCase__)
             model.eval()

             _lowerCamelCase							:     Dict	=		model(lowerCAmelCase__      ,							token_type_ids=lowerCAmelCase__      ,							labels=lowerCAmelCase__)
             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      ,							a__      ,							a__      ,							a__      ,							a__      ,							*a__):



             """simple docstring"""





             _lowerCamelCase							:     Optional[Any]	=		self.num_labels
             _lowerCamelCase							:     Dict	=		OpenAIGPTForSequenceClassification(lowerCAmelCase__)
             model.to(lowerCAmelCase__)
             model.eval()

             _lowerCamelCase							:     str	=		ids_tensor([self.batch_size]      ,							self.type_sequence_label_size)
             _lowerCamelCase							:     Tuple	=		model(lowerCAmelCase__      ,							token_type_ids=lowerCAmelCase__      ,							labels=lowerCAmelCase__)
             self.parent.assertEqual(result.logits.shape      ,							(self.batch_size, self.num_labels))



      def 				__snake_case			(		self):



             """simple docstring"""





             _lowerCamelCase							:     Optional[int]	=		self.prepare_config_and_inputs()
             (
                 _lowerCamelCase 
             )							:     Tuple	=		config_and_inputs
             _lowerCamelCase							:     List[str]	=		{
                 "input_ids": input_ids,
                 "token_type_ids": token_type_ids,
                 "head_mask": head_mask,
             }

             return config, inputs_dict







@require_torch
class 			__A       (      a__ ,a__ ,a__ ,unittest.TestCase  ):




      """simple docstring"""







      UpperCAmelCase__						=      (
          (OpenAIGPTModel, OpenAIGPTLMHeadModel, OpenAIGPTDoubleHeadsModel, OpenAIGPTForSequenceClassification)
          if is_torch_available()
          else ()
      )
      UpperCAmelCase__						=      (
          (OpenAIGPTLMHeadModel,) if is_torch_available() else ()
      )  # TODO (PVP): Add Double HeadsModel when generate() function is changed accordingly
      UpperCAmelCase__						=      (
          {
              """feature-extraction""": OpenAIGPTModel,
              """text-classification""": OpenAIGPTForSequenceClassification,
              """text-generation""": OpenAIGPTLMHeadModel,
              """zero-shot""": OpenAIGPTForSequenceClassification,
          }
          if is_torch_available()
          else {}
      )


      def 				__snake_case			(		self      ,							a__      ,							a__      ,							a__      ,							a__      ,							a__):



             """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 				__snake_case			(		self      ,							a__      ,							a__      ,							a__=False):



             """simple docstring"""





             _lowerCamelCase							:     Dict	=		super()._prepare_for_class(lowerCAmelCase__      ,							lowerCAmelCase__      ,							return_labels=lowerCAmelCase__)

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


      def 				__snake_case			(		self):



             """simple docstring"""





             _lowerCamelCase							:     List[str]	=		OpenAIGPTModelTester(self)
             _lowerCamelCase							:     Any	=		ConfigTester(self      ,							config_class=lowerCAmelCase__      ,							n_embd=37)


      def 				__snake_case			(		self):



             """simple docstring"""





             self.config_tester.run_common_tests()


      def 				__snake_case			(		self):



             """simple docstring"""





             _lowerCamelCase							:     Union[str, Any]	=		self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_openai_gpt_model(*lowerCAmelCase__)


      def 				__snake_case			(		self):



             """simple docstring"""





             _lowerCamelCase							:     Dict	=		self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_lm_head_model(*lowerCAmelCase__)


      def 				__snake_case			(		self):



             """simple docstring"""





             _lowerCamelCase							:     List[Any]	=		self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_double_lm_head_model(*lowerCAmelCase__)


      def 				__snake_case			(		self):



             """simple docstring"""





             _lowerCamelCase							:     int	=		self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_openai_gpt_for_sequence_classification(*lowerCAmelCase__)



      @slow
      def 				__snake_case			(		self):



             """simple docstring"""





             for model_name in OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                    _lowerCamelCase							:     List[Any]	=		OpenAIGPTModel.from_pretrained(lowerCAmelCase__)
                    self.assertIsNotNone(lowerCAmelCase__)







@require_torch
class 			__A       (      unittest.TestCase  ):




      """simple docstring"""







      @slow
      def 				__snake_case			(		self):



             """simple docstring"""





             _lowerCamelCase							:     str	=		OpenAIGPTLMHeadModel.from_pretrained('''openai-gpt''')
             model.to(lowerCAmelCase__)
             _lowerCamelCase							:     Union[str, Any]	=		torch.tensor([[481, 4735, 544]]      ,							dtype=torch.long      ,							device=lowerCAmelCase__)  # the president is
             _lowerCamelCase							:     str	=		[
                 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

             _lowerCamelCase							:     Optional[Any]	=		model.generate(lowerCAmelCase__      ,							do_sample=lowerCAmelCase__)
             self.assertListEqual(output_ids[0].tolist()      ,							lowerCAmelCase__)








import math




def    __UpperCAmelCase(      lowercase_ ,    lowercase_      ):
       _lowerCamelCase							:     List[str]	=		len(lowercase_      )
       _lowerCamelCase							:     Optional[int]	=		int(math.floor(math.sqrt(lowercase_      )      )      )
       _lowerCamelCase							:     Tuple	=		0
       while arr[min(lowercase_ ,    lowercase_      ) - 1] < x:
              _lowerCamelCase							:     Optional[Any]	=		step
              step += int(math.floor(math.sqrt(lowercase_      )      )      )
              if prev >= n:
                     return -1

       while arr[prev] < x:
              _lowerCamelCase							:     int	=		prev + 1
              if prev == min(lowercase_ ,    lowercase_      ):
                     return -1
       if arr[prev] == x:
              return prev
       return -1


if __name__ == "__main__":
       _lowerCamelCase			       =      input('Enter numbers separated by a comma:\n').strip()
       _lowerCamelCase			       =      [int(item) for item in user_input.split(',')]
       _lowerCamelCase			       =      int(input('Enter the number to be searched:\n'))
       _lowerCamelCase			       =      jump_search(arr, x)
       if res == -1:
              print('Number not found!')
       else:
              print(F'''Number {x} is at index {res}''')

