
    gI                     v    d dl mZ d dlZddlmZmZmZmZ ddlm	Z	m
Z
 ddlmZ dZd	e
d
fdedefdZd Zd ZdS )    )PathN   )is_mlu_availableis_musa_availableis_npu_availableis_xpu_available   )ClusterConfigdefault_json_config_file)SubcommandHelpFormatterzFCreate a default config file for Accelerate with only a few flags set.noFsave_locationuse_xpuc                 ~   t          |          }|j                            dd           |                                rt	          d| d           dS |                                 } | dvrt          d|            d| d	}t                      r<t          j	        
                                }||d
<   d|d<   |dk    rd|d<   nKd|d<   nDt                      r;t          j        
                                }||d
<   d|d<   |dk    rd|d<   nd|d<   nt          j                                        r:t          j        
                                }||d
<   d|d<   |dk    rd|d<   nd|d<   nt                      r<|r:t          j        
                                }||d
<   d|d<   |dk    rd|d<   n_d|d<   nYt#                      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 )aA  
    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 overriden by setting
            the `HF_HOME` environmental variable, followed by `accelerate/default_config.yaml`.
        use_xpu (`bool`, *optional*, defaults to `False`):
            Whether to use XPU if available.
    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_MUSA	MULTI_GPU	MULTI_XPU	MULTI_NPUr   debugenable_cpu_affinity )r   parentmkdirexistsprintlower
ValueErrorr   torchmludevice_countr   musacudais_availabler   xpur   npur
   to_json_file)
r   r   r   pathconfignum_mlus	num_musasnum_gpusnum_xpusnum_npuss
             ^/var/www/html/ai-engine/env/lib/python3.11/site-packages/accelerate/commands/config/default.pywrite_basic_configr<      s    DKdT222{{}}  Y}  Y  Y  Y	
 	
 	
 u%++--O;;;l[jll
 
 	
  /* F  ,*9))++"*!ya<<)4F%&&)-F%&&			 $*J++--	"+!yq==)5F%&&)-F%&&		 	 	"	" *:**,,"*!ya<<)4F%&&)-F%&&			 * *9))++"*!ya<<)4F%&&)-F%&&			 *9))++"*!ya<<)4F%&&)-F%&& y"#%)!"F7O$)F !$$V$$F
K    c                     |                      d|t          t                    } |                     dt          dd           |                     dg dt
          d	d
           |                     t                     | 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   zWhether 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   s     r;   default_command_parserrM   p   s    y']tuuF
("
   
 
 
 &&&[      3444Mr=   c                 f    t          | j        | j                  }|rt          d|            d S d S )Nz"accelerate configuration saved at )r<   r   r   r(   )argsconfig_files     r;   rK   rK      sI    $T%94;MNNK B@;@@AAAAAB Br=   )pathlibr   r+   utilsr   r   r   r   config_argsr
   r   config_utilsr   rG   rI   boolr<   rM   rK   r$   r=   r;   <module>rV      s   "        \ \ \ \ \ \ \ \ \ \ \ \ @ @ @ @ @ @ @ @ 1 1 1 1 1 1 W (,BZlq P PC Pei P P P Pf  6B B B B Br=   