o
    i el                     @   sb   d Z ddlZddlm  mZ ddlmZ dZed Z	ed Z
dZdd	 Zd
d Zdadd ZdS )zHContains function to log if devices are compatible with mixed precision.    N)
tf_loggingz5Mixed precision compatibility check (mixed_float16): OKWARNINGzIf you will use compatible GPU(s) not attached to this host, e.g. by running a multi-worker model, you can ignore this warning. This message will only be logged oncec                 C   sN   g }t | D ]\}}tt|}|dkr|| q|d||f  q|S )a  Groups together consecutive identical strings.

    For example, given:
        ['GPU 1', 'GPU 2', 'GPU 2', 'GPU 3', 'GPU 3', 'GPU 3']
    This function returns:
        ['GPU 1', 'GPU 2 (x2)', 'GPU 3 (x3)']

    Args:
      device_strs: A list of strings, each representing a device.

    Returns:
      A copy of the input, but identical consecutive strings are merged into a
      single string.
       z%s (x%d))	itertoolsgroupbylenlistappend)device_strsnew_device_strs
device_strvalsnum r   c/var/www/myenv/lib/python3.10/site-packages/keras/src/mixed_precision/device_compatibility_check.py_dedup_strings"   s   r   c           	      C   sL  | dkrdS g }g }|D ]4}| dd}| d}|r9| d|d  d|d	  }|d
kr3|| q|| q||d  q|r}td }|rN|d7 }nt|d	krY|d7 }n|d7 }t|| D ]
}|d| d 7 }qc|d7 }|t7 }t| dS |stdttf  dS t|d	krtdt	|d f  dS tdt	  dS )ai  Logs a compatibility check if the devices support the policy.

    Currently only logs for the policy mixed_float16.

    Args:
      policy_name: The name of the dtype policy.
      gpu_details_list: A list of dicts, one dict per GPU. Each dict
        is the device details for a GPU, as returned by
        `tf.config.experimental.get_device_details()`.
    mixed_float16Ndevice_namezUnknown GPUcompute_capabilityz, compute capability r   .r   )   r   z4, no compute capability (probably not an Nvidia GPU)
zSome of your GPUs may run slowly with dtype policy mixed_float16 because they do not all have compute capability of at least 7.0. Your GPUs:
zYour GPU may run slowly with dtype policy mixed_float16 because it does not have compute capability of at least 7.0. Your GPU:
zYour GPUs may run slowly with dtype policy mixed_float16 because they do not have compute capability of at least 7.0. Your GPUs:
z  z^See https://developer.nvidia.com/cuda-gpus for a list of GPUs and their compute capabilities.
z%s
The dtype policy mixed_float16 may run slowly because this machine does not have a GPU. Only Nvidia GPUs with compute capability of at least 7.0 run quickly with mixed_float16.
%sz~%s
Your GPU will likely run quickly with dtype policy mixed_float16 as it has compute capability of at least 7.0. Your GPU: %szx%s
Your GPUs will likely run quickly with dtype policy mixed_float16 as they all have compute capability of at least 7.0)
getr
   _COMPAT_CHECK_WARNING_PREFIXr   r   _COMPAT_CHECK_WARNING_SUFFIXr   warninginfo_COMPAT_CHECK_OK_PREFIX)	policy_namegpu_details_listsupported_device_strsunsupported_device_strsdetailsnameccr   warning_strr   r   r   _log_device_compatibility_check;   sl   

r'   Fc                 C   s4   t rdS da tjd}dd |D }t| | dS )zLogs a compatibility check if the devices support the policy.

    Currently only logs for the policy mixed_float16. A log is shown only the
    first time this function is called.

    Args:
      policy_name: The name of the dtype policy.
    NTGPUc                 S   s   g | ]	}t jj|qS r   )tfconfigexperimentalget_device_details).0gr   r   r   
<listcomp>   s    z2log_device_compatibility_check.<locals>.<listcomp>)_logged_compatibility_checkr)   r*   list_physical_devicesr'   )r   gpusr    r   r   r   log_device_compatibility_check   s   
r3   )__doc__r   tensorflow.compat.v2compatv2r)   tensorflow.python.platformr   _COMPAT_CHECK_PREFIXr   r   r   r   r'   r0   r3   r   r   r   r   <module>   s   W