


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




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




     def 			snake_case__  ( self):
        UpperCAmelCase__					:   Optional[Any]       				=       ids_tensor([self.batch_size, self.seq_length]							,							self.vocab_size)

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

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

        UpperCAmelCase__					:   List[str]       				=       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							,							)

        UpperCAmelCase__					:   Optional[int]       				=       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							,							_lowerCamelCase							,							_lowerCamelCase							,							_lowerCamelCase							,							_lowerCamelCase							,							*_lowerCamelCase):
        UpperCAmelCase__					:   str       				=       OpenAIGPTModel(config=_snake_case)
        model.to(_snake_case)
        model.eval()

        UpperCAmelCase__					:   Optional[int]       				=       model(_snake_case							,							token_type_ids=_snake_case							,							head_mask=_snake_case)
        UpperCAmelCase__					:   Optional[int]       				=       model(_snake_case							,							token_type_ids=_snake_case)
        UpperCAmelCase__					:   List[str]       				=       model(_snake_case)

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




     def 			snake_case__  ( self							,							_lowerCamelCase							,							_lowerCamelCase							,							_lowerCamelCase							,							_lowerCamelCase							,							*_lowerCamelCase):
        UpperCAmelCase__					:   Union[str, Any]       				=       OpenAIGPTLMHeadModel(_snake_case)
        model.to(_snake_case)
        model.eval()

        UpperCAmelCase__					:   Union[str, Any]       				=       model(_snake_case							,							token_type_ids=_snake_case							,							labels=_snake_case)
        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							,							_lowerCamelCase							,							_lowerCamelCase							,							_lowerCamelCase							,							_lowerCamelCase							,							*_lowerCamelCase):
        UpperCAmelCase__					:   Optional[Any]       				=       OpenAIGPTDoubleHeadsModel(_snake_case)
        model.to(_snake_case)
        model.eval()

        UpperCAmelCase__					:   List[str]       				=       model(_snake_case							,							token_type_ids=_snake_case							,							labels=_snake_case)
        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							,							_lowerCamelCase							,							_lowerCamelCase							,							_lowerCamelCase							,							_lowerCamelCase							,							*_lowerCamelCase):
        UpperCAmelCase__					:   Any       				=       self.num_labels
        UpperCAmelCase__					:   Optional[int]       				=       OpenAIGPTForSequenceClassification(_snake_case)
        model.to(_snake_case)
        model.eval()

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




     def 			snake_case__  ( self):
        UpperCAmelCase__					:   str       				=       self.prepare_config_and_inputs()
        (
            (
            UpperCAmelCase__					
        )				,    (
            UpperCAmelCase__					
        )				,    (
            UpperCAmelCase__					
        )				,    (
            UpperCAmelCase__					
        )				,    (
            UpperCAmelCase__					
        )				,    (
            UpperCAmelCase__					
        )				,    (
            UpperCAmelCase__					
        )				,    					
        )					:   List[Any]       				=       config_and_inputs
        UpperCAmelCase__					:   List[Any]       				=       {
            """input_ids""": input_ids,
            """token_type_ids""": token_type_ids,
            """head_mask""": head_mask,
        }

        return config, inputs_dict


@require_torch
class 						_snake_case   (       a__    ,				a__    ,				a__    ,				unittest.TestCase		):
     lowerCAmelCase :Dict						=   (
         (OpenAIGPTModel, OpenAIGPTLMHeadModel, OpenAIGPTDoubleHeadsModel, OpenAIGPTForSequenceClassification)
         if is_torch_available()
         else ()
     )
     lowerCAmelCase :Optional[Any]						=   (
         (OpenAIGPTLMHeadModel,) if is_torch_available() else ()
     )  # TODO (PVP): Add Double HeadsModel when generate() function is changed accordingly
     lowerCAmelCase :Union[str, Any]						=   (
         {
             '''feature-extraction''': OpenAIGPTModel,
             '''text-classification''': OpenAIGPTForSequenceClassification,
             '''text-generation''': OpenAIGPTLMHeadModel,
             '''zero-shot''': OpenAIGPTForSequenceClassification,
         }
         if is_torch_available()
         else {}
     )




     def 			snake_case__  ( self							,							_lowerCamelCase							,							_lowerCamelCase							,							_lowerCamelCase							,							_lowerCamelCase							,							_lowerCamelCase):




        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							,							_lowerCamelCase							,							_lowerCamelCase							,							_lowerCamelCase=False):
        UpperCAmelCase__					:   Optional[int]       				=       super()._prepare_for_class(_snake_case							,							_snake_case							,							return_labels=_snake_case)

        if return_labels:
           if model_class.__name__ == "OpenAIGPTDoubleHeadsModel":
              UpperCAmelCase__					:   Tuple       				=       torch.zeros(
                  (self.model_tester.batch_size, self.model_tester.num_choices, self.model_tester.seq_length)							,							dtype=torch.long							,							device=_snake_case							,							)
              UpperCAmelCase__					:   Any       				=       inputs_dict["""labels"""]
              UpperCAmelCase__					:   str       				=       inputs_dict["""labels"""]
              UpperCAmelCase__					:   Any       				=       torch.zeros(
                  (self.model_tester.batch_size, self.model_tester.num_choices)							,							dtype=torch.long							,							device=_snake_case							,							)
              UpperCAmelCase__					:   Dict       				=       torch.zeros(
                  self.model_tester.batch_size							,							dtype=torch.long							,							device=_snake_case)
        return inputs_dict




     def 			snake_case__  ( self):
        UpperCAmelCase__					:   Dict       				=       OpenAIGPTModelTester(self)
        UpperCAmelCase__					:   Optional[int]       				=       ConfigTester(self							,							config_class=_snake_case							,							n_embd=37)




     def 			snake_case__  ( self):
        self.config_tester.run_common_tests()




     def 			snake_case__  ( self):
        UpperCAmelCase__					:   Optional[Any]       				=       self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_openai_gpt_model(*_snake_case)




     def 			snake_case__  ( self):
        UpperCAmelCase__					:   Tuple       				=       self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_lm_head_model(*_snake_case)




     def 			snake_case__  ( self):
        UpperCAmelCase__					:   Optional[Any]       				=       self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_double_lm_head_model(*_snake_case)




     def 			snake_case__  ( self):
        UpperCAmelCase__					:   Optional[Any]       				=       self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_openai_gpt_for_sequence_classification(*_snake_case)




     @slow
     def 			snake_case__  ( self):




        for model_name in OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
           UpperCAmelCase__					:   Union[str, Any]       				=       OpenAIGPTModel.from_pretrained(_snake_case)
           self.assertIsNotNone(_snake_case)


@require_torch
class 						_snake_case   (       unittest.TestCase		):




     @slow
     def 			snake_case__  ( self):
        UpperCAmelCase__					:   Optional[int]       				=       OpenAIGPTLMHeadModel.from_pretrained("""openai-gpt""")
        model.to(_snake_case)
        UpperCAmelCase__					:   str       				=       torch.tensor([[481, 4735, 544]]							,							dtype=torch.long							,							device=_snake_case)  # the president is
        UpperCAmelCase__					:   Dict       				=       [
            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

        UpperCAmelCase__					:   Optional[int]       				=       model.generate(_snake_case							,							do_sample=_snake_case)
        self.assertListEqual(output_ids[0].tolist()							,							_snake_case)



'''simple docstring'''



def       _UpperCamelCase (						UpperCamelCase__ = 4_0_0_0_0_0_0   ):
			UpperCAmelCase__					:   List[str]       				=       [0, 1]
			UpperCAmelCase__					:   Any       				=       0
			while fib[i] <= n:
						fib.append(fib[i] + fib[i + 1]   )
						if fib[i + 2] > n:
									break
						i += 1
			UpperCAmelCase__					:   str       				=       0
			for j in range(len(UpperCamelCase__   ) - 1   ):
						if fib[j] % 2 == 0:
									total += fib[j]

			return total


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