


# Copyright 2023 The HuggingFace Inc. team. All rights reserved.
#
# 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.
import copy
import importlib.metadata
import json
import os
from dataclasses import dataclass
from typing import Any, Dict, Union

from packaging import version

from ..utils import is_torch_available, logging


if is_torch_available():
 import torch


__lowerCAmelCase		       =							logging.get_logger(__name__)





@dataclass
class   __a			:
 def __init__(   self				, lowerCAmelCase__=False				, lowerCAmelCase__=False				, lowerCAmelCase__=6.0				, lowerCAmelCase__=None				, lowerCAmelCase__=False				, lowerCAmelCase__=False				, lowerCAmelCase__=None				, lowerCAmelCase__="fp4"				, lowerCAmelCase__=False				, **lowerCAmelCase__				, )					->				Dict:




        '''simple docstring'''
        lowercase__:   Union[str, Any]  			=   load_in_abit
        lowercase__:   Dict  			=   load_in_abit
        lowercase__:   Optional[int]  			=   llm_inta_threshold
        lowercase__:   Dict  			=   llm_inta_skip_modules
        lowercase__:   Tuple  			=   llm_inta_enable_fpaa_cpu_offload
        lowercase__:   List[str]  			=   llm_inta_has_fpaa_weight
        lowercase__:   List[Any]  			=   bnb_abit_quant_type
        lowercase__:   Optional[Any]  			=   bnb_abit_use_double_quant

        if bnb_abit_compute_dtype is None:
               lowercase__:   str  			=   torch.floataa
        elif isinstance(lowerCAmelCase__				, lowerCAmelCase__ ):
               lowercase__:   Tuple  			=   getattr(lowerCAmelCase__				, lowerCAmelCase__ )
        elif isinstance(lowerCAmelCase__				, torch.dtype ):
               lowercase__:   List[str]  			=   bnb_abit_compute_dtype
        else:
               raise ValueError('bnb_4bit_compute_dtype must be a string or a torch.dtype' )

        self.post_init()
 def 		SCREAMING_SNAKE_CASE__   (   self )					->				Any:




        '''simple docstring'''
        if not isinstance(self.llm_inta_threshold				, lowerCAmelCase__ ):
               raise ValueError('llm_int8_threshold must be a float' )

        if self.llm_inta_skip_modules is not None and not isinstance(self.llm_inta_skip_modules				, lowerCAmelCase__ ):
               raise ValueError('llm_int8_skip_modules must be a list of strings' )
        if not isinstance(self.llm_inta_enable_fpaa_cpu_offload				, lowerCAmelCase__ ):
               raise ValueError('llm_int8_enable_fp32_cpu_offload must be a boolean' )

        if not isinstance(self.llm_inta_has_fpaa_weight				, lowerCAmelCase__ ):
               raise ValueError('llm_int8_has_fp16_weight must be a boolean' )

        if self.bnb_abit_compute_dtype is not None and not isinstance(self.bnb_abit_compute_dtype				, torch.dtype ):
               raise ValueError('bnb_4bit_compute_dtype must be torch.dtype' )

        if not isinstance(self.bnb_abit_quant_type				, lowerCAmelCase__ ):
               raise ValueError('bnb_4bit_quant_type must be a string' )

        if not isinstance(self.bnb_abit_use_double_quant				, lowerCAmelCase__ ):
               raise ValueError('bnb_4bit_use_double_quant must be a boolean' )

        if self.load_in_abit and not version.parse(importlib.metadata.version('bitsandbytes' ) ) >= version.parse(
            '0.39.0' ):
               raise ValueError(
                   '4 bit quantization requires bitsandbytes>=0.39.0 - please upgrade your bitsandbytes version' )
 def 		SCREAMING_SNAKE_CASE__   (   self )					->				List[str]:




        '''simple docstring'''
        return self.load_in_abit or self.load_in_abit
 def 		SCREAMING_SNAKE_CASE__   (   self )					->				List[str]:




        '''simple docstring'''
        if self.load_in_abit:
               return "llm_int8"
        elif self.load_in_abit and self.bnb_abit_quant_type == "fp4":
               return "fp4"
        elif self.load_in_abit and self.bnb_abit_quant_type == "nf4":
               return "nf4"
        else:
               return None
 @classmethod
 def 		SCREAMING_SNAKE_CASE__   (   cls				, lowerCAmelCase__				, lowerCAmelCase__				, **lowerCAmelCase__ )					->				Union[str, Any]:




        '''simple docstring'''
        lowercase__:   Union[str, Any]  			=   cls(**lowerCAmelCase__ )

        lowercase__:   str  			=   []
        for key, value in kwargs.items():
               if hasattr(lowerCAmelCase__				, lowerCAmelCase__ ):
                      setattr(lowerCAmelCase__				, lowerCAmelCase__				, lowerCAmelCase__ )
                      to_remove.append(lowerCAmelCase__ )
        for key in to_remove:
               kwargs.pop(lowerCAmelCase__				, lowerCAmelCase__ )

        if return_unused_kwargs:
               return config, kwargs
        else:
               return config
 def 		SCREAMING_SNAKE_CASE__   (   self				, lowerCAmelCase__ )					->				Union[str, Any]:




        '''simple docstring'''
        with open(lowerCAmelCase__				, 'w'				, encoding='utf-8' ) as writer:
               lowercase__:   Dict  			=   self.to_dict()
               lowercase__:   Dict  			=   json.dumps(lowerCAmelCase__				, indent=2				, sort_keys=lowerCAmelCase__ ) + '\n'

               writer.write(lowerCAmelCase__ )
 def 		SCREAMING_SNAKE_CASE__   (   self )					->				Dict[str, Any]:




        '''simple docstring'''
        lowercase__:   List[Any]  			=   copy.deepcopy(self.__dict__ )
        lowercase__:   str  			=   str(output['bnb_4bit_compute_dtype'] ).split('.' )[1]

        return output
 def __repr__(   self )					->				List[Any]:




        '''simple docstring'''
        return F'{self.__class__.__name__} {self.to_json_string()}'
 def 		SCREAMING_SNAKE_CASE__   (   self				, lowerCAmelCase__ = True )					->				str:




        '''simple docstring'''
        if use_diff is True:
               lowercase__:   Any  			=   self.to_diff_dict()
        else:
               lowercase__:   str  			=   self.to_dict()
        return json.dumps(lowerCAmelCase__				, indent=2				, sort_keys=lowerCAmelCase__ ) + "\n"
 def 		SCREAMING_SNAKE_CASE__   (   self )					->				Dict[str, Any]:




        '''simple docstring'''
        lowercase__:   Optional[Any]  			=   self.to_dict()

        # get the default config dict
        lowercase__:   Dict  			=   BitsAndBytesConfig().to_dict()

        lowercase__:   Union[str, Any]  			=   {}

        # only serialize values that differ from the default config
        for key, value in config_dict.items():
               if value != default_config_dict[key]:
                      lowercase__:   Optional[Any]  			=   value

        return serializable_config_dict






import math

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


__lowerCAmelCase		       =							logging.get_logger(__name__)

__lowerCAmelCase		       =							{
    '''facebook/data2vec-base-960h''': '''https://huggingface.co/facebook/data2vec-audio-base-960h/resolve/main/config.json''',
    # See all Data2VecAudio models at https://huggingface.co/models?filter=data2vec-audio
}





class   __a			(    __UpperCamelCase      ):
 __lowercase :							Optional[int]        = 'data2vec-audio'
 def __init__(   self				, lowerCAmelCase__=32				, lowerCAmelCase__=768				, lowerCAmelCase__=12				, lowerCAmelCase__=12				, lowerCAmelCase__=3_072				, lowerCAmelCase__="gelu"				, lowerCAmelCase__=0.1				, lowerCAmelCase__=0.1				, lowerCAmelCase__=0.1				, lowerCAmelCase__=0.0				, lowerCAmelCase__=0.1				, lowerCAmelCase__=0.1				, lowerCAmelCase__=0.0_2				, lowerCAmelCase__=1E-5				, lowerCAmelCase__="gelu"				, lowerCAmelCase__=(512, 512, 512, 512, 512, 512, 512)				, lowerCAmelCase__=(5, 2, 2, 2, 2, 2, 2)				, lowerCAmelCase__=(10, 3, 3, 3, 3, 2, 2)				, lowerCAmelCase__=False				, lowerCAmelCase__=16				, lowerCAmelCase__=19				, lowerCAmelCase__=5				, lowerCAmelCase__=0.0_5				, lowerCAmelCase__=10				, lowerCAmelCase__=2				, lowerCAmelCase__=0.0				, lowerCAmelCase__=10				, lowerCAmelCase__=0				, lowerCAmelCase__="sum"				, lowerCAmelCase__=False				, lowerCAmelCase__=False				, lowerCAmelCase__=256				, lowerCAmelCase__=(512, 512, 512, 512, 1_500)				, lowerCAmelCase__=(5, 3, 3, 1, 1)				, lowerCAmelCase__=(1, 2, 3, 1, 1)				, lowerCAmelCase__=512				, lowerCAmelCase__=0				, lowerCAmelCase__=1				, lowerCAmelCase__=2				, lowerCAmelCase__=False				, lowerCAmelCase__=3				, lowerCAmelCase__=2				, lowerCAmelCase__=3				, lowerCAmelCase__=None				, **lowerCAmelCase__				, )					->				Optional[int]:




        '''simple docstring'''
        super().__init__(**lowerCAmelCase__				, pad_token_id=lowerCAmelCase__				, bos_token_id=lowerCAmelCase__				, eos_token_id=lowerCAmelCase__ )
        lowercase__:   int  			=   hidden_size
        lowercase__:   str  			=   feat_extract_activation
        lowercase__:   List[Any]  			=   list(lowerCAmelCase__ )
        lowercase__:   Optional[int]  			=   list(lowerCAmelCase__ )
        lowercase__:   int  			=   list(lowerCAmelCase__ )
        lowercase__:   Union[str, Any]  			=   conv_bias
        lowercase__:   int  			=   num_conv_pos_embeddings
        lowercase__:   List[str]  			=   num_conv_pos_embedding_groups
        lowercase__:   List[Any]  			=   conv_pos_kernel_size
        lowercase__:   Optional[Any]  			=   len(self.conv_dim )
        lowercase__:   List[str]  			=   num_hidden_layers
        lowercase__:   List[str]  			=   intermediate_size
        lowercase__:   Tuple  			=   hidden_act
        lowercase__:   Any  			=   num_attention_heads
        lowercase__:   Optional[int]  			=   hidden_dropout
        lowercase__:   List[str]  			=   attention_dropout
        lowercase__:   int  			=   activation_dropout
        lowercase__:   Dict  			=   feat_proj_dropout
        lowercase__:   str  			=   final_dropout
        lowercase__:   List[str]  			=   layerdrop
        lowercase__:   str  			=   layer_norm_eps
        lowercase__:   Union[str, Any]  			=   initializer_range
        lowercase__:   Union[str, Any]  			=   vocab_size
        lowercase__:   Any  			=   use_weighted_layer_sum

        if (
            (len(self.conv_stride ) != self.num_feat_extract_layers)
            or (len(self.conv_kernel ) != self.num_feat_extract_layers)
            or (len(self.conv_dim ) != self.num_feat_extract_layers)
        ):
               raise ValueError(
                   'Configuration for convolutional layers is incorrect. It is required that `len(config.conv_dim)` =='
                   ' `len(config.conv_stride)` == `len(config.conv_kernel)`, but is `len(config.conv_dim) ='
                   F' {len(self.conv_dim )}`, `len(config.conv_stride) = {len(self.conv_stride )}`,'
                   F' `len(config.conv_kernel) = {len(self.conv_kernel )}`.' )

        # fine-tuning config parameters for SpecAugment: https://arxiv.org/abs/1904.08779
        lowercase__:   List[str]  			=   mask_time_prob
        lowercase__:   Tuple  			=   mask_time_length
        lowercase__:   List[Any]  			=   mask_time_min_masks
        lowercase__:   Optional[int]  			=   mask_feature_prob
        lowercase__:   Union[str, Any]  			=   mask_feature_length
        lowercase__:   List[str]  			=   mask_feature_min_masks

        # ctc loss
        lowercase__:   Union[str, Any]  			=   ctc_loss_reduction
        lowercase__:   str  			=   ctc_zero_infinity

        # adapter
        lowercase__:   str  			=   add_adapter
        lowercase__:   List[Any]  			=   adapter_kernel_size
        lowercase__:   Tuple  			=   adapter_stride
        lowercase__:   Dict  			=   num_adapter_layers
        lowercase__:   Optional[Any]  			=   output_hidden_size or hidden_size

        # SequenceClassification-specific parameter. Feel free to ignore for other classes.
        lowercase__:   List[Any]  			=   classifier_proj_size

        # XVector-specific parameters. Feel free to ignore for other classes.
        lowercase__:   int  			=   list(lowerCAmelCase__ )
        lowercase__:   Dict  			=   list(lowerCAmelCase__ )
        lowercase__:   int  			=   list(lowerCAmelCase__ )
        lowercase__:   str  			=   xvector_output_dim
 @property
 def 		SCREAMING_SNAKE_CASE__   (   self )					->				Optional[int]:




        '''simple docstring'''
        return math.prod(self.conv_stride )


