o
    hQ
                     @   st   d dl Z d dlZd dlmZ d dlZdefddZdd Zdd	d
ZdddZ	de
dee
ef fddZdd ZdS )    N)Dictreturnc                 C   s.   |   } | dv r
dS | dv rdS td|  )z
    Converts a string representation of truth to `True` (1) or `False` (0).

    True values are `y`, `yes`, `t`, `true`, `on`, and `1`; False value are `n`, `no`, `f`, `false`, `off`, and `0`;
    )yyesttrueon1   )nnoffalseoff0r   zinvalid truth value )lower
ValueError)value r   R/var/www/html/ai/venv/lib/python3.10/site-packages/accelerate/utils/environment.pystr_to_bool   s   r   c                 C   s0   | D ]}t tj|d}|dkr|  S q|S )zQReturns the first positive env value found in the `env_keys` list or the default.r   )intosenvironget)env_keysdefaultevalr   r   r   get_int_from_env%   s   r    Fc                 C   s   t j| t|}t|dkS )zJReturns truthy value for `key` from the env if available else the default.r
   )r   r   r   strr   keyr   r   r   r   r   parse_flag_from_env.   s   r$   r   c                 C   s   t j| t|}|S N)r   r   r   r!   r"   r   r   r   parse_choice_from_env4   s   r&   library_namesc                  G   s   dd | D S )zu
    Checks if any of `library_names` are imported in the environment. Will return results as a `key:bool` pair.
    c                 S   s   g | ]	}|t jv r|qS r   )sysmodules).0lib_namer   r   r   
<listcomp>=   s    z-are_libraries_initialized.<locals>.<listcomp>r   )r'   r   r   r   are_libraries_initialized9   s   r-   c                     sL   t j r$t j  t j } ddg}| dkr$t fdd|D r$dS dS )z
    Checks if the devices being used have issues with P2P and IB communications, namely any consumer GPU hardware after
    the 3090.
    zRTX 3090zRTX 40r
   c                 3   s    | ]}| v V  qd S r%   r   )r*   devicedevice_namer   r   	<genexpr>K   s    z,check_cuda_p2p_ib_support.<locals>.<genexpr>FT)torchcudais_availableget_device_namedevice_countany)r6   unsupported_devicesr   r/   r   check_cuda_p2p_ib_support@   s   


r9   )F)r   )r   r(   typingr   r2   r   r   r    r$   r&   r!   boolr-   r9   r   r   r   r   <module>   s   
	
