


import functools
import operator

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


__lowerCamelCase        =     logging.get_logger(__name__)

__lowerCamelCase        =     {
    '''microsoft/wavlm-base''': '''https://huggingface.co/microsoft/wavlm-base/resolve/main/config.json''',
    # See all WavLM models at https://huggingface.co/models?filter=wavlm
}


class   a__	(						lowerCAmelCase_    ):
       lowerCamelCase__:     Union[str, Any]							    =     """wavlm"""

       def __init__(   self      :     Optional[int]      ,							lowerCamelCase_      :     int=3_2      ,							lowerCamelCase_      :     int=7_6_8      ,							lowerCamelCase_      :     Optional[int]=1_2      ,							lowerCamelCase_      :     List[str]=1_2      ,							lowerCamelCase_      :     Any=3_0_7_2      ,							lowerCamelCase_      :     List[Any]="gelu"      ,							lowerCamelCase_      :     Tuple=0.1      ,							lowerCamelCase_      :     Optional[Any]=0.1      ,							lowerCamelCase_      :     str=0.1      ,							lowerCamelCase_      :     Union[str, Any]=0.0      ,							lowerCamelCase_      :     Any=0.1      ,							lowerCamelCase_      :     Union[str, Any]=0.1      ,							lowerCamelCase_      :     str=0.0_2      ,							lowerCamelCase_      :     Dict=1E-5      ,							lowerCamelCase_      :     Tuple="group"      ,							lowerCamelCase_      :     Any="gelu"      ,							lowerCamelCase_      :     Any=(5_1_2, 5_1_2, 5_1_2, 5_1_2, 5_1_2, 5_1_2, 5_1_2)      ,							lowerCamelCase_      :     Any=(5, 2, 2, 2, 2, 2, 2)      ,							lowerCamelCase_      :     Tuple=(1_0, 3, 3, 3, 3, 2, 2)      ,							lowerCamelCase_      :     Tuple=False      ,							lowerCamelCase_      :     Optional[Any]=1_2_8      ,							lowerCamelCase_      :     str=1_6      ,							lowerCamelCase_      :     List[str]=3_2_0      ,							lowerCamelCase_      :     List[str]=8_0_0      ,							lowerCamelCase_      :     Any=False      ,							lowerCamelCase_      :     Optional[Any]=True      ,							lowerCamelCase_      :     int=0.0_5      ,							lowerCamelCase_      :     Optional[int]=1_0      ,							lowerCamelCase_      :     Any=2      ,							lowerCamelCase_      :     List[str]=0.0      ,							lowerCamelCase_      :     List[str]=1_0      ,							lowerCamelCase_      :     Union[str, Any]=3_2_0      ,							lowerCamelCase_      :     List[Any]=2      ,							lowerCamelCase_      :     Optional[int]=0.1      ,							lowerCamelCase_      :     Union[str, Any]=1_0_0      ,							lowerCamelCase_      :     Optional[Any]=2_5_6      ,							lowerCamelCase_      :     str=2_5_6      ,							lowerCamelCase_      :     Optional[int]=0.1      ,							lowerCamelCase_      :     Any="mean"      ,							lowerCamelCase_      :     str=False      ,							lowerCamelCase_      :     Tuple=False      ,							lowerCamelCase_      :     List[str]=2_5_6      ,							lowerCamelCase_      :     Any=(5_1_2, 5_1_2, 5_1_2, 5_1_2, 1_5_0_0)      ,							lowerCamelCase_      :     Optional[Any]=(5, 3, 3, 1, 1)      ,							lowerCamelCase_      :     List[Any]=(1, 2, 3, 1, 1)      ,							lowerCamelCase_      :     int=5_1_2      ,							lowerCamelCase_      :     Dict=8_0      ,							lowerCamelCase_      :     List[Any]=0      ,							lowerCamelCase_      :     str=1      ,							lowerCamelCase_      :     Any=2      ,							lowerCamelCase_      :     Dict=False      ,							lowerCamelCase_      :     Optional[Any]=3      ,							lowerCamelCase_      :     List[Any]=2      ,							lowerCamelCase_      :     List[str]=3      ,							lowerCamelCase_      :     Optional[int]=None      ,							**lowerCamelCase_      :     int      ,							):
            super().__init__(**lowerCamelCase_      ,							pad_token_id=lowerCamelCase_      ,							bos_token_id=lowerCamelCase_      ,							eos_token_id=lowerCamelCase_    )
            a_    :     Union[str, Any]										=    hidden_size
            a_    :     Optional[Any]										=    feat_extract_norm
            a_    :     str										=    feat_extract_activation
            a_    :     Union[str, Any]										=    list(lowerCamelCase_    )
            a_    :     int										=    list(lowerCamelCase_    )
            a_    :     Union[str, Any]										=    list(lowerCamelCase_    )
            a_    :     Dict										=    conv_bias
            a_    :     int										=    num_buckets
            a_    :     Optional[int]										=    max_bucket_distance
            a_    :     List[str]										=    num_conv_pos_embeddings
            a_    :     Optional[Any]										=    num_conv_pos_embedding_groups
            a_    :     int										=    len(self.conv_dim    )
            a_    :     Any										=    num_hidden_layers
            a_    :     Union[str, Any]										=    intermediate_size
            a_    :     Any										=    hidden_act
            a_    :     Dict										=    num_attention_heads
            a_    :     Optional[int]										=    hidden_dropout
            a_    :     Tuple										=    attention_dropout
            a_    :     Optional[Any]										=    activation_dropout
            a_    :     Dict										=    feat_proj_dropout
            a_    :     Tuple										=    final_dropout
            a_    :     Optional[Any]										=    layerdrop
            a_    :     List[str]										=    layer_norm_eps
            a_    :     Dict										=    initializer_range
            a_    :     Dict										=    num_ctc_classes
            a_    :     int										=    vocab_size
            a_    :     Optional[int]										=    do_stable_layer_norm
            a_    :     str										=    use_weighted_layer_sum
            a_    :     Dict										=    classifier_proj_size

            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
            a_    :     List[Any]										=    apply_spec_augment
            a_    :     Any										=    mask_time_prob
            a_    :     Tuple										=    mask_time_length
            a_    :     Tuple										=    mask_time_min_masks
            a_    :     int										=    mask_feature_prob
            a_    :     List[str]										=    mask_feature_length

            # parameters for pretraining with codevector quantized representations
            a_    :     Tuple										=    num_codevectors_per_group
            a_    :     Any										=    num_codevector_groups
            a_    :     Dict										=    contrastive_logits_temperature
            a_    :     Optional[int]										=    num_negatives
            a_    :     List[Any]										=    codevector_dim
            a_    :     Union[str, Any]										=    proj_codevector_dim
            a_    :     Dict										=    diversity_loss_weight

            # ctc loss
            a_    :     Optional[Any]										=    ctc_loss_reduction
            a_    :     Tuple										=    ctc_zero_infinity

            # adapter
            a_    :     Union[str, Any]										=    add_adapter
            a_    :     List[Any]										=    adapter_kernel_size
            a_    :     List[str]										=    adapter_stride
            a_    :     Union[str, Any]										=    num_adapter_layers
            a_    :     Tuple										=    output_hidden_size or hidden_size

            # SequenceClassification-specific parameter. Feel free to ignore for other classes.
            a_    :     str										=    classifier_proj_size

            # XVector-specific parameters. Feel free to ignore for other classes.
            a_    :     List[str]										=    list(lowerCamelCase_    )
            a_    :     Any										=    list(lowerCamelCase_    )
            a_    :     List[Any]										=    list(lowerCamelCase_    )
            a_    :     Dict										=    xvector_output_dim

       @property
       def 						UpperCAmelCase(   self      :     Union[str, Any]    ):
            return functools.reduce(operator.mul      ,							self.conv_stride      ,							1    )







import dataclasses
import json
import warnings
from dataclasses import dataclass, field
from time import time
from typing import List

from ..utils import logging


__lowerCamelCase        =     logging.get_logger(__name__)



def  _a			(						__UpperCamelCase=None  ,  __UpperCamelCase=None ):
     return field(default_factory=lambda: default  ,  metadata=__UpperCamelCase )


@dataclass
class   a__	:
       lowerCamelCase__:     List[str]							    =     list_field(
           default=[]						,       metadata={
               """help""": (
                   """Model checkpoints to be provided to the AutoModel classes. Leave blank to benchmark the base version"""
                   """ of all available models"""
               )
           }						,       )

       lowerCamelCase__:     List[int]							    =     list_field(
           default=[8]						,       metadata={"""help""": """List of batch sizes for which memory and time performance will be evaluated"""}    )

       lowerCamelCase__:     List[int]							    =     list_field(
           default=[8, 32, 128, 512]						,       metadata={"""help""": """List of sequence lengths for which memory and time performance will be evaluated"""}						,       )

       lowerCamelCase__:     bool							    =     field(
           default=lowerCAmelCase_						,       metadata={"""help""": """Whether to benchmark inference of model. Inference can be disabled via --no-inference."""}						,       )
       lowerCamelCase__:     bool							    =     field(
           default=lowerCAmelCase_						,       metadata={"""help""": """Whether to run on available cuda devices. Cuda can be disabled via --no-cuda."""}						,       )
       lowerCamelCase__:     bool							    =     field(
           default=lowerCAmelCase_						,       metadata={"""help""": """Whether to run on available tpu devices. TPU can be disabled via --no-tpu."""}    )
       lowerCamelCase__:     bool							    =     field(default=lowerCAmelCase_						,       metadata={"""help""": """Use FP16 to accelerate inference."""}    )
       lowerCamelCase__:     bool							    =     field(default=lowerCAmelCase_						,       metadata={"""help""": """Benchmark training of model"""}    )
       lowerCamelCase__:     bool							    =     field(default=lowerCAmelCase_						,       metadata={"""help""": """Verbose memory tracing"""}    )
       lowerCamelCase__:     bool							    =     field(
           default=lowerCAmelCase_						,       metadata={"""help""": """Whether to perform speed measurements. Speed measurements can be disabled via --no-speed."""}						,       )
       lowerCamelCase__:     bool							    =     field(
           default=lowerCAmelCase_						,       metadata={
               """help""": """Whether to perform memory measurements. Memory measurements can be disabled via --no-memory"""
           }						,       )
       lowerCamelCase__:     bool							    =     field(default=lowerCAmelCase_						,       metadata={"""help""": """Trace memory line by line"""}    )
       lowerCamelCase__:     bool							    =     field(default=lowerCAmelCase_						,       metadata={"""help""": """Save result to a CSV file"""}    )
       lowerCamelCase__:     bool							    =     field(default=lowerCAmelCase_						,       metadata={"""help""": """Save all print statements in a log file"""}    )
       lowerCamelCase__:     bool							    =     field(default=lowerCAmelCase_						,       metadata={"""help""": """Whether to print environment information"""}    )
       lowerCamelCase__:     bool							    =     field(
           default=lowerCAmelCase_						,       metadata={
               """help""": (
                   """Whether to use multiprocessing for memory and speed measurement. It is highly recommended to use"""
                   """ multiprocessing for accurate CPU and GPU memory measurements. This option should only be disabled"""
                   """ for debugging / testing and on TPU."""
               )
           }						,       )
       lowerCamelCase__:     str							    =     field(
           default=F"""inference_time_{round(time()    )}.csv"""						,       metadata={"""help""": """CSV filename used if saving time results to csv."""}						,       )
       lowerCamelCase__:     str							    =     field(
           default=F"""inference_memory_{round(time()    )}.csv"""						,       metadata={"""help""": """CSV filename used if saving memory results to csv."""}						,       )
       lowerCamelCase__:     str							    =     field(
           default=F"""train_time_{round(time()    )}.csv"""						,       metadata={"""help""": """CSV filename used if saving time results to csv for training."""}						,       )
       lowerCamelCase__:     str							    =     field(
           default=F"""train_memory_{round(time()    )}.csv"""						,       metadata={"""help""": """CSV filename used if saving memory results to csv for training."""}						,       )
       lowerCamelCase__:     str							    =     field(
           default=F"""env_info_{round(time()    )}.csv"""						,       metadata={"""help""": """CSV filename used if saving environment information."""}						,       )
       lowerCamelCase__:     str							    =     field(
           default=F"""log_{round(time()    )}.csv"""						,       metadata={"""help""": """Log filename used if print statements are saved in log."""}						,       )
       lowerCamelCase__:     int							    =     field(default=3						,       metadata={"""help""": """Times an experiment will be run."""}    )
       lowerCamelCase__:     bool							    =     field(
           default=lowerCAmelCase_						,       metadata={
               """help""": (
                   """Instead of loading the model as defined in `config.architectures` if exists, just load the pretrain"""
                   """ model weights."""
               )
           }						,       )

       def 						UpperCAmelCase(   self      :     Any    ):
            warnings.warn(
                F'''The class {self.__class__} is deprecated. Hugging Face Benchmarking utils'''
                """ are deprecated in general and it is advised to use external Benchmarking libraries """
                """ to benchmark Transformer models."""      ,							lowerCamelCase_      ,							)

       def 						UpperCAmelCase(   self      :     Union[str, Any]    ):
            return json.dumps(dataclasses.asdict(self    )      ,							indent=2    )

       @property
       def 						UpperCAmelCase(   self      :     List[str]    ):
            if len(self.models    ) <= 0:
                 raise ValueError(
                     """Please make sure you provide at least one model name / model identifier, *e.g.* `--models"""
                     """ bert-base-cased` or `args.models = ['bert-base-cased']."""    )
            return self.models

       @property
       def 						UpperCAmelCase(   self      :     Union[str, Any]    ):
            if not self.multi_process:
                 return False
            elif self.is_tpu:
                 logger.info("""Multiprocessing is currently not possible on TPU."""    )
                 return False
            else:
                 return True



