






"""simple docstring"""






from collections import OrderedDict
from typing import Any, List, Mapping, Optional

from ... import PreTrainedTokenizer, TensorType, is_torch_available
from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfigWithPast, PatchingSpec
from ...utils import logging


UpperCAmelCase_   : Optional[Any]   			= logging.get_logger(__name__)

UpperCAmelCase_   : Optional[Any]   			= {
    'EleutherAI/gpt-j-6B': 'https://huggingface.co/EleutherAI/gpt-j-6B/resolve/main/config.json',
    # See all GPT-J models at https://huggingface.co/models?filter=gpt_j
}




class 							lowerCAmelCase__				(			UpperCAmelCase__ ):






      '''simple docstring'''

      __UpperCamelCase	 =  "gptj"
      __UpperCamelCase	 =  {
          "max_position_embeddings": "n_positions",
          "hidden_size": "n_embd",
          "num_attention_heads": "n_head",
          "num_hidden_layers": "n_layer",
      }
      def __init__(						self     :  Union[str, Any]						,	lowercase_     :  Dict=50400						,	lowercase_     :  List[Any]=2048						,	lowercase_     :  int=4096						,	lowercase_     :  List[str]=28						,	lowercase_     :  Tuple=16						,	lowercase_     :  Union[str, Any]=64						,	lowercase_     :  Union[str, Any]=None						,	lowercase_     :  str="gelu_new"						,	lowercase_     :  Union[str, Any]=0.0						,	lowercase_     :  Optional[int]=0.0						,	lowercase_     :  List[Any]=0.0						,	lowercase_     :  str=1e-5						,	lowercase_     :  int=0.02						,	lowercase_     :  Any=True						,	lowercase_     :  str=50256						,	lowercase_     :  Optional[int]=50256						,	lowercase_     :  int=False						,	**lowercase_     :  str						,	):




          '''simple docstring'''


          SCREAMING_SNAKE_CASE_      :  Tuple    						=		vocab_size
          SCREAMING_SNAKE_CASE_      :  Optional[int]    						=		n_positions
          SCREAMING_SNAKE_CASE_      :  Optional[Any]    						=		n_embd
          SCREAMING_SNAKE_CASE_      :  Dict    						=		n_layer
          SCREAMING_SNAKE_CASE_      :  Union[str, Any]    						=		n_head
          SCREAMING_SNAKE_CASE_      :  Union[str, Any]    						=		n_inner
          SCREAMING_SNAKE_CASE_      :  int    						=		rotary_dim
          SCREAMING_SNAKE_CASE_      :  Tuple    						=		activation_function
          SCREAMING_SNAKE_CASE_      :  int    						=		resid_pdrop
          SCREAMING_SNAKE_CASE_      :  str    						=		embd_pdrop
          SCREAMING_SNAKE_CASE_      :  Optional[Any]    						=		attn_pdrop
          SCREAMING_SNAKE_CASE_      :  Any    						=		layer_norm_epsilon
          SCREAMING_SNAKE_CASE_      :  Tuple    						=		initializer_range
          SCREAMING_SNAKE_CASE_      :  int    						=		use_cache

          SCREAMING_SNAKE_CASE_      :  Any    						=		bos_token_id
          SCREAMING_SNAKE_CASE_      :  str    						=		eos_token_id

          super().__init__(
              bos_token_id=lowercase_						,	eos_token_id=lowercase_						,	tie_word_embeddings=lowercase_						,	**lowercase_)




class 							lowerCAmelCase__				(			UpperCAmelCase__ ):






      '''simple docstring'''

      def __init__(						self     :  Union[str, Any]						,	lowercase_     :  Any						,	lowercase_     :  Tuple = "default"						,	lowercase_     :  Union[str, Any] = None						,	lowercase_     :  Any = False						,	):




          '''simple docstring'''


          super().__init__(lowercase_						,	task=lowercase_						,	patching_specs=lowercase_						,	use_past=lowercase_)
          if not getattr(self._config						,	'''pad_token_id'''						,	lowercase_):
              # TODO: how to do that better?
              SCREAMING_SNAKE_CASE_      :  List[str]    						=		0
      @property
      def _SCREAMING_SNAKE_CASE (						self     :  Tuple):




          '''simple docstring'''


          SCREAMING_SNAKE_CASE_      :  List[str]    						=		OrderedDict({'''input_ids''': {0: '''batch''', 1: '''sequence'''}})
          if self.use_past:
              self.fill_with_past_key_values_(lowercase_						,	direction='''inputs''')
              SCREAMING_SNAKE_CASE_      :  List[Any]    						=		{0: '''batch''', 1: '''past_sequence + sequence'''}
          else:
              SCREAMING_SNAKE_CASE_      :  Optional[int]    						=		{0: '''batch''', 1: '''sequence'''}

          return common_inputs
      @property
      def _SCREAMING_SNAKE_CASE (						self     :  List[Any]):




          '''simple docstring'''


          return self._config.n_layer
      @property
      def _SCREAMING_SNAKE_CASE (						self     :  Union[str, Any]):




          '''simple docstring'''


          return self._config.n_head
      def _SCREAMING_SNAKE_CASE (						self     :  int						,	lowercase_     :  Optional[int]						,	lowercase_     :  Tuple = -1						,	lowercase_     :  Optional[Any] = -1						,	lowercase_     :  List[Any] = False						,	lowercase_     :  Union[str, Any] = None						,	):




          '''simple docstring'''


          SCREAMING_SNAKE_CASE_      :  Optional[Any]    						=		super(lowercase_						,	self).generate_dummy_inputs(
              lowercase_						,	batch_size=lowercase_						,	seq_length=lowercase_						,	is_pair=lowercase_						,	framework=lowercase_)

          # We need to order the input in the way they appears in the forward()
          SCREAMING_SNAKE_CASE_      :  Optional[Any]    						=		OrderedDict({'''input_ids''': common_inputs['''input_ids''']})

          # Need to add the past_keys
          if self.use_past:
              if not is_torch_available():
                  raise ValueError('''Cannot generate dummy past_keys inputs without PyTorch installed.''')
              else:
                  import torch

                  SCREAMING_SNAKE_CASE_      :  Optional[int]    						=		common_inputs['''input_ids'''].shape
                  # Not using the same length for past_key_values
                  SCREAMING_SNAKE_CASE_      :  Dict    						=		seqlen + 2
                  SCREAMING_SNAKE_CASE_      :  Tuple    						=		(
                      batch,
                      self.num_attention_heads,
                      past_key_values_length,
                      self._config.hidden_size // self.num_attention_heads,
                  )
                  SCREAMING_SNAKE_CASE_      :  List[Any]    						=		[
                      (torch.zeros(lowercase_), torch.zeros(lowercase_)) for _ in range(self.num_layers)
                  ]

          SCREAMING_SNAKE_CASE_      :  Optional[Any]    						=		common_inputs['''attention_mask''']
          if self.use_past:
              SCREAMING_SNAKE_CASE_      :  Any    						=		ordered_inputs['''attention_mask'''].dtype
              SCREAMING_SNAKE_CASE_      :  Union[str, Any]    						=		torch.cat(
                  [ordered_inputs['''attention_mask'''], torch.ones(lowercase_						,	lowercase_						,	dtype=lowercase_)]						,	dim=1)

          return ordered_inputs



      @property
      def _SCREAMING_SNAKE_CASE (						self     :  str):




          '''simple docstring'''


          return 13







"""simple docstring"""
import unittest

from datasets import load_dataset

from transformers.pipelines import pipeline
from transformers.testing_utils import is_pipeline_test, nested_simplify, require_torch, slow
@is_pipeline_test
@require_torch
class 							_UpperCAmelCase							( unittest.TestCase      ):





     '''simple docstring'''



     @require_torch
     def  __lowerCAmelCase	(					self		)							->					Any:
         _UpperCAmelCase							:  str											=    pipeline(
             task='''zero-shot-audio-classification'''       ,	model='''hf-internal-testing/tiny-clap-htsat-unfused'''		)
         _UpperCAmelCase							:  List[Any]											=    load_dataset('''ashraq/esc50'''		)
         _UpperCAmelCase							:  Optional[int]											=    dataset['''train''']['''audio'''][-1]['''array''']
         _UpperCAmelCase							:  str											=    audio_classifier(A       ,	candidate_labels=['''Sound of a dog''', '''Sound of vaccum cleaner''']		)
         self.assertEqual(
             nested_simplify(A		)       ,	[{'''score''': 0.501, '''label''': '''Sound of a dog'''}, {'''score''': 0.499, '''label''': '''Sound of vaccum cleaner'''}]       ,	)





     @unittest.skip('''No models are available in TF'''		)
     def  __lowerCAmelCase	(					self		)							->					Union[str, Any]:
         pass





     @slow
     @require_torch
     def  __lowerCAmelCase	(					self		)							->					str:
         _UpperCAmelCase							:  Union[str, Any]											=    pipeline(
             task='''zero-shot-audio-classification'''       ,	model='''laion/clap-htsat-unfused'''       ,	)
         # This is an audio of a dog
         _UpperCAmelCase							:  List[Any]											=    load_dataset('''ashraq/esc50'''		)
         _UpperCAmelCase							:  Optional[int]											=    dataset['''train''']['''audio'''][-1]['''array''']
         _UpperCAmelCase							:  Any											=    audio_classifier(A       ,	candidate_labels=['''Sound of a dog''', '''Sound of vaccum cleaner''']		)

         self.assertEqual(
             nested_simplify(A		)       ,	[
                 {'''score''': 0.999, '''label''': '''Sound of a dog'''},
                 {'''score''': 0.001, '''label''': '''Sound of vaccum cleaner'''},
             ]       ,	)

         _UpperCAmelCase							:  List[Any]											=    audio_classifier([audio] * 5       ,	candidate_labels=['''Sound of a dog''', '''Sound of vaccum cleaner''']		)
         self.assertEqual(
             nested_simplify(A		)       ,	[
                 [
                     {'''score''': 0.999, '''label''': '''Sound of a dog'''},
                     {'''score''': 0.001, '''label''': '''Sound of vaccum cleaner'''},
                 ],
             ]
             * 5       ,	)
         _UpperCAmelCase							:  Tuple											=    audio_classifier(
             [audio] * 5       ,	candidate_labels=['''Sound of a dog''', '''Sound of vaccum cleaner''']       ,	batch_size=5		)
         self.assertEqual(
             nested_simplify(A		)       ,	[
                 [
                     {'''score''': 0.999, '''label''': '''Sound of a dog'''},
                     {'''score''': 0.001, '''label''': '''Sound of vaccum cleaner'''},
                 ],
             ]
             * 5       ,	)





     @unittest.skip('''No models are available in TF'''		)
     def  __lowerCAmelCase	(					self		)							->					int:
         pass


