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





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





 def        snake_case__		(    self):
     snake_case_ :    str     			=						ids_tensor([self.batch_size, self.seq_length] ,       self.vocab_size)

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

     snake_case_ :    Optional[int]     			=						None
     snake_case_ :    List[Any]     			=						None
     snake_case_ :    Optional[int]     			=						None
     if self.use_labels:
         snake_case_ :    str     			=						ids_tensor([self.batch_size] ,       self.type_sequence_label_size)
         snake_case_ :    str     			=						ids_tensor([self.batch_size, self.seq_length] ,       self.num_labels)
         snake_case_ :    Dict     			=						ids_tensor([self.batch_size] ,       self.num_choices)

     snake_case_ :    List[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 ,       )

     snake_case_ :    Tuple     			=						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 ,       lowercase_ ,       lowercase_ ,       lowercase_ ,       lowercase_ ,       *lowercase_):
     snake_case_ :    int     			=						OpenAIGPTModel(config=UpperCamelCase__)
     model.to(UpperCamelCase__)
     model.eval()

     snake_case_ :    str     			=						model(UpperCamelCase__ ,       token_type_ids=UpperCamelCase__ ,       head_mask=UpperCamelCase__)
     snake_case_ :    Tuple     			=						model(UpperCamelCase__ ,       token_type_ids=UpperCamelCase__)
     snake_case_ :    Any     			=						model(UpperCamelCase__)

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





 def        snake_case__		(    self ,       lowercase_ ,       lowercase_ ,       lowercase_ ,       lowercase_ ,       *lowercase_):
     snake_case_ :    Tuple     			=						OpenAIGPTLMHeadModel(UpperCamelCase__)
     model.to(UpperCamelCase__)
     model.eval()

     snake_case_ :    List[str]     			=						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 ,       lowercase_ ,       lowercase_ ,       lowercase_ ,       lowercase_ ,       *lowercase_):
     snake_case_ :    Any     			=						OpenAIGPTDoubleHeadsModel(UpperCamelCase__)
     model.to(UpperCamelCase__)
     model.eval()

     snake_case_ :    str     			=						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 ,       lowercase_ ,       lowercase_ ,       lowercase_ ,       lowercase_ ,       *lowercase_):
     snake_case_ :    str     			=						self.num_labels
     snake_case_ :    int     			=						OpenAIGPTForSequenceClassification(UpperCamelCase__)
     model.to(UpperCamelCase__)
     model.eval()

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





 def        snake_case__		(    self):
     snake_case_ :    Optional[int]     			=						self.prepare_config_and_inputs()
     (
         snake_case_       
     ) :    Optional[Any]     			=						config_and_inputs
     snake_case_ :    List[Any]     			=						{
         'input_ids': input_ids,
         'token_type_ids': token_type_ids,
         'head_mask': head_mask,
     }

     return config, inputs_dict






@require_torch
class    UpperCAmelCase_				(	__A    ,						__A    ,						__A    ,						unittest.TestCase					):
 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 ,       lowercase_ ,       lowercase_ ,       lowercase_ ,       lowercase_ ,       lowercase_):
     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 ,       lowercase_ ,       lowercase_ ,       lowercase_=False):
     snake_case_ :    Any     			=						super()._prepare_for_class(UpperCamelCase__ ,       UpperCamelCase__ ,       return_labels=UpperCamelCase__)

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





 def        snake_case__		(    self):
     snake_case_ :    List[Any]     			=						OpenAIGPTModelTester(self)
     snake_case_ :    Union[str, Any]     			=						ConfigTester(self ,       config_class=UpperCamelCase__ ,       n_embd=37)





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





 def        snake_case__		(    self):
     snake_case_ :    Any     			=						self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_openai_gpt_model(*UpperCamelCase__)





 def        snake_case__		(    self):
     snake_case_ :    str     			=						self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_lm_head_model(*UpperCamelCase__)





 def        snake_case__		(    self):
     snake_case_ :    Dict     			=						self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_double_lm_head_model(*UpperCamelCase__)





 def        snake_case__		(    self):
     snake_case_ :    List[Any]     			=						self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_openai_gpt_for_sequence_classification(*UpperCamelCase__)





 @slow
 def        snake_case__		(    self):
     for model_name in OPENAI_GPT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
         snake_case_ :    Optional[int]     			=						OpenAIGPTModel.from_pretrained(UpperCamelCase__)
         self.assertIsNotNone(UpperCamelCase__)






@require_torch
class    UpperCAmelCase_				(	unittest.TestCase					):





 @slow
 def        snake_case__		(    self):
     snake_case_ :    List[Any]     			=						OpenAIGPTLMHeadModel.from_pretrained("openai-gpt")
     model.to(UpperCamelCase__)
     snake_case_ :    List[Any]     			=						torch.tensor([[4_81, 47_35, 5_44]] ,       dtype=torch.long ,       device=UpperCamelCase__)  # the president is
     snake_case_ :    Any     			=						[
         4_81,
         47_35,
         5_44,
         2_46,
         9_63,
         8_70,
         7_62,
         2_39,
         2_44,
         4_04_77,
         2_44,
         2_49,
         7_19,
         8_81,
         4_87,
         5_44,
         2_40,
         2_44,
         6_03,
         4_81,
     ]  # the president is a very good man. " \n " i\'m sure he is, " said the

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






'''simple docstring'''
from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


a_											=						{"configuration_wavlm": ["WAVLM_PRETRAINED_CONFIG_ARCHIVE_MAP", "WavLMConfig"]}

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  a_											=						[
      "WAVLM_PRETRAINED_MODEL_ARCHIVE_LIST",
      "WavLMForAudioFrameClassification",
      "WavLMForCTC",
      "WavLMForSequenceClassification",
      "WavLMForXVector",
      "WavLMModel",
      "WavLMPreTrainedModel",
  ]

if TYPE_CHECKING:
  from .configuration_wavlm import WAVLM_PRETRAINED_CONFIG_ARCHIVE_MAP, WavLMConfig

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_wavlm import (
        WAVLM_PRETRAINED_MODEL_ARCHIVE_LIST,
        WavLMForAudioFrameClassification,
        WavLMForCTC,
        WavLMForSequenceClassification,
        WavLMForXVector,
        WavLMModel,
        WavLMPreTrainedModel,
    )

else:
  import sys

  a_											=						_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)




