






import functools
import operator

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


snake_case    				=		logging.get_logger(__name__)

snake_case    				=		{
    '''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  SCREAMING_SNAKE_CASE			(			__UpperCAmelCase					):
     '''simple docstring'''


     UpperCamelCase_							:		List[Any]			=	'''wavlm'''


     def __init__(				self       :	int					, UpperCAmelCase_       :	int=32					, UpperCAmelCase_       :	Optional[int]=768					, UpperCAmelCase_       :	Optional[int]=12					, UpperCAmelCase_       :	List[Any]=12					, UpperCAmelCase_       :	List[Any]=3072					, UpperCAmelCase_       :	Tuple="gelu"					, UpperCAmelCase_       :	List[str]=0.1					, UpperCAmelCase_       :	Any=0.1					, UpperCAmelCase_       :	int=0.1					, UpperCAmelCase_       :	Tuple=0.0					, UpperCAmelCase_       :	Any=0.1					, UpperCAmelCase_       :	str=0.1					, UpperCAmelCase_       :	Any=0.02					, UpperCAmelCase_       :	Optional[int]=1E-5					, UpperCAmelCase_       :	int="group"					, UpperCAmelCase_       :	List[str]="gelu"					, UpperCAmelCase_       :	int=(512, 512, 512, 512, 512, 512, 512)					, UpperCAmelCase_       :	int=(5, 2, 2, 2, 2, 2, 2)					, UpperCAmelCase_       :	Any=(10, 3, 3, 3, 3, 2, 2)					, UpperCAmelCase_       :	List[str]=False					, UpperCAmelCase_       :	Any=128					, UpperCAmelCase_       :	Optional[int]=16					, UpperCAmelCase_       :	Dict=320					, UpperCAmelCase_       :	str=800					, UpperCAmelCase_       :	int=False					, UpperCAmelCase_       :	Union[str, Any]=True					, UpperCAmelCase_       :	str=0.05					, UpperCAmelCase_       :	Optional[int]=10					, UpperCAmelCase_       :	Dict=2					, UpperCAmelCase_       :	Dict=0.0					, UpperCAmelCase_       :	Tuple=10					, UpperCAmelCase_       :	str=320					, UpperCAmelCase_       :	Dict=2					, UpperCAmelCase_       :	Tuple=0.1					, UpperCAmelCase_       :	Optional[int]=100					, UpperCAmelCase_       :	Optional[Any]=256					, UpperCAmelCase_       :	List[str]=256					, UpperCAmelCase_       :	Tuple=0.1					, UpperCAmelCase_       :	List[str]="mean"					, UpperCAmelCase_       :	Tuple=False					, UpperCAmelCase_       :	Optional[int]=False					, UpperCAmelCase_       :	Dict=256					, UpperCAmelCase_       :	Any=(512, 512, 512, 512, 1500)					, UpperCAmelCase_       :	List[str]=(5, 3, 3, 1, 1)					, UpperCAmelCase_       :	List[str]=(1, 2, 3, 1, 1)					, UpperCAmelCase_       :	Optional[Any]=512					, UpperCAmelCase_       :	Any=80					, UpperCAmelCase_       :	Optional[int]=0					, UpperCAmelCase_       :	int=1					, UpperCAmelCase_       :	List[str]=2					, UpperCAmelCase_       :	Union[str, Any]=False					, UpperCAmelCase_       :	Optional[int]=3					, UpperCAmelCase_       :	Dict=2					, UpperCAmelCase_       :	Tuple=3					, UpperCAmelCase_       :	Any=None					, **UpperCAmelCase_       :	int					, ):
       super().__init__(**__SCREAMING_SNAKE_CASE					, pad_token_id=__SCREAMING_SNAKE_CASE					, bos_token_id=__SCREAMING_SNAKE_CASE					, eos_token_id=__SCREAMING_SNAKE_CASE      )
       SCREAMING_SNAKE_CASE       :      Union[str, Any]							=    hidden_size
       SCREAMING_SNAKE_CASE       :      Optional[int]							=    feat_extract_norm
       SCREAMING_SNAKE_CASE       :      Union[str, Any]							=    feat_extract_activation
       SCREAMING_SNAKE_CASE       :      Union[str, Any]							=    list(__SCREAMING_SNAKE_CASE      )
       SCREAMING_SNAKE_CASE       :      List[Any]							=    list(__SCREAMING_SNAKE_CASE      )
       SCREAMING_SNAKE_CASE       :      str							=    list(__SCREAMING_SNAKE_CASE      )
       SCREAMING_SNAKE_CASE       :      Union[str, Any]							=    conv_bias
       SCREAMING_SNAKE_CASE       :      str							=    num_buckets
       SCREAMING_SNAKE_CASE       :      Optional[int]							=    max_bucket_distance
       SCREAMING_SNAKE_CASE       :      Optional[int]							=    num_conv_pos_embeddings
       SCREAMING_SNAKE_CASE       :      Any							=    num_conv_pos_embedding_groups
       SCREAMING_SNAKE_CASE       :      str							=    len(self.conv_dim      )
       SCREAMING_SNAKE_CASE       :      Optional[Any]							=    num_hidden_layers
       SCREAMING_SNAKE_CASE       :      Tuple							=    intermediate_size
       SCREAMING_SNAKE_CASE       :      int							=    hidden_act
       SCREAMING_SNAKE_CASE       :      List[Any]							=    num_attention_heads
       SCREAMING_SNAKE_CASE       :      List[str]							=    hidden_dropout
       SCREAMING_SNAKE_CASE       :      Tuple							=    attention_dropout
       SCREAMING_SNAKE_CASE       :      List[str]							=    activation_dropout
       SCREAMING_SNAKE_CASE       :      Tuple							=    feat_proj_dropout
       SCREAMING_SNAKE_CASE       :      Tuple							=    final_dropout
       SCREAMING_SNAKE_CASE       :      Optional[int]							=    layerdrop
       SCREAMING_SNAKE_CASE       :      Tuple							=    layer_norm_eps
       SCREAMING_SNAKE_CASE       :      Optional[Any]							=    initializer_range
       SCREAMING_SNAKE_CASE       :      str							=    num_ctc_classes
       SCREAMING_SNAKE_CASE       :      Any							=    vocab_size
       SCREAMING_SNAKE_CASE       :      Union[str, Any]							=    do_stable_layer_norm
       SCREAMING_SNAKE_CASE       :      int							=    use_weighted_layer_sum
       SCREAMING_SNAKE_CASE       :      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
       SCREAMING_SNAKE_CASE       :      List[str]							=    apply_spec_augment
       SCREAMING_SNAKE_CASE       :      List[str]							=    mask_time_prob
       SCREAMING_SNAKE_CASE       :      List[Any]							=    mask_time_length
       SCREAMING_SNAKE_CASE       :      Optional[int]							=    mask_time_min_masks
       SCREAMING_SNAKE_CASE       :      Dict							=    mask_feature_prob
       SCREAMING_SNAKE_CASE       :      str							=    mask_feature_length

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

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

       # adapter
       SCREAMING_SNAKE_CASE       :      Union[str, Any]							=    add_adapter
       SCREAMING_SNAKE_CASE       :      Union[str, Any]							=    adapter_kernel_size
       SCREAMING_SNAKE_CASE       :      Optional[Any]							=    adapter_stride
       SCREAMING_SNAKE_CASE       :      List[Any]							=    num_adapter_layers
       SCREAMING_SNAKE_CASE       :      int							=    output_hidden_size or hidden_size

       # SequenceClassification-specific parameter. Feel free to ignore for other classes.
       SCREAMING_SNAKE_CASE       :      Optional[int]							=    classifier_proj_size

       # XVector-specific parameters. Feel free to ignore for other classes.
       SCREAMING_SNAKE_CASE       :      Union[str, Any]							=    list(__SCREAMING_SNAKE_CASE      )
       SCREAMING_SNAKE_CASE       :      List[Any]							=    list(__SCREAMING_SNAKE_CASE      )
       SCREAMING_SNAKE_CASE       :      List[Any]							=    list(__SCREAMING_SNAKE_CASE      )
       SCREAMING_SNAKE_CASE       :      int							=    xvector_output_dim






     @property
     def 				_A       (				self       :	Optional[int]      ):
       return functools.reduce(operator.mul					, self.conv_stride					, 1      )














# Copyright 2021 The HuggingFace 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.

from pathlib import Path

import torch

from ...utils import is_npu_available, is_xpu_available
from .config_args import ClusterConfig, default_json_config_file
from .config_utils import SubcommandHelpFormatter


snake_case    				=		"""Create a default config file for Accelerate with only a few flags set."""


def   lowerCamelCase__			(     lowercase="no"						,     lowercase = default_json_config_file						,     lowercase = False				):

  """simple docstring"""






  SCREAMING_SNAKE_CASE       :      Tuple							=    Path(lowercase				)
  path.parent.mkdir(parents=lowercase						,     exist_ok=lowercase				)
  if path.exists():
    print(
        F'''Configuration already exists at {save_location}, will not override. Run `accelerate config` manually or pass a different `save_location`.'''				)
    return False
  SCREAMING_SNAKE_CASE       :      int							=    mixed_precision.lower()
  if mixed_precision not in ["no", "fp16", "bf16", "fp8"]:
    raise ValueError(
        F'''`mixed_precision` should be one of \'no\', \'fp16\', \'bf16\', or \'fp8\'. Received {mixed_precision}'''				)
  SCREAMING_SNAKE_CASE       :      Union[str, Any]							=    {
      "compute_environment": "LOCAL_MACHINE",
      "mixed_precision": mixed_precision,
  }
  if torch.cuda.is_available():
    SCREAMING_SNAKE_CASE       :      Union[str, Any]							=    torch.cuda.device_count()
    SCREAMING_SNAKE_CASE       :      int							=    num_gpus
    SCREAMING_SNAKE_CASE       :      Union[str, Any]							=    False
    if num_gpus > 1:
      SCREAMING_SNAKE_CASE       :      Tuple							=    "MULTI_GPU"
    else:
      SCREAMING_SNAKE_CASE       :      Optional[Any]							=    "NO"
  elif is_xpu_available() and use_xpu:
    SCREAMING_SNAKE_CASE       :      List[str]							=    torch.xpu.device_count()
    SCREAMING_SNAKE_CASE       :      str							=    num_xpus
    SCREAMING_SNAKE_CASE       :      Union[str, Any]							=    False
    if num_xpus > 1:
      SCREAMING_SNAKE_CASE       :      Any							=    "MULTI_XPU"
    else:
      SCREAMING_SNAKE_CASE       :      str							=    "NO"
  elif is_npu_available():
    SCREAMING_SNAKE_CASE       :      List[Any]							=    torch.npu.device_count()
    SCREAMING_SNAKE_CASE       :      Optional[Any]							=    num_npus
    SCREAMING_SNAKE_CASE       :      Union[str, Any]							=    False
    if num_npus > 1:
      SCREAMING_SNAKE_CASE       :      str							=    "MULTI_NPU"
    else:
      SCREAMING_SNAKE_CASE       :      int							=    "NO"
  else:
    SCREAMING_SNAKE_CASE       :      Dict							=    0
    SCREAMING_SNAKE_CASE       :      List[Any]							=    True
    SCREAMING_SNAKE_CASE       :      Dict							=    1
    SCREAMING_SNAKE_CASE       :      int							=    "NO"
  SCREAMING_SNAKE_CASE       :      Dict							=    ClusterConfig(**lowercase				)
  config.to_json_file(lowercase				)
  return path


def   lowerCamelCase__			(     lowercase						,     lowercase				):

  """simple docstring"""






  SCREAMING_SNAKE_CASE       :      Dict							=    parser.add_parser("default"						,     parents=lowercase						,     help=lowercase						,     formatter_class=lowercase				)
  parser.add_argument(
      "--config_file"						,     default=lowercase						,     help=(
          "The path to use to store the config file. Will default to a file named default_config.yaml in the cache "
          "location, which is the content of the environment `HF_HOME` suffixed with 'accelerate', or if you don't have "
          "such an environment variable, your cache directory ('~/.cache' or the content of `XDG_CACHE_HOME`) suffixed "
          "with 'huggingface'."
      )						,     dest="save_location"						,     )

  parser.add_argument(
      "--mixed_precision"						,     choices=["no", "fp16", "bf16"]						,     type=lowercase						,     help="Whether or not to use mixed precision training. "
      "Choose between FP16 and BF16 (bfloat16) training. "
      "BF16 training is only supported on Nvidia Ampere GPUs and PyTorch 1.10 or later."						,     default="no"						,     )
  parser.set_defaults(func=lowercase				)
  return parser


def   lowerCamelCase__			(     lowercase				):

  """simple docstring"""






  SCREAMING_SNAKE_CASE       :      Optional[int]							=    write_basic_config(args.mixed_precision						,     args.save_location				)
  if config_file:
    print(F'''accelerate configuration saved at {config_file}'''				)






