codingutf8 2023 the huggingface inc team licensed under the apache license version 2 0 the license you may not use this file except in compliance with the license you may obtain a copy of the license at http www apache orglicenseslicense2 0 unless required by applicable law or agreed to in writing software distributed under the license is distributed on an as is basis without warranties or conditions of any kind either express or implied see the license for the specific language governing permissions and limitations under the license clap model configuration import os from typing import union from configurationutils import pretrainedconfig from utils import logging logger logging getloggername clappretrainedmodelarchivelist laionclaphtsatfused https huggingface colaionclaphtsatfusedresolvemainconfig json laionclaphtsatunfused https huggingface colaionclaphtsatunfusedresolvemainconfig json class claptextconfigpretrainedconfig r this is the configuration class to store the configuration of a claptextmodel it is used to instantiate a clap model according to the specified arguments defining the model architecture instantiating a configuration with the defaults will yield a similar configuration to that of the clap calphsatfusedhttps huggingface colaionclaphsatfused architecture configuration objects inherit from pretrainedconfig and can be used to control the model outputs read the documentation from pretrainedconfig for more information args vocabsize int optional defaults to 30522 vocabulary size of the clap model defines the number of different tokens that can be represented by the inputsids passed when calling claptextmodel hiddensize int optional defaults to 768 dimensionality of the encoder layers and the pooler layer numhiddenlayers int optional defaults to 12 number of hidden layers in the transformer encoder numattentionheads int optional defaults to 12 number of attention heads for each attention layer in the transformer encoder intermediatesize int optional defaults to 3072 dimensionality of the intermediate often named feedforward layer in the transformer encoder hiddenact str or callable optional defaults to relu the nonlinear activation function function or string in the encoder and pooler if string relu relu silu and relunew are supported hiddendropoutprob float optional defaults to 0 1 the dropout probability for all fully connected layers in the embeddings encoder and pooler attentionprobsdropoutprob float optional defaults to 0 1 the dropout ratio for the attention probabilities maxpositionembeddings int optional defaults to 512 the maximum sequence length that this model might ever be used with typically set this to something large just in case e g 512 or 1024 or 2048 typevocabsize int optional defaults to 2 the vocabulary size of the tokentypeids passed when calling claptextmodel layernormeps float optional defaults to 1e12 the epsilon used by the layer normalization layers positionembeddingtype str optional defaults to absolute type of position embedding choose one of absolute relativekey relativekeyquery for positional embeddings use absolute for more information on relativekey please refer to selfattention with relative position representations shaw et al https arxiv orgabs1803 02155 for more information on relativekeyquery please refer to method 4 in improve transformer models with better relative position embeddings huang et al https arxiv orgabs2009 13658 isdecoder bool optional defaults to false whether the model is used as a decoder or not if false the model is used as an encoder usecache bool optional defaults to true whether or not the model should return the last keyvalues attentions not used by all models only relevant if config isdecodertrue projectionhiddenact str optional defaults to relu the nonlinear activation function function or string in the projection layer if string gelu relu silu and gelunew are supported projectiondim int optional defaults to 512 dimension of the projection head of the claptextmodelwithprojection examples python from transformers import claptextconfig claptextmodel initializing a clap text configuration configuration claptextconfig initializing a model with random weights from the configuration model claptextmodelconfiguration accessing the model configuration configuration model config modeltype claptextmodel def init self vocabsize50265 hiddensize768 numhiddenlayers12 numattentionheads12 intermediatesize3072 hiddenactgelu hiddendropoutprob0 1 attentionprobsdropoutprob0 1 maxpositionembeddings514 typevocabsize1 initializerfactor1 0 layernormeps1e12 projectiondim512 padtokenid1 bostokenid0 eostokenid2 positionembeddingtypeabsolute usecachetrue projectionhiddenactrelu kwargs super initpadtokenidpadtokenid bostokenidbostokenid eostokenideostokenid kwargs self vocabsize vocabsize self hiddensize hiddensize self numhiddenlayers numhiddenlayers self numattentionheads numattentionheads self hiddenact hiddenact self intermediatesize intermediatesize self hiddendropoutprob hiddendropoutprob self attentionprobsdropoutprob attentionprobsdropoutprob self maxpositionembeddings maxpositionembeddings self typevocabsize typevocabsize self initializerfactor initializerfactor self layernormeps layernormeps self positionembeddingtype positionembeddingtype self usecache usecache self projectionhiddenact projectionhiddenact self projectiondim projectiondim classmethod def frompretrainedcls pretrainedmodelnameorpath unionstr os pathlike kwargs pretrainedconfig cls settokeninkwargskwargs configdict kwargs cls getconfigdictpretrainedmodelnameorpath kwargs get the text config dict if we are loading from clapconfig if configdict getmodeltype clap configdict configdicttextconfig if modeltype in configdict and hasattrcls modeltype and configdictmodeltype cls modeltype logger warning fyou are using a model of type configdict modeltype to instantiate a model of type fcls modeltype this is not supported for all configurations of models and can yield errors return cls fromdictconfigdict kwargs class clapaudioconfigpretrainedconfig r this is the configuration class to store the configuration of a clapaudiomodel it is used to instantiate a clap audio encoder according to the specified arguments defining the model architecture instantiating a configuration with the defaults will yield a similar configuration to that of the audio encoder of the clap laionclaphtsatfusedhttps huggingface colaionclaphtsatfused architecture configuration objects inherit from pretrainedconfig and can be used to control the model outputs read the documentation from pretrainedconfig for more information args windowsize int optional defaults to 8 image size of the spectrogram nummelbins int optional defaults to 64 number of mel features used per frames should correspond to the value used in the clapprocessor class specsize int optional defaults to 256 desired input size of the spectrogram that the model supports it can be different from the output of the clapfeatureextractor in which case the input features will be resized corresponds to the imagesize of the audio models hiddenact str optional defaults to gelu the nonlinear activation function function or string in the encoder and pooler if string gelu relu silu and gelunew are supported patchsize int optional defaults to 4 patch size for the audio spectrogram patchstride list optional defaults to 4 4 patch stride for the audio spectrogram numclasses int optional defaults to 527 number of classes used for the head training hiddensize int optional defaults to 768 hidden size of the output of the audio encoder correspond to the dimension of the penultimate layer s output which is sent to the projection mlp layer projectiondim int optional defaults to 512 hidden size of the projection layer depths list optional defaults to 2 2 6 2 depths used for the swin layers of the audio model numattentionheads list optional defaults to 4 8 16 32 number of attention heads used for the swin layers of the audio model enablefusion bool optional defaults to false whether or not to enable patch fusion this is the main contribution of the s and should give the best results hiddendropoutprob float optional defaults to 0 1 the dropout probabilitiy for all fully connected layers in the encoder fusiontype type optional fusion type used for the patch fusion patchembedinputchannels int optional defaults to 1 number of channels used for the input spectrogram flattenpatchembeds bool optional defaults to true whether or not to flatten the patch embeddings patchembedshiddensize int optional defaults to 96 hidden size of the patch embeddings it is used as the number of output channels enablepatchlayernorm bool optional defaults to true whether or not to enable layer normalization for the patch embeddings droppathrate float optional defaults to 0 0 drop path rate for the patch fusion attentionprobsdropoutprob float optional defaults to 0 0 the dropout ratio for the attention probabilities qkvbias bool optional defaults to true whether or not to add a bias to the query key value projections mlpratio float optional defaults to 4 0 ratio of the mlp hidden dim to embedding dim affblockr int optional defaults to 4 downsizeratio used in the audioff block numhiddenlayers int optional defaults to 4 number of hidden layers in the transformer encoder projectionhiddenact str optional defaults to relu the nonlinear activation function function or string in the projection layer if string gelu relu silu and gelunew are supported layernormeps type optional defaults to 1e05 the epsilon used by the layer normalization layers initializerfactor float optional defaults to 1 0 a factor for initializing all weight matrices should be kept to 1 used internally for initialization testing example python from transformers import clapaudioconfig clapaudiomodel initializing a clapaudioconfig with laionclaphtsatfused style configuration configuration clapaudioconfig initializing a clapaudiomodel with random weights from the laionclaphtsatfused style configuration model clapaudiomodelconfiguration accessing the model configuration configuration model config modeltype clapaudiomodel def init self windowsize8 nummelbins64 specsize256 hiddenactgelu patchsize4 patchstride4 4 numclasses527 hiddensize768 projectiondim512 depths2 2 6 2 numattentionheads4 8 16 32 enablefusionfalse hiddendropoutprob0 1 fusiontypenone patchembedinputchannels1 flattenpatchembedstrue patchembedshiddensize96 enablepatchlayernormtrue droppathrate0 0 attentionprobsdropoutprob0 0 qkvbiastrue mlpratio4 0 affblockr4 numhiddenlayers4 projectionhiddenactrelu layernormeps1e5 initializerfactor1 0 kwargs super initkwargs self windowsize windowsize self nummelbins nummelbins self specsize specsize self patchsize patchsize self patchstride patchstride self numclasses numclasses self hiddensize hiddensize self depths depths self numhiddenlayers numhiddenlayers self numattentionheads numattentionheads self windowsize windowsize self enablefusion enablefusion self fusiontype fusiontype self hiddenact hiddenact self hiddendropoutprob hiddendropoutprob self projectiondim projectiondim self flattenpatchembeds flattenpatchembeds self patchembedshiddensize patchembedshiddensize self enablepatchlayernorm enablepatchlayernorm self droppathrate droppathrate self attentionprobsdropoutprob attentionprobsdropoutprob self qkvbias qkvbias self mlpratio mlpratio self patchembedinputchannels patchembedinputchannels self affblockr affblockr self layernormeps layernormeps self initializerfactor initializerfactor self projectionhiddenact projectionhiddenact classmethod def frompretrainedcls pretrainedmodelnameorpath unionstr os pathlike kwargs pretrainedconfig cls settokeninkwargskwargs configdict kwargs cls getconfigdictpretrainedmodelnameorpath kwargs get the audio config dict if we are loading from clapconfig if configdict getmodeltype clap configdict configdictaudioconfig if modeltype in configdict and hasattrcls modeltype and configdictmodeltype cls modeltype logger warning fyou are using a model of type configdict modeltype to instantiate a model of type fcls modeltype this is not supported for all configurations of models and can yield errors return cls fromdictconfigdict kwargs class clapconfigpretrainedconfig r clapconfig is the configuration class to store the configuration of a clapmodel it is used to instantiate a clap model according to the specified arguments defining the text model and audio model configs instantiating a configuration with the defaults will yield a similar configuration to that of the clap laionclaphtsatfusedhttps huggingface colaionclaphtsatfused architecture configuration objects inherit from pretrainedconfig and can be used to control the model outputs read the documentation from pretrainedconfig for more information args textconfig dict optional dictionary of configuration options used to initialize claptextconfig audioconfig dict optional dictionary of configuration options used to initialize clapaudioconfig logitscaleinitvalue float optional defaults to 14 29 the inital value of the logitscale paramter default is used as per the original clap implementation projectiondim int optional defaults to 512 dimentionality of text and audio projection layers projectionhiddenact str optional defaults to relu activation function for the projection layers initializerfactor float optional defaults to 1 0 factor to scale the initialization of the model weights kwargs optional dictionary of keyword arguments example python from transformers import clapconfig clapmodel initializing a clapconfig with laionaibase style configuration configuration clapconfig initializing a clapmodel with random weights from the laionaibase style configuration model clapmodelconfiguration accessing the model configuration configuration model config we can also initialize a clapconfig from a claptextconfig and a clapaudioconfig from transformers import claptextconfig clapaudioconfig initializing a claptext and clapaudioconfig configuration configtext claptextconfig configaudio clapaudioconfig config clapconfig fromtextaudioconfigsconfigtext configaudio modeltype clap def init self textconfignone audioconfignone logitscaleinitvalue1 0 07 projectiondim512 projectionhiddenactrelu initializerfactor1 0 kwargs super initkwargs if textconfig is none textconfig logger infotextconfig is none initializing the claptextconfig with default values if audioconfig is none audioconfig logger infoaudioconfig is none initializing the clapaudioconfig with default values self textconfig claptextconfigtextconfig self audioconfig clapaudioconfigaudioconfig self textconfig projectiondim projectiondim self audioconfig projectiondim projectiondim self textconfig projectionhiddenact projectionhiddenact self audioconfig projectionhiddenact projectionhiddenact self projectiondim projectiondim self projectionhiddenact projectionhiddenact self hiddensize self textconfig hiddensize self logitscaleinitvalue logitscaleinitvalue self initializerfactor initializerfactor self numhiddenlayers self textconfig numhiddenlayers lenself audioconfig depths classmethod def fromtextaudioconfigscls textconfig claptextconfig audioconfig clapaudioconfig kwargs r instantiate a clapconfig or a derived class from clap text model configuration and clap audio model configuration returns clapconfig an instance of a configuration object coding utf 8 2023 the huggingface inc team licensed under the apache license version 2 0 the license you may not use this file except in compliance with the license you may obtain a copy of the license at http www apache org licenses license 2 0 unless required by applicable law or agreed to in writing software distributed under the license is distributed on an as is basis without warranties or conditions of any kind either express or implied see the license for the specific language governing permissions and limitations under the license clap model configuration this is the configuration class to store the configuration of a claptextmodel it is used to instantiate a clap model according to the specified arguments defining the model architecture instantiating a configuration with the defaults will yield a similar configuration to that of the clap calp hsat fused https huggingface co laion clap hsat fused architecture configuration objects inherit from pretrainedconfig and can be used to control the model outputs read the documentation from pretrainedconfig for more information args vocab_size int optional defaults to 30522 vocabulary size of the clap model defines the number of different tokens that can be represented by the inputs_ids passed when calling claptextmodel hidden_size int optional defaults to 768 dimensionality of the encoder layers and the pooler layer num_hidden_layers int optional defaults to 12 number of hidden layers in the transformer encoder num_attention_heads int optional defaults to 12 number of attention heads for each attention layer in the transformer encoder intermediate_size int optional defaults to 3072 dimensionality of the intermediate often named feed forward layer in the transformer encoder hidden_act str or callable optional defaults to relu the non linear activation function function or string in the encoder and pooler if string relu relu silu and relu_new are supported hidden_dropout_prob float optional defaults to 0 1 the dropout probability for all fully connected layers in the embeddings encoder and pooler attention_probs_dropout_prob float optional defaults to 0 1 the dropout ratio for the attention probabilities max_position_embeddings int optional defaults to 512 the maximum sequence length that this model might ever be used with typically set this to something large just in case e g 512 or 1024 or 2048 type_vocab_size int optional defaults to 2 the vocabulary size of the token_type_ids passed when calling claptextmodel layer_norm_eps float optional defaults to 1e 12 the epsilon used by the layer normalization layers position_embedding_type str optional defaults to absolute type of position embedding choose one of absolute relative_key relative_key_query for positional embeddings use absolute for more information on relative_key please refer to self attention with relative position representations shaw et al https arxiv org abs 1803 02155 for more information on relative_key_query please refer to method 4 in improve transformer models with better relative position embeddings huang et al https arxiv org abs 2009 13658 is_decoder bool optional defaults to false whether the model is used as a decoder or not if false the model is used as an encoder use_cache bool optional defaults to true whether or not the model should return the last key values attentions not used by all models only relevant if config is_decoder true projection_hidden_act str optional defaults to relu the non linear activation function function or string in the projection layer if string gelu relu silu and gelu_new are supported projection_dim int optional defaults to 512 dimension of the projection head of the claptextmodelwithprojection examples python from transformers import claptextconfig claptextmodel initializing a clap text configuration configuration claptextconfig initializing a model with random weights from the configuration model claptextmodel configuration accessing the model configuration configuration model config get the text config dict if we are loading from clapconfig this is the configuration class to store the configuration of a clapaudiomodel it is used to instantiate a clap audio encoder according to the specified arguments defining the model architecture instantiating a configuration with the defaults will yield a similar configuration to that of the audio encoder of the clap laion clap htsat fused https huggingface co laion clap htsat fused architecture configuration objects inherit from pretrainedconfig and can be used to control the model outputs read the documentation from pretrainedconfig for more information args window_size int optional defaults to 8 image size of the spectrogram num_mel_bins int optional defaults to 64 number of mel features used per frames should correspond to the value used in the clapprocessor class spec_size int optional defaults to 256 desired input size of the spectrogram that the model supports it can be different from the output of the clapfeatureextractor in which case the input features will be resized corresponds to the image_size of the audio models hidden_act str optional defaults to gelu the non linear activation function function or string in the encoder and pooler if string gelu relu silu and gelu_new are supported patch_size int optional defaults to 4 patch size for the audio spectrogram patch_stride list optional defaults to 4 4 patch stride for the audio spectrogram num_classes int optional defaults to 527 number of classes used for the head training hidden_size int optional defaults to 768 hidden size of the output of the audio encoder correspond to the dimension of the penultimate layer s output which is sent to the projection mlp layer projection_dim int optional defaults to 512 hidden size of the projection layer depths list optional defaults to 2 2 6 2 depths used for the swin layers of the audio model num_attention_heads list optional defaults to 4 8 16 32 number of attention heads used for the swin layers of the audio model enable_fusion bool optional defaults to false whether or not to enable patch fusion this is the main contribution of the s and should give the best results hidden_dropout_prob float optional defaults to 0 1 the dropout probabilitiy for all fully connected layers in the encoder fusion_type type optional fusion type used for the patch fusion patch_embed_input_channels int optional defaults to 1 number of channels used for the input spectrogram flatten_patch_embeds bool optional defaults to true whether or not to flatten the patch embeddings patch_embeds_hidden_size int optional defaults to 96 hidden size of the patch embeddings it is used as the number of output channels enable_patch_layer_norm bool optional defaults to true whether or not to enable layer normalization for the patch embeddings drop_path_rate float optional defaults to 0 0 drop path rate for the patch fusion attention_probs_dropout_prob float optional defaults to 0 0 the dropout ratio for the attention probabilities qkv_bias bool optional defaults to true whether or not to add a bias to the query key value projections mlp_ratio float optional defaults to 4 0 ratio of the mlp hidden dim to embedding dim aff_block_r int optional defaults to 4 downsize_ratio used in the audioff block num_hidden_layers int optional defaults to 4 number of hidden layers in the transformer encoder projection_hidden_act str optional defaults to relu the non linear activation function function or string in the projection layer if string gelu relu silu and gelu_new are supported layer_norm_eps type optional defaults to 1e 05 the epsilon used by the layer normalization layers initializer_factor float optional defaults to 1 0 a factor for initializing all weight matrices should be kept to 1 used internally for initialization testing example python from transformers import clapaudioconfig clapaudiomodel initializing a clapaudioconfig with laion clap htsat fused style configuration configuration clapaudioconfig initializing a clapaudiomodel with random weights from the laion clap htsat fused style configuration model clapaudiomodel configuration accessing the model configuration configuration model config get the audio config dict if we are loading from clapconfig clapconfig is the configuration class to store the configuration of a clapmodel it is used to instantiate a clap model according to the specified arguments defining the text model and audio model configs instantiating a configuration with the defaults will yield a similar configuration to that of the clap laion clap htsat fused https huggingface co laion clap htsat fused architecture configuration objects inherit from pretrainedconfig and can be used to control the model outputs read the documentation from pretrainedconfig for more information args text_config dict optional dictionary of configuration options used to initialize claptextconfig audio_config dict optional dictionary of configuration options used to initialize clapaudioconfig logit_scale_init_value float optional defaults to 14 29 the inital value of the logit_scale paramter default is used as per the original clap implementation projection_dim int optional defaults to 512 dimentionality of text and audio projection layers projection_hidden_act str optional defaults to relu activation function for the projection layers initializer_factor float optional defaults to 1 0 factor to scale the initialization of the model weights kwargs optional dictionary of keyword arguments example python from transformers import clapconfig clapmodel initializing a clapconfig with laion ai base style configuration configuration clapconfig initializing a clapmodel with random weights from the laion ai base style configuration model clapmodel configuration accessing the model configuration configuration model config we can also initialize a clapconfig from a claptextconfig and a clapaudioconfig from transformers import claptextconfig clapaudioconfig initializing a claptext and clapaudioconfig configuration config_text claptextconfig config_audio clapaudioconfig config clapconfig from_text_audio_configs config_text config_audio instantiate a clapconfig or a derived class from clap text model configuration and clap audio model configuration returns clapconfig an instance of a configuration object
import os
from typing import Union

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


logger = logging.get_logger(__name__)

CLAP_PRETRAINED_MODEL_ARCHIVE_LIST = {
    "laion/clap-htsat-fused": "https://huggingface.co/laion/clap-htsat-fused/resolve/main/config.json",
    "laion/clap-htsat-unfused": "https://huggingface.co/laion/clap-htsat-unfused/resolve/main/config.json",
}


class ClapTextConfig(PretrainedConfig):
    r

    model_type = "clap_text_model"

    def __init__(
        self,
        vocab_size=50265,
        hidden_size=768,
        num_hidden_layers=12,
        num_attention_heads=12,
        intermediate_size=3072,
        hidden_act="gelu",
        hidden_dropout_prob=0.1,
        attention_probs_dropout_prob=0.1,
        max_position_embeddings=514,
        type_vocab_size=1,
        initializer_factor=1.0,
        layer_norm_eps=1e-12,
        projection_dim=512,
        pad_token_id=1,
        bos_token_id=0,
        eos_token_id=2,
        position_embedding_type="absolute",
        use_cache=True,
        projection_hidden_act="relu",
        **kwargs,
    ):
        super().__init__(pad_token_id=pad_token_id, bos_token_id=bos_token_id, eos_token_id=eos_token_id, **kwargs)

        self.vocab_size = vocab_size
        self.hidden_size = hidden_size
        self.num_hidden_layers = num_hidden_layers
        self.num_attention_heads = num_attention_heads
        self.hidden_act = hidden_act
        self.intermediate_size = intermediate_size
        self.hidden_dropout_prob = hidden_dropout_prob
        self.attention_probs_dropout_prob = attention_probs_dropout_prob
        self.max_position_embeddings = max_position_embeddings
        self.type_vocab_size = type_vocab_size
        self.initializer_factor = initializer_factor
        self.layer_norm_eps = layer_norm_eps
        self.position_embedding_type = position_embedding_type
        self.use_cache = use_cache
        self.projection_hidden_act = projection_hidden_act
        self.projection_dim = projection_dim

    @classmethod
    def from_pretrained(cls, pretrained_model_name_or_path: Union[str, os.PathLike], **kwargs) -> "PretrainedConfig":
        cls._set_token_in_kwargs(kwargs)

        config_dict, kwargs = cls.get_config_dict(pretrained_model_name_or_path, **kwargs)

        
        if config_dict.get("model_type") == "clap":
            config_dict = config_dict["text_config"]

        if "model_type" in config_dict and hasattr(cls, "model_type") and config_dict["model_type"] != cls.model_type:
            logger.warning(
                f"You are using a model of type {config_dict['model_type']} to instantiate a model of type "
                f"{cls.model_type}. This is not supported for all configurations of models and can yield errors."
            )

        return cls.from_dict(config_dict, **kwargs)


class ClapAudioConfig(PretrainedConfig):
    r

    model_type = "clap_audio_model"

    def __init__(
        self,
        window_size=8,
        num_mel_bins=64,
        spec_size=256,
        hidden_act="gelu",
        patch_size=4,
        patch_stride=[4, 4],
        num_classes=527,
        hidden_size=768,
        projection_dim=512,
        depths=[2, 2, 6, 2],
        num_attention_heads=[4, 8, 16, 32],
        enable_fusion=False,
        hidden_dropout_prob=0.1,
        fusion_type=None,
        patch_embed_input_channels=1,
        flatten_patch_embeds=True,
        patch_embeds_hidden_size=96,
        enable_patch_layer_norm=True,
        drop_path_rate=0.0,
        attention_probs_dropout_prob=0.0,
        qkv_bias=True,
        mlp_ratio=4.0,
        aff_block_r=4,
        num_hidden_layers=4,
        projection_hidden_act="relu",
        layer_norm_eps=1e-5,
        initializer_factor=1.0,
        **kwargs,
    ):
        super().__init__(**kwargs)
        self.window_size = window_size
        self.num_mel_bins = num_mel_bins
        self.spec_size = spec_size
        self.patch_size = patch_size
        self.patch_stride = patch_stride
        self.num_classes = num_classes
        self.hidden_size = hidden_size
        self.depths = depths
        self.num_hidden_layers = num_hidden_layers
        self.num_attention_heads = num_attention_heads
        self.window_size = window_size
        self.enable_fusion = enable_fusion
        self.fusion_type = fusion_type
        self.hidden_act = hidden_act
        self.hidden_dropout_prob = hidden_dropout_prob
        self.projection_dim = projection_dim
        self.flatten_patch_embeds = flatten_patch_embeds
        self.patch_embeds_hidden_size = patch_embeds_hidden_size
        self.enable_patch_layer_norm = enable_patch_layer_norm
        self.drop_path_rate = drop_path_rate
        self.attention_probs_dropout_prob = attention_probs_dropout_prob
        self.qkv_bias = qkv_bias
        self.mlp_ratio = mlp_ratio
        self.patch_embed_input_channels = patch_embed_input_channels
        self.aff_block_r = aff_block_r
        self.layer_norm_eps = layer_norm_eps
        self.initializer_factor = initializer_factor
        self.projection_hidden_act = projection_hidden_act

    @classmethod
    def from_pretrained(cls, pretrained_model_name_or_path: Union[str, os.PathLike], **kwargs) -> "PretrainedConfig":
        cls._set_token_in_kwargs(kwargs)

        config_dict, kwargs = cls.get_config_dict(pretrained_model_name_or_path, **kwargs)

        
        if config_dict.get("model_type") == "clap":
            config_dict = config_dict["audio_config"]

        if "model_type" in config_dict and hasattr(cls, "model_type") and config_dict["model_type"] != cls.model_type:
            logger.warning(
                f"You are using a model of type {config_dict['model_type']} to instantiate a model of type "
                f"{cls.model_type}. This is not supported for all configurations of models and can yield errors."
            )

        return cls.from_dict(config_dict, **kwargs)


class ClapConfig(PretrainedConfig):
    r

    model_type = "clap"

    def __init__(
        self,
        text_config=None,
        audio_config=None,
        logit_scale_init_value=(1 / 0.07),
        projection_dim=512,
        projection_hidden_act="relu",
        initializer_factor=1.0,
        **kwargs,
    ):
        super().__init__(**kwargs)

        if text_config is None:
            text_config = {}
            logger.info("text_config is None. Initializing the ClapTextConfig with default values.")

        if audio_config is None:
            audio_config = {}
            logger.info("audio_config is None. initializing the ClapAudioConfig with default values.")

        self.text_config = ClapTextConfig(**text_config)
        self.audio_config = ClapAudioConfig(**audio_config)
        self.text_config.projection_dim = projection_dim
        self.audio_config.projection_dim = projection_dim

        self.text_config.projection_hidden_act = projection_hidden_act
        self.audio_config.projection_hidden_act = projection_hidden_act

        self.projection_dim = projection_dim
        self.projection_hidden_act = projection_hidden_act
        self.hidden_size = self.text_config.hidden_size

        self.logit_scale_init_value = logit_scale_init_value
        self.initializer_factor = initializer_factor
        self.num_hidden_layers = self.text_config.num_hidden_layers + len(self.audio_config.depths)

    @classmethod
    def from_text_audio_configs(cls, text_config: ClapTextConfig, audio_config: ClapAudioConfig, **kwargs):
        r

        return cls(text_config=text_config.to_dict(), audio_config=audio_config.to_dict(), **kwargs)