






import shutil
import tempfile
import unittest

from transformers import ClapFeatureExtractor, ClapProcessor, RobertaTokenizer, RobertaTokenizerFast
from transformers.testing_utils import require_sentencepiece, require_torchaudio

from .test_feature_extraction_clap import floats_list
@require_torchaudio
@require_sentencepiece
class 		SCREAMING_SNAKE_CASE__	(  unittest.TestCase     ):

  '''simple docstring'''







  def  lowerCamelCase       (      self		:			str							)						->	List[Any]:


         """simple docstring"""
         _UpperCAmelCase							=    """laion/clap-htsat-unfused"""
         _UpperCAmelCase							=    tempfile.mkdtemp()


  def  lowerCamelCase       (      self		:			List[str]       ,				**lowerCamelCase		:			List[str]							)						->	List[Any]:


         """simple docstring"""
         return RobertaTokenizer.from_pretrained(self.checkpoint       ,				**lowerCamelCase							)


  def  lowerCamelCase       (      self		:			List[Any]       ,				**lowerCamelCase		:			Any							)						->	Any:


         """simple docstring"""
         return ClapFeatureExtractor.from_pretrained(self.checkpoint       ,				**lowerCamelCase							)


  def  lowerCamelCase       (      self		:			Optional[int]							)						->	str:


         """simple docstring"""
         shutil.rmtree(self.tmpdirname							)


  def  lowerCamelCase       (      self		:			Any							)						->	int:


         """simple docstring"""
         _UpperCAmelCase							=    self.get_tokenizer()
         _UpperCAmelCase							=    self.get_feature_extractor()

         _UpperCAmelCase							=    ClapProcessor(tokenizer=lowerCamelCase       ,				feature_extractor=lowerCamelCase							)

         processor.save_pretrained(self.tmpdirname							)
         _UpperCAmelCase							=    ClapProcessor.from_pretrained(self.tmpdirname							)

         self.assertEqual(processor.tokenizer.get_vocab()       ,				tokenizer.get_vocab()							)
         self.assertIsInstance(processor.tokenizer       ,				lowerCamelCase							)

         self.assertEqual(processor.feature_extractor.to_json_string()       ,				feature_extractor.to_json_string()							)
         self.assertIsInstance(processor.feature_extractor       ,				lowerCamelCase							)


  def  lowerCamelCase       (      self		:			str							)						->	Optional[int]:


         """simple docstring"""
         _UpperCAmelCase							=    ClapProcessor(tokenizer=self.get_tokenizer()       ,				feature_extractor=self.get_feature_extractor()							)
         processor.save_pretrained(self.tmpdirname							)

         _UpperCAmelCase							=    self.get_tokenizer(bos_token="""(BOS)"""       ,				eos_token="""(EOS)"""							)
         _UpperCAmelCase							=    self.get_feature_extractor(do_normalize=lowerCamelCase       ,				padding_value=1.0							)

         _UpperCAmelCase							=    ClapProcessor.from_pretrained(
             self.tmpdirname       ,				bos_token="""(BOS)"""       ,				eos_token="""(EOS)"""       ,				do_normalize=lowerCamelCase       ,				padding_value=1.0							)

         self.assertEqual(processor.tokenizer.get_vocab()       ,				tokenizer_add_kwargs.get_vocab()							)
         self.assertIsInstance(processor.tokenizer       ,				lowerCamelCase							)

         self.assertEqual(processor.feature_extractor.to_json_string()       ,				feature_extractor_add_kwargs.to_json_string()							)
         self.assertIsInstance(processor.feature_extractor       ,				lowerCamelCase							)


  def  lowerCamelCase       (      self		:			Tuple							)						->	List[Any]:


         """simple docstring"""
         _UpperCAmelCase							=    self.get_feature_extractor()
         _UpperCAmelCase							=    self.get_tokenizer()

         _UpperCAmelCase							=    ClapProcessor(tokenizer=lowerCamelCase       ,				feature_extractor=lowerCamelCase							)

         _UpperCAmelCase							=    floats_list((3, 1000)							)

         _UpperCAmelCase							=    feature_extractor(lowerCamelCase       ,				return_tensors="""np"""							)
         _UpperCAmelCase							=    processor(audios=lowerCamelCase       ,				return_tensors="""np"""							)

         for key in input_feat_extract.keys():
                self.assertAlmostEqual(input_feat_extract[key].sum()       ,				input_processor[key].sum()       ,				delta=1E-2							)


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


         """simple docstring"""
         _UpperCAmelCase							=    self.get_feature_extractor()
         _UpperCAmelCase							=    self.get_tokenizer()

         _UpperCAmelCase							=    ClapProcessor(tokenizer=lowerCamelCase       ,				feature_extractor=lowerCamelCase							)

         _UpperCAmelCase							=    """This is a test string"""

         _UpperCAmelCase							=    processor(text=lowerCamelCase							)

         _UpperCAmelCase							=    tokenizer(lowerCamelCase							)

         for key in encoded_tok.keys():
                self.assertListEqual(encoded_tok[key]       ,				encoded_processor[key]							)


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


         """simple docstring"""
         _UpperCAmelCase							=    self.get_feature_extractor()
         _UpperCAmelCase							=    self.get_tokenizer()

         _UpperCAmelCase							=    ClapProcessor(tokenizer=lowerCamelCase       ,				feature_extractor=lowerCamelCase							)

         _UpperCAmelCase							=    [[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

         _UpperCAmelCase							=    processor.batch_decode(lowerCamelCase							)
         _UpperCAmelCase							=    tokenizer.batch_decode(lowerCamelCase							)

         self.assertListEqual(lowerCamelCase       ,				lowerCamelCase							)





  def  lowerCamelCase       (      self		:			Optional[Any]							)						->	List[Any]:


         """simple docstring"""
         _UpperCAmelCase							=    self.get_feature_extractor()
         _UpperCAmelCase							=    self.get_tokenizer()

         _UpperCAmelCase							=    ClapProcessor(tokenizer=lowerCamelCase       ,				feature_extractor=lowerCamelCase							)

         self.assertListEqual(
             processor.model_input_names[2:]       ,				feature_extractor.model_input_names       ,				msg="""`processor` and `feature_extractor` model input names do not match"""       ,				)






'''simple docstring'''


from ...configuration_utils import PretrainedConfig
from ...utils import logging


_SCREAMING_SNAKE_CASE									=				logging.get_logger(__name__)

_SCREAMING_SNAKE_CASE									=				{
    "tiiuae/falcon-40b": "https://huggingface.co/tiiuae/falcon-40b/resolve/main/config.json",
    "tiiuae/falcon-7b": "https://huggingface.co/tiiuae/falcon-7b/resolve/main/config.json",
}

class  lowerCAmelCase_		(		__magic_name__		):
 __lowerCamelCase    :				Any								=       "falcon"
 __lowerCamelCase    :				List[str]								=       ["past_key_values"]




 def __init__(						self      ,  _lowerCAmelCase=65024      ,  _lowerCAmelCase=4544      ,  _lowerCAmelCase=32      ,  _lowerCAmelCase=71      ,  _lowerCAmelCase=1E-5      ,  _lowerCAmelCase=0.02      ,  _lowerCAmelCase=True      ,  _lowerCAmelCase=0.0      ,  _lowerCAmelCase=0.0      ,  _lowerCAmelCase=None      ,  _lowerCAmelCase=False      ,  _lowerCAmelCase=False      ,  _lowerCAmelCase=True      ,  _lowerCAmelCase=True      ,  _lowerCAmelCase=False      ,  _lowerCAmelCase=11      ,  _lowerCAmelCase=11      ,  **_lowerCAmelCase      ,  )     ->				Union[str, Any]:
     _lowerCAmelCase						      =   vocab_size
     # Backward compatibility with n_embed kwarg
     _lowerCAmelCase						      =   kwargs.pop("n_embed"      ,  _lowerCAmelCase		)
     _lowerCAmelCase						      =   hidden_size if n_embed is None else n_embed
     _lowerCAmelCase						      =   num_hidden_layers
     _lowerCAmelCase						      =   num_attention_heads
     _lowerCAmelCase						      =   layer_norm_epsilon
     _lowerCAmelCase						      =   initializer_range
     _lowerCAmelCase						      =   use_cache
     _lowerCAmelCase						      =   hidden_dropout
     _lowerCAmelCase						      =   attention_dropout

     _lowerCAmelCase						      =   bos_token_id
     _lowerCAmelCase						      =   eos_token_id
     _lowerCAmelCase						      =   num_attention_heads if num_kv_heads is None else num_kv_heads
     _lowerCAmelCase						      =   alibi
     _lowerCAmelCase						      =   new_decoder_architecture
     _lowerCAmelCase						      =   multi_query  # Ignored when new_decoder_architecture is True
     _lowerCAmelCase						      =   parallel_attn
     _lowerCAmelCase						      =   bias

     super().__init__(bos_token_id=_lowerCAmelCase      ,  eos_token_id=_lowerCAmelCase      ,  **_lowerCAmelCase		)




 @property
 def 				_snake_case (						self		)     ->				Optional[Any]:
     return self.hidden_size // self.num_attention_heads





 @property
 def 				_snake_case (						self		)     ->				Optional[Any]:
     return not self.alibi


