


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 A    (  unittest.TestCase	):






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




             _lowerCamelCase			:						Any            ='laion/clap-htsat-unfused'
             _lowerCamelCase			:						str            =tempfile.mkdtemp()






      def 			lowerCamelCase			(   self		:	Union[str, Any]     ,  **lowercase_		:	List[Any]					)   ->		Tuple:
             """simple docstring"""




             return RobertaTokenizer.from_pretrained(self.checkpoint     ,  **lowercase_					)






      def 			lowerCamelCase			(   self		:	List[str]     ,  **lowercase_		:	Union[str, Any]					)   ->		Optional[int]:
             """simple docstring"""




             return ClapFeatureExtractor.from_pretrained(self.checkpoint     ,  **lowercase_					)






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




             shutil.rmtree(self.tmpdirname					)






      def 			lowerCamelCase			(   self		:	Optional[int]					)   ->		Union[str, Any]:
             """simple docstring"""




             _lowerCamelCase			:						str            =self.get_tokenizer()
             _lowerCamelCase			:						Optional[Any]            =self.get_feature_extractor()

             _lowerCamelCase			:						Tuple            =ClapProcessor(tokenizer=lowercase_     ,  feature_extractor=lowercase_					)

             processor.save_pretrained(self.tmpdirname					)
             _lowerCamelCase			:						int            =ClapProcessor.from_pretrained(self.tmpdirname					)

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

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






      def 			lowerCamelCase			(   self		:	Dict					)   ->		int:
             """simple docstring"""




             _lowerCamelCase			:						Optional[Any]            =ClapProcessor(tokenizer=self.get_tokenizer()     ,  feature_extractor=self.get_feature_extractor()					)
             processor.save_pretrained(self.tmpdirname					)

             _lowerCamelCase			:						Dict            =self.get_tokenizer(bos_token='(BOS)'     ,  eos_token='(EOS)'					)
             _lowerCamelCase			:						List[str]            =self.get_feature_extractor(do_normalize=lowercase_     ,  padding_value=1.0					)

             _lowerCamelCase			:						Optional[int]            =ClapProcessor.from_pretrained(
                 self.tmpdirname     ,  bos_token='(BOS)'     ,  eos_token='(EOS)'     ,  do_normalize=lowercase_     ,  padding_value=1.0					)

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

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






      def 			lowerCamelCase			(   self		:	int					)   ->		Optional[int]:
             """simple docstring"""




             _lowerCamelCase			:						List[str]            =self.get_feature_extractor()
             _lowerCamelCase			:						List[Any]            =self.get_tokenizer()

             _lowerCamelCase			:						str            =ClapProcessor(tokenizer=lowercase_     ,  feature_extractor=lowercase_					)

             _lowerCamelCase			:						Optional[int]            =floats_list((3, 1000)					)

             _lowerCamelCase			:						Union[str, Any]            =feature_extractor(lowercase_     ,  return_tensors='np'					)
             _lowerCamelCase			:						List[str]            =processor(audios=lowercase_     ,  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		:	Tuple					)   ->		Dict:
             """simple docstring"""




             _lowerCamelCase			:						Any            =self.get_feature_extractor()
             _lowerCamelCase			:						Any            =self.get_tokenizer()

             _lowerCamelCase			:						int            =ClapProcessor(tokenizer=lowercase_     ,  feature_extractor=lowercase_					)

             _lowerCamelCase			:						int            ='This is a test string'

             _lowerCamelCase			:						Optional[int]            =processor(text=lowercase_					)

             _lowerCamelCase			:						str            =tokenizer(lowercase_					)

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






      def 			lowerCamelCase			(   self		:	Tuple					)   ->		Any:
             """simple docstring"""




             _lowerCamelCase			:						List[str]            =self.get_feature_extractor()
             _lowerCamelCase			:						int            =self.get_tokenizer()

             _lowerCamelCase			:						int            =ClapProcessor(tokenizer=lowercase_     ,  feature_extractor=lowercase_					)

             _lowerCamelCase			:						Dict            =[[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

             _lowerCamelCase			:						Dict            =processor.batch_decode(lowercase_					)
             _lowerCamelCase			:						Optional[Any]            =tokenizer.batch_decode(lowercase_					)

             self.assertListEqual(lowercase_     ,  lowercase_					)






      def 			lowerCamelCase			(   self		:	Tuple					)   ->		Tuple:
             """simple docstring"""




             _lowerCamelCase			:						Tuple            =self.get_feature_extractor()
             _lowerCamelCase			:						Tuple            =self.get_tokenizer()

             _lowerCamelCase			:						Tuple            =ClapProcessor(tokenizer=lowercase_     ,  feature_extractor=lowercase_					)

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






from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


lowerCamelCase		   =			logging.get_logger(__name__)

lowerCamelCase		   =			{
    'microsoft/focalnet-tiny': 'https://huggingface.co/microsoft/focalnet-tiny/resolve/main/config.json',
}




class A    (  UpperCamelCase_       ,				UpperCamelCase_	):
      UpperCamelCase__				:    str ='focalnet'






      def __init__(   self		:	Optional[int]     ,  lowercase_		:	List[Any]=224     ,  lowercase_		:	str=4     ,  lowercase_		:	Any=3     ,  lowercase_		:	Dict=96     ,  lowercase_		:	List[str]=False     ,  lowercase_		:	Any=[192, 384, 768, 768]     ,  lowercase_		:	Dict=[2, 2, 6, 2]     ,  lowercase_		:	Optional[int]=[2, 2, 2, 2]     ,  lowercase_		:	List[Any]=[3, 3, 3, 3]     ,  lowercase_		:	Any="gelu"     ,  lowercase_		:	str=4.0     ,  lowercase_		:	List[Any]=0.0     ,  lowercase_		:	Tuple=0.1     ,  lowercase_		:	Optional[Any]=False     ,  lowercase_		:	Optional[int]=1E-4     ,  lowercase_		:	Dict=False     ,  lowercase_		:	Optional[Any]=False     ,  lowercase_		:	Dict=False     ,  lowercase_		:	List[Any]=0.02     ,  lowercase_		:	Any=1E-5     ,  lowercase_		:	Any=32     ,  lowercase_		:	List[str]=None     ,  lowercase_		:	int=None     ,  **lowercase_		:	Optional[Any]     ,  )   ->		Optional[Any]:
             """simple docstring"""




             super().__init__(**lowercase_					)

             _lowerCamelCase			:						Union[str, Any]            =image_size
             _lowerCamelCase			:						str            =patch_size
             _lowerCamelCase			:						str            =num_channels
             _lowerCamelCase			:						Tuple            =embed_dim
             _lowerCamelCase			:						Dict            =use_conv_embed
             _lowerCamelCase			:						int            =hidden_sizes
             _lowerCamelCase			:						str            =depths
             _lowerCamelCase			:						int            =focal_levels
             _lowerCamelCase			:						List[Any]            =focal_windows
             _lowerCamelCase			:						List[Any]            =hidden_act
             _lowerCamelCase			:						int            =mlp_ratio
             _lowerCamelCase			:						Any            =hidden_dropout_prob
             _lowerCamelCase			:						Optional[Any]            =drop_path_rate
             _lowerCamelCase			:						int            =use_layerscale
             _lowerCamelCase			:						str            =layerscale_value
             _lowerCamelCase			:						Dict            =use_post_layernorm
             _lowerCamelCase			:						str            =use_post_layernorm_in_modulation
             _lowerCamelCase			:						List[Any]            =normalize_modulator
             _lowerCamelCase			:						Optional[Any]            =initializer_range
             _lowerCamelCase			:						List[str]            =layer_norm_eps
             _lowerCamelCase			:						Optional[int]            =encoder_stride
             _lowerCamelCase			:						List[str]            =['stem'] + [F'''stage{idx}''' for idx in range(1     ,  len(self.depths					) + 1					)]
             _lowerCamelCase      ,	_lowerCamelCase			:						Union[str, Any]            =get_aligned_output_features_output_indices(
                 out_features=lowercase_     ,  out_indices=lowercase_     ,  stage_names=self.stage_names					)


