U
    0-e                     @   sp   d dl mZ d dlZddlmZmZ ddlmZmZ ddl	m
Z
 dZd	ed
feedddZdd Zdd ZdS )    )PathN   )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                 C   sX  t |}|jjddd | r4td| d dS |  } | dkrRtd|  d| d	}tj	 rtj
 }||d
< d|d< |dkrd|d< nd|d< nt r|rtj
 }||d
< d|d< |dkrd|d< nd|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< tf |}|| |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bf16Zfp8zL`mixed_precision` should be one of 'no', 'fp16', 'bf16', or 'fp8'. Received ZLOCAL_MACHINE)Zcompute_environmentmixed_precisionZnum_processesZuse_cpur   Z	MULTI_GPUZdistributed_typeNOZ	MULTI_XPUZ	MULTI_NPUr   debug)r   parentmkdirexistsprintlower
ValueErrortorchcudaZis_availableZdevice_countr   Zxpur   Znpur   Zto_json_file)r   r   r   pathconfigZnum_gpusZnum_xpusZnum_npus r   c/var/www/html/Darija-Ai-Train/env/lib/python3.8/site-packages/accelerate/commands/config/default.pywrite_basic_config   sX    














r    c                 C   sN   | j d|ttd} | jdtddd | jddd	d
g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_precisionr
   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.)choicestyper"   r!   )func)
add_parserdescriptionr	   add_argumentr   strset_defaultsdefault_config_command)parserr   r   r   r   default_command_parser_   s     	r/   c                 C   s$   t | j| j}|r td|  d S )Nz"accelerate configuration saved at )r    r   r   r   )argsconfig_filer   r   r   r-   z   s    r-   )pathlibr   r   utilsr   r   Zconfig_argsr   r   Zconfig_utilsr	   r)   r+   boolr    r/   r-   r   r   r   r   <module>   s   B