a
    þdà  ã                   @   sž   d Z ddlmZmZ ddlmZ ddlmZ ddlm	Z	m
Z
mZmZmZ ddlmZ ddlmZ ddlmZ G d	d
„ d
eƒZe
e
dœdd„ZG dd„ dƒZdS )z.Abstract base class used to build new loggers.é    )ÚABCÚabstractmethod)Ú	Namespace)Úwraps)ÚAnyÚCallableÚDictÚOptionalÚUnion)ÚTensor)ÚModule)Úrank_zero_onlyc                   @   s  e Zd ZdZeeee dœdd„ƒƒZeeee	e
ef  dœdd„ƒƒZeee dœdd„ƒZeee dœd	d
„ƒZeedœdd„ƒZedeeef ee
 ddœdd„ƒZee	eeef ef eeddœdd„ƒZdeee ddœdd„Zddœdd„Zeddœdd„ZdS )ÚLoggerz"Base class for experiment loggers.©Úreturnc                 C   s   dS )zReturn the experiment name.N© ©Úselfr   r   úh/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/lightning_fabric/loggers/logger.pyÚname   s    zLogger.namec                 C   s   dS )zReturn the experiment version.Nr   r   r   r   r   Úversion#   s    zLogger.versionc                 C   s   dS )z„Return the root directory where all versions of an experiment get saved, or `None` if the logger does
        not save data locally.Nr   r   r   r   r   Úroot_dir(   s    zLogger.root_dirc                 C   s   dS )z~Return directory the current version of the experiment gets saved, or `None` if the logger does not save
        data locally.Nr   r   r   r   r   Úlog_dir.   s    zLogger.log_dirc                 C   s   dS )zRReturn the default separator used by the logger to group the data into subfolders.ú/r   r   r   r   r   Úgroup_separator4   s    zLogger.group_separatorN)ÚmetricsÚstepr   c                 C   s   dS )a   Records metrics. This method logs metrics as soon as it received them.

        Args:
            metrics: Dictionary with metric names as keys and measured quantities as values
            step: Step number at which the metrics should be recorded
        Nr   )r   r   r   r   r   r   Úlog_metrics9   s    zLogger.log_metrics)ÚparamsÚargsÚkwargsr   c                 O   s   dS )a>  Record hyperparameters.

        Args:
            params: :class:`~argparse.Namespace` or `Dict` containing the hyperparameters
            args: Optional positional arguments, depends on the specific logger being used
            kwargs: Optional keyword arguments, depends on the specific logger being used
        Nr   )r   r   r   r    r   r   r   Úlog_hyperparamsC   s    zLogger.log_hyperparams)ÚmodelÚinput_arrayr   c                 C   s   dS )z¨Record model graph.

        Args:
            model: the model with an implementation of ``forward``.
            input_array: input passes to `model.forward`
        Nr   )r   r"   r#   r   r   r   Ú	log_graphM   s    zLogger.log_graphc                 C   s   dS )zSave log data.Nr   r   r   r   r   ÚsaveV   s    zLogger.save)Ústatusr   c                 C   s   |   ¡  dS )z³Do any processing that is necessary to finalize an experiment.

        Args:
            status: Status that the experiment finished with (e.g. success, failed, aborted)
        N)r%   )r   r&   r   r   r   ÚfinalizeY   s    zLogger.finalize)N)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úpropertyr   r	   Ústrr   r
   Úintr   r   r   r   r   Úfloatr   r   r   r!   r   r   r$   r%   r'   r   r   r   r   r      s(   "	&		r   )Úfnr   c                    s&   t ˆ ƒtttf dœ‡ fdd„ƒ}|S )zIReturns the real experiment on rank 0 and otherwise the _DummyExperiment.r   c                    s$   t tdœ‡‡ fdd„ƒ}|ƒ p"tƒ S )aÈ  
        Note:
            ``self`` is a custom logger instance. The loggers typically wrap an ``experiment`` method
            with a ``@rank_zero_experiment`` decorator.

            ``Union[Any, _DummyExperiment]`` is used because the wrapped hooks have several return
            types that are specific to the custom logger. The return type here can be considered as
            ``Union[return type of logger.experiment, _DummyExperiment]``.
        r   c                      s   ˆ ˆƒS ©Nr   r   )r0   r   r   r   Úget_experimentq   s    z@rank_zero_experiment.<locals>.experiment.<locals>.get_experiment)r   r   Ú_DummyExperiment)r   r2   ©r0   r   r   Ú
experimente   s    z(rank_zero_experiment.<locals>.experiment)r   r
   r   r3   )r0   r5   r   r4   r   Úrank_zero_experimentb   s    r6   c                   @   sT   e Zd ZdZeeddœdd„Zeedœdd„Zed d	œd
d„Z	eeddœdd„Z
dS )r3   zDummy experiment.N)r   Úkwr   c                 O   s   d S r1   r   )r   r   r7   r   r   r   Únop}   s    z_DummyExperiment.nop)Ú_r   c                 C   s   | j S r1   )r8   )r   r9   r   r   r   Ú__getattr__€   s    z_DummyExperiment.__getattr__)Úidxr   c                 C   s   | S r1   r   )r   r;   r   r   r   Ú__getitem__ƒ   s    z_DummyExperiment.__getitem__)r   r    r   c                 O   s   d S r1   r   )r   r   r    r   r   r   Ú__setitem__‡   s    z_DummyExperiment.__setitem__)r(   r)   r*   r+   r   r8   r   r:   r.   r<   r=   r   r   r   r   r3   z   s
   r3   N)r+   Úabcr   r   Úargparser   Ú	functoolsr   Útypingr   r   r   r	   r
   Ztorchr   Ztorch.nnr   Z$lightning_fabric.utilities.rank_zeror   r   r6   r3   r   r   r   r   Ú<module>   s   G