Ë
    Áš¾j²	  ã                   ól   — d Z ddlmZmZmZmZ ddlZddlmZ ddl	m
Z
 ddlmZ ddlmZ 	 dd	ed
efd„Zy)zW
A logger that queries CuPy metrics and passes that information to downstream loggers.
é    )ÚDictÚAnyÚOptionalÚION)ÚLanguage)Úcontext_pools)Úhas_cupy_gpué   )ÚLoggerTÚprefixÚreturnc                 óÖ   ‡ ‡— 	 ddl Št        st        d«      ‚t        j
                  t        j                  fdt        dt        dt        fˆˆ fd„}|S # t        $ r t        d«      ‚w xY w)	a  Creates a logger that queries CuPy metrics and passes that information to downstream loggers.

    Args:
        prefix (str):
            All metric names are prefixed with this string using dot notation, e.g: `<prefix>.<metric>`.

    Returns:
        LoggerT: Logger instance.
    r   Nz¬The 'cupy' library could not be found - did you install it? Alternatively, specify the 'ConsoleLogger' in the 'training.logger' config section, instead of the 'CuPyLogger'.z€The 'cupy' library could be loaded but GPU support couldn't be initialized - do you have the necessary CUDA libraries installed?ÚnlpÚstdoutÚstderrc                 óx   •‡— dt         dt        fd„Šdt        t        t        t
        f      fˆˆˆfd„}d„ }||fS )NÚbytesr   c                 ó   — | dz  S )Ng      0A© )r   s    ú\/home/spazio/kingdom_calls/work5/transenv/lib/python3.12/site-packages/spacy_loggers/cupy.pyÚto_mibz4cupy_logger_v1.<locals>.setup_logger.<locals>.to_mib)   s   € Ø˜IÑ&Ð&ó    Úinfoc                 óÀ  •— | €y ‰j                   j                  «       j                  }t        j                  «       }|j	                  d«      |k(  rd}n|j	                  d«      |k(  rd}nd}|| ‰› d�<    ‰|j                  «       «      | ‰› d�<    ‰|j                  «       «      | ‰› d�<    ‰|j                  «       «      | ‰› d�<   |j                  «       | ‰› d�<   y )	NÚpytorchÚ
tensorflowÚdefaultz.pool.sourcez.pool.acquired_mibz.pool.used_mibz.pool.free_mibz.pool.num_free_blocks)	ÚcudaÚget_allocatorÚ__self__r   ÚgetÚtotal_bytesÚ
used_bytesÚ
free_bytesÚn_free_blocks)r   Úcupy_memory_poolÚ
thinc_poolÚpool_sourceÚcupyr   r   s       €€€r   Úlog_stepz6cupy_logger_v1.<locals>.setup_logger.<locals>.log_step,   sô   ø€ Øˆ|Øð  $Ÿy™y×6Ñ6Ó8×AÑAÐÜ&×*Ñ*Ó,ˆJà�~‰~˜iÓ(Ð,<Ò<Ø'‘Ø—‘ Ó-Ð1AÒAØ*‘à'�à,7ˆD�F�8˜<Ð(Ñ)Ù28Ð9I×9UÑ9UÓ9WÓ2XˆD�F�8Ð-Ð.Ñ/Ù.4Ð5E×5PÑ5PÓ5RÓ.SˆD�F�8˜>Ð*Ñ+Ù.4Ð5E×5PÑ5PÓ5RÓ.SˆD�F�8˜>Ð*Ñ+Ø5E×5SÑ5SÓ5UˆD�F�8Ð0Ð1Ò2r   c                   ó   — y )Nr   r   r   r   Úfinalizez6cupy_logger_v1.<locals>.setup_logger.<locals>.finalizeB   s   € Ør   )ÚintÚfloatr   r   Ústrr   )r   r   r   r*   r,   r   r)   r   s        @€€r   Úsetup_loggerz$cupy_logger_v1.<locals>.setup_logger(   sC   ù€ ð	'œ#ð 	'¤%ó 	'ð	Vœ8¤D¬¬c¨¡NÑ3÷ 	Vò,	ð ˜Ð!Ð!r   )	r)   ÚImportErrorr	   Ú
ValueErrorÚsysr   r   r   r   )r   r0   r)   s   ` @r   Úcupy_logger_v1r4      sy   ù€ ð
Ûõ ÜðBó
ð 	
ô
 25·±Ì#Ï*É*ñ "œ(ð "¬Bð "ÄRö "ð> ÐøôY ò 
ÜðMó
ð 	
ð
ús   „A ÁA()r)   )Ú__doc__Útypingr   r   r   r   r3   Úspacyr   Úthinc.backendsr   Ú
thinc.utilr	   Úutilr   r/   r4   r   r   r   ú<module>r;      s;   ðñ÷ +Ó *Û 
å Ý (Ý #Ý ð ñ:Øð:àô:r   