
    h	                     p    S r SSKJrJrJrJr  SSKrSSKJr  SSK	J
r
  SSKJr  SSKJr   SS	\S
\4S jjrg)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                    ^ ^  SSK m[        (       d  [        S5      e[        R
                  [        R                  4S[        S[        S[        4UU 4S jjjnU$ ! [         a    [        S5      ef = f)	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   NzThe 'cupy' library could not be found - did you install it? Alternatively, specify the 'ConsoleLogger' in the 'training.logger' config section, instead of the 'CuPyLogger'.zThe 'cupy' library could be loaded but GPU support couldn't be initialized - do you have the necessary CUDA libraries installed?nlpstdoutstderrc                 |   >^ S[         S[        4S jmS[        [        [        [
        4      4UUU4S jjnS nX44$ )Nbytesr   c                     U S-  $ )Ng      0A )r   s    L/home/james-whalen/.local/lib/python3.13/site-packages/spacy_loggers/cupy.pyto_mib4cupy_logger_v1.<locals>.setup_logger.<locals>.to_mib)   s    I&&    infoc                   > U c  g TR                   R                  5       R                  n[        R                  " 5       nUR	                  S5      U:X  a  SnOUR	                  S5      U:X  a  SnOSnX0T S3'   T" UR                  5       5      U T S3'   T" UR                  5       5      U T S3'   T" UR                  5       5      U T S3'   UR                  5       U T S3'   g )	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_step6cupy_logger_v1.<locals>.setup_logger.<locals>.log_step,   s    |  $yy668AA&**,J~~i(,<<'-1AA*',7F8<()289I9U9U9W2XDF8-./.45E5P5P5R.SDF8>*+.45E5P5P5R.SDF8>*+5E5S5S5UDF8012r   c                      g )Nr   r   r   r   finalize6cupy_logger_v1.<locals>.setup_logger.<locals>.finalizeB   s    r   )intfloatr   r   strr   )r   r   r   r+   r.   r   r*   r   s        @r   setup_logger$cupy_logger_v1.<locals>.setup_logger(   sG    	'# 	'% 	'	V8DcN3 	V 	V,	 !!r   )	r*   ImportErrorr	   
ValueErrorsysr   r   r   r   )r   r3   r*   s   ` @r   cupy_logger_v1r8      s    
 <B
 	

 25#** "( "B "R " "> Y  
M
 	

s   A A1)r*   )__doc__typingr   r   r   r   r7   spacyr   thinc.backendsr   
thinc.utilr	   utilr   r2   r8   r   r   r   <module>r?      s;    + * 
  ( #  :::r   