
    biE                     v    d dl mZ d dlZddl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Zd Zd Zy)    )PathN   )is_hpu_availableis_mlu_availableis_musa_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                 *   t        |      }|j                  j                  dd       |j                         rt	        d| d       y| j                         } | dvrt        d|        d| d	}t               r8t        j                  j                         }||d
<   d|d<   |dkD  rd|d<   nd|d<   t               r;t        j                  j                         }||d
<   d|d<   |dkD  rd|d<   n}d|d<   nvt               r;t        j                  j                         }||d
<   d|d<   |dkD  rd|d<   n8d|d<   n1t               r9t        j                   j                         }||d
<   d|d<   |dkD  rd|d<   nd|d<   nt        j"                  j%                         r9t        j"                  j                         }||d
<   d|d<   |dkD  rd|d<   nd|d<   nt'               r9t        j(                  j                         }	|	|d
<   d|d<   |	dkD  rd|d<   nZd|d<   nTt+               r9t        j,                  j                         }
|
|d
<   d|d<   |
dkD  rd|d<   nd|d<   nd}	d|d<   d|d
<   d|d<   d|d<   d|d<   t/        di |}|j1                  |       |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_NPUr   debugenable_cpu_affinity )r   parentmkdirexistsprintlower
ValueErrorr   torchmludevice_countr	   sdaar   musar   hpucudais_availabler
   xpur   npur   to_json_file)r   r   pathconfignum_mlus	num_sdaas	num_musasnum_hpusnum_gpusnum_xpusnum_npuss              ]/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/accelerate/commands/config/default.pywrite_basic_configrC   $   s    DKKdT2{{}.}o  >X  Y	
 %++-O;;Z[jZkl
 	
  /*F 99))+"*!ya<)4F%&)-F%&JJ++-	"+!yq=)5F%&)-F%&		JJ++-	"+!yq=)5F%&)-F%&		99))+"*!ya<)4F%&)-F%&		 	 	"::**,"*!ya<)4F%&)-F%&		99))+"*!ya<)4F%&)-F%&		99))+"*!ya<)4F%&)-F%& y"#%)!"F7O$)F !$V$F
K    c                     | j                  d|t        t              } | j                  dt        dd       | j                  dg dt
        d	d
       | j                  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   )rF   rG   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typerG   rF   )func)
add_parserdescriptionr   add_argumentr   strset_defaultsdefault_config_command)parserr   s     rB   default_command_parserrT      s    y']tuF
("
   
 &[    34MrD   c                 f    t        | j                  | j                        }|rt        d|        y y )Nz"accelerate configuration saved at )rC   r   r   r+   )argsconfig_files     rB   rR   rR      s2    $T%9%94;M;MNK2;-@A rD   )pathlibr   r.   utilsr   r   r   r   r	   r
   config_argsr   r   config_utilsr   rN   rP   rC   rT   rR   r'   rD   rB   <module>r\      sJ   "    A 1 W (,BZ ^C ^B6BrD   