
    i	                     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   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                 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    c/var/www/vps2.regionflexible.com/Desarrollo/venv/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    |  $yy668AA&**,J~~i(,<<'-1AA*',7DF8<()289I9U9U9W2XDF8-./.45E5P5P5R.SDF8>*+.45E5P5P5R.SDF8>*+5E5S5S5UDF8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8D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   