

'''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		,					UpperCamelCase__		,					UpperCamelCase__=13		,					UpperCamelCase__=7		,					UpperCamelCase__=True		,					UpperCamelCase__=True		,					UpperCamelCase__=True		,					UpperCamelCase__=99		,					UpperCamelCase__=32		,					UpperCamelCase__=5		,					UpperCamelCase__=4		,					UpperCamelCase__=37		,					UpperCamelCase__="gelu"		,					UpperCamelCase__=0.1		,					UpperCamelCase__=0.1		,					UpperCamelCase__=512		,					UpperCamelCase__=16		,					UpperCamelCase__=2		,					UpperCamelCase__=0.02		,					UpperCamelCase__=3		,					UpperCamelCase__=4		,					UpperCamelCase__=None		,					)    ->   Any:





           '''simple docstring'''
           A_						       =   parent
           A_						       =   batch_size
           A_						       =   seq_length
           A_						       =   is_training
           A_						       =   use_token_type_ids
           A_						       =   use_labels
           A_						       =   vocab_size
           A_						       =   hidden_size
           A_						       =   num_hidden_layers
           A_						       =   num_attention_heads
           A_						       =   intermediate_size
           A_						       =   hidden_act
           A_						       =   hidden_dropout_prob
           A_						       =   attention_probs_dropout_prob
           A_						       =   max_position_embeddings
           A_						       =   type_vocab_size
           A_						       =   type_sequence_label_size
           A_						       =   initializer_range
           A_						       =   num_labels
           A_						       =   num_choices
           A_						       =   scope
           A_						       =   self.vocab_size - 1



    def        snake_case_      (       self							)    ->   Optional[int]:





           '''simple docstring'''
           A_						       =   ids_tensor([self.batch_size, self.seq_length]		,					self.vocab_size							)

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

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

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

           A_						       =   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		,					UpperCamelCase__		,					UpperCamelCase__		,					UpperCamelCase__		,					UpperCamelCase__		,					*UpperCamelCase__							)    ->   int:





           '''simple docstring'''
           A_						       =   OpenAIGPTModel(config=UpperCamelCase_							)
           model.to(UpperCamelCase_							)
           model.eval()

           A_						       =   model(UpperCamelCase_		,					token_type_ids=UpperCamelCase_		,					head_mask=UpperCamelCase_							)
           A_						       =   model(UpperCamelCase_		,					token_type_ids=UpperCamelCase_							)
           A_						       =   model(UpperCamelCase_							)

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



    def        snake_case_      (       self		,					UpperCamelCase__		,					UpperCamelCase__		,					UpperCamelCase__		,					UpperCamelCase__		,					*UpperCamelCase__							)    ->   List[str]:





           '''simple docstring'''
           A_						       =   OpenAIGPTLMHeadModel(UpperCamelCase_							)
           model.to(UpperCamelCase_							)
           model.eval()

           A_						       =   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        snake_case_      (       self		,					UpperCamelCase__		,					UpperCamelCase__		,					UpperCamelCase__		,					UpperCamelCase__		,					*UpperCamelCase__							)    ->   int:





           '''simple docstring'''
           A_						       =   OpenAIGPTDoubleHeadsModel(UpperCamelCase_							)
           model.to(UpperCamelCase_							)
           model.eval()

           A_						       =   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        snake_case_      (       self		,					UpperCamelCase__		,					UpperCamelCase__		,					UpperCamelCase__		,					UpperCamelCase__		,					*UpperCamelCase__							)    ->   Optional[int]:





           '''simple docstring'''
           A_						       =   self.num_labels
           A_						       =   OpenAIGPTForSequenceClassification(UpperCamelCase_							)
           model.to(UpperCamelCase_							)
           model.eval()

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







    def        snake_case_      (       self							)    ->   Union[str, Any]:





           '''simple docstring'''
           A_						       =   self.prepare_config_and_inputs()
           (
               A_							
           )						       =   config_and_inputs
           A_						       =   {
               '''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      ):
    lowercase						       =		(
        (OpenAIGPTModel, OpenAIGPTLMHeadModel, OpenAIGPTDoubleHeadsModel, OpenAIGPTForSequenceClassification)
        if is_torch_available()
        else ()
    )
    lowercase						       =		(
        (OpenAIGPTLMHeadModel,) if is_torch_available() else ()
    )  # TODO (PVP): Add Double HeadsModel when generate() function is changed accordingly
    lowercase						       =		(
        {
            "feature-extraction": OpenAIGPTModel,
            "text-classification": OpenAIGPTForSequenceClassification,
            "text-generation": OpenAIGPTLMHeadModel,
            "zero-shot": OpenAIGPTForSequenceClassification,
        }
        if is_torch_available()
        else {}
    )



    def        snake_case_      (       self		,					UpperCamelCase__		,					UpperCamelCase__		,					UpperCamelCase__		,					UpperCamelCase__		,					UpperCamelCase__							)    ->   Optional[int]:





           '''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		,					UpperCamelCase__		,					UpperCamelCase__		,					UpperCamelCase__=False							)    ->   Optional[int]:





           '''simple docstring'''
           A_						       =   super()._prepare_for_class(UpperCamelCase_		,					UpperCamelCase_		,					return_labels=UpperCamelCase_							)

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



    def        snake_case_      (       self							)    ->   List[str]:





           '''simple docstring'''
           A_						       =   OpenAIGPTModelTester(self							)
           A_						       =   ConfigTester(self		,					config_class=UpperCamelCase_		,					n_embd=37							)



    def        snake_case_      (       self							)    ->   List[Any]:





           '''simple docstring'''
           self.config_tester.run_common_tests()



    def        snake_case_      (       self							)    ->   str:





           '''simple docstring'''
           A_						       =   self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_openai_gpt_model(*UpperCamelCase_							)



    def        snake_case_      (       self							)    ->   Tuple:





           '''simple docstring'''
           A_						       =   self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_lm_head_model(*UpperCamelCase_							)



    def        snake_case_      (       self							)    ->   Optional[int]:





           '''simple docstring'''
           A_						       =   self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_double_lm_head_model(*UpperCamelCase_							)



    def        snake_case_      (       self							)    ->   str:





           '''simple docstring'''
           A_						       =   self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_openai_gpt_for_sequence_classification(*UpperCamelCase_							)







    @slow
    def        snake_case_      (       self							)    ->   Dict:





           '''simple docstring'''


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


@require_torch
class        A__   (   unittest.TestCase      ):



    @slow
    def        snake_case_      (       self							)    ->   int:





           '''simple docstring'''
           A_						       =   OpenAIGPTLMHeadModel.from_pretrained("""openai-gpt"""							)
           model.to(UpperCamelCase_							)
           A_						       =   torch.tensor([[481, 4735, 544]]		,					dtype=torch.long		,					device=UpperCamelCase_							)  # the president is
           A_						       =   [
               481,
               4735,
               544,
               246,
               963,
               870,
               762,
               239,
               244,
               40477,
               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

           A_						       =   model.generate(UpperCamelCase_		,					do_sample=UpperCamelCase_							)
           self.assertListEqual(output_ids[0].tolist()		,					UpperCamelCase_							)




'''simple docstring'''
from __future__ import annotations

from math import pi, sqrt


def      a (     __a					,   __a  )    ->      tuple:



					'''simple docstring'''






					if inductance <= 0:
										raise ValueError('''Inductance cannot be 0 or negative'''  )

					elif capacitance <= 0:
										raise ValueError('''Capacitance cannot be 0 or negative'''  )

					else:
										return (
										    "Resonant frequency",
										    float(1 / (2 * pi * (sqrt(inductance * capacitance  )))  ),
										)


if __name__ == "__main__":
		import doctest

		doctest.testmod()