o
    rôjŸ  ã                   @   s€   d dl mZ d dlZddlmZmZmZmZmZm	Z	m
Z
 ddlmZmZ ddlmZ dZd	efd
efdd„Zdd„ Zdd„ ZdS )é    )ÚPathNé   )Úis_hpu_availableÚis_mlu_availableÚis_musa_availableÚis_neuron_availableÚis_npu_availableÚis_sdaa_availableÚis_xpu_availableé   )ÚClusterConfigÚdefault_json_config_file)ÚSubcommandHelpFormatterzFCreate a default config file for Accelerate with only a few flags set.ÚnoÚsave_locationc                 C   sŒ  t |ƒ}|jjddd� | ¡ rtd|› d�ƒ dS |  ¡ } | dvr)td| › �ƒ‚d| d	œ}tƒ rKtj	 
¡ }||d
< d|d< |dkrGd|d< nd|d< tƒ ritj 
¡ }||d
< d|d< |dkrdd|d< nÌd|d< nÇtƒ r‡tj 
¡ }||d
< d|d< |dkr‚d|d< n®d|d< n©tƒ r¥tj 
¡ }||d
< d|d< |dkr d|d< n�d|d< n‹tj ¡ rÅtj 
¡ }||d
< d|d< |dkrÀd|d< npd|d< nktƒ rãtj 
¡ }	|	|d
< d|d< |	dkrÞd|d< nRd|d< nMtƒ �rtj 
¡ }
|
|d
< d|d< |
dkrýd|d< n3d|d< n.tƒ �r"tj 
¡ }||d
< d|d< |dk�rd|d< nd|d< nd}	d|d< d|d
< d|d< d|d< d|d< tdi |¤Ž}| |¡ |S )aÚ  
    Creates and saves a basic cluster config to be used on a local machine with potentially multiple GPUs. Will also
    set CPU if it is a CPU-only machine.

    Args:
        mixed_precision (`str`, *optional*, defaults to "no"):
            Mixed Precision to use. Should be one of "no", "fp16", or "bf16"
        save_location (`str`, *optional*, defaults to `default_json_config_file`):
            Optional custom save location. Should be passed to `--config_file` when using `accelerate launch`. Default
            location is inside the huggingface cache folder (`~/.cache/huggingface`) but can be overridden by setting
            the `HF_HOME` environmental variable, followed by `accelerate/default_config.yaml`.
    T)ÚparentsÚexist_okz Configuration already exists at zZ, will not override. Run `accelerate config` manually or pass a different `save_location`.F)r   Úfp16Úbf16Úfp8zL`mixed_precision` should be one of 'no', 'fp16', 'bf16', or 'fp8'. Received ÚLOCAL_MACHINE)Úcompute_environmentÚmixed_precisionÚnum_processesÚuse_cpur   Ú	MULTI_MLUÚdistributed_typeÚNOÚ
MULTI_SDAAÚ
MULTI_MUSAÚ	MULTI_HPUÚ	MULTI_GPUÚ	MULTI_XPUÚ	MULTI_NPUÚMULTI_NEURONr   ÚdebugÚenable_cpu_affinityN© )r   ÚparentÚmkdirÚexistsÚprintÚlowerÚ
ValueErrorr   ÚtorchÚmluÚdevice_countr	   Úsdaar   Úmusar   ÚhpuÚcudaÚis_availabler
   Úxpur   Únpur   Úneuronr   Úto_json_file)r   r   ÚpathÚconfigZnum_mlusZ	num_sdaasZ	num_musasZnum_hpusZnum_gpusZnum_xpusZnum_npusZnum_neuron_coresr'   r'   ús/var/www/html/academy/tools/voices/clone/sv-venv/lib/python3.10/site-packages/accelerate/commands/config/default.pyÚwrite_basic_config%   s    
ÿÿþ

























r=   c                 C   sL   | j d|ttd�} | jdtddd� | jdg d¢td	d
d� | jtd� | S )NÚdefault)r   ÚhelpÚformatter_classz--config_fileaT  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'.r   )r>   r?   Údestz--mixed_precision)r   r   r   z²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.r   )ÚchoicesÚtyper?   r>   )Úfunc)Ú
add_parserÚdescriptionr   Úadd_argumentr   ÚstrÚset_defaultsÚdefault_config_command)Úparserr   r'   r'   r<   Údefault_command_parserŽ   s    ÷ù	rL   c                 C   s(   t | j| jƒ}|rtd|› �ƒ d S d S )Nz"accelerate configuration saved at )r=   r   r   r+   )ÚargsÚconfig_filer'   r'   r<   rJ   ©   s   ÿrJ   )Úpathlibr   r.   Úutilsr   r   r   r   r   r	   r
   Úconfig_argsr   r   Úconfig_utilsr   rF   rH   r=   rL   rJ   r'   r'   r'   r<   Ú<module>   s   $	i