a
    d$                     @   s   d dl mZmZmZ d dlmZ eG dd dZeG dd deZeG dd deZeG d	d
 d
eZ	eG dd deZ
eG dd de
ZeG dd de
ZeG dd de
ZeG dd deZeG dd deZdS )    )asdict	dataclassfield)Typec                   @   sP   e Zd ZdZedddZeddddZeed dd	d
ZddddZ	dS )BaseProgressz>Mixin that implements state-loading utilities for dataclasses.returnc                 C   s   t | S N)r   self r   k/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/pytorch_lightning/trainer/progress.py
state_dict   s    zBaseProgress.state_dictNr   r   c                 C   s   | j | d S r	   )__dict__updater   r   r   r   r   load_state_dict   s    zBaseProgress.load_state_dictc                 C   s   |  }| | |S r	   )r   )clsr   objr   r   r   from_state_dict   s    
zBaseProgress.from_state_dictc                 C   s   t dS )zReset the object's state.N)NotImplementedErrorr
   r   r   r   reset"   s    zBaseProgress.reset)
__name__
__module____qualname____doc__dictr   r   classmethodr   r   r   r   r   r   r      s   r   c                   @   sF   e Zd ZU dZdZeed< dZeed< ddddZddd	d
Z	dS )ReadyCompletedTrackeraE  Track an event's progress.

    Args:
        ready: Intended to track the number of events ready to start.
        completed: Intended to be incremented after the event completes (e.g. after ``on_*_end`` runs).

    These attributes should be increased in order, that is, :attr:`ready` first and :attr:`completed` last.
    r   ready	completedNr   c                 C   s   d| _ d| _dS )zReset the state.r   N)r    r!   r
   r   r   r   r   5   s    zReadyCompletedTracker.resetc                 C   s   | j | _dS )zReset the progress on restart.

        If there is a failure before all attributes are increased, restore the attributes to the last fully completed
        value.
        N)r!   r    r
   r   r   r   reset_on_restart:   s    z&ReadyCompletedTracker.reset_on_restart)
r   r   r   r   r    int__annotations__r!   r   r"   r   r   r   r   r   '   s
   
	r   c                       sF   e Zd ZU dZdZeed< dd fddZdd fdd	Z  Z	S )
StartedTrackera  Track an event's progress.

    Args:
        ready: Intended to track the number of events ready to start.
        started: Intended to be incremented after the event is started (e.g. after ``on_*_start`` runs).
        completed: Intended to be incremented after the event completes (e.g. after ``on_*_end`` runs).

    These attributes should be increased in order, that is, :attr:`ready` first and :attr:`completed` last.
    r   startedNr   c                    s   t    d| _d S Nr   )superr   r&   r
   	__class__r   r   r   Q   s    
zStartedTracker.resetc                    s   t    | j| _d S r	   )r(   r"   r!   r&   r
   r)   r   r   r"   U   s    
zStartedTracker.reset_on_restart)
r   r   r   r   r&   r#   r$   r   r"   __classcell__r   r   r)   r   r%   C   s   

r%   c                       sF   e Zd ZU dZdZeed< dd fddZdd fdd	Z  Z	S )
ProcessedTrackera  Track an event's progress.

    Args:
        ready: Intended to track the number of events ready to start.
        started: Intended to be incremented after the event is started (e.g. after ``on_*_start`` runs).
        processed: Intended to be incremented after the event is processed.
        completed: Intended to be incremented after the event completes (e.g. after ``on_*_end`` runs).

    These attributes should be increased in order, that is, :attr:`ready` first and :attr:`completed` last.
    r   	processedNr   c                    s   t    d| _d S r'   )r(   r   r-   r
   r)   r   r   r   i   s    
zProcessedTracker.resetc                    s   t    | j| _d S r	   )r(   r"   r!   r-   r
   r)   r   r   r"   m   s    
z!ProcessedTracker.reset_on_restart)
r   r   r   r   r-   r#   r$   r   r"   r+   r   r   r)   r   r,   Z   s   
r,   c                   @   s   e Zd ZU dZeedZeed< eedZ	eed< ddddZ
ddd	d
ZddddZddddZddddZeee ed dddZddddZddddZddddZeddddZdS )ProgresszTrack aggregated and current progress.

    Args:
        total: Intended to track the total progress of an event.
        current: Intended to track the current progress of an event.
    default_factorytotalcurrentNr   c                 C   s    t | jt | jurtdd S )Nz?The `total` and `current` instances should be of the same class)typer1   r2   
ValueErrorr
   r   r   r   __post_init__~   s    zProgress.__post_init__c                 C   s$   | j  jd7  _| j jd7  _d S N   )r1   r    r2   r
   r   r   r   increment_ready   s    zProgress.increment_readyc                 C   sF   t | jts"td| jjj d| j jd7  _| j jd7  _d S )N`z$` doesn't have a `started` attributer7   )
isinstancer1   r%   	TypeErrorr*   r   r&   r2   r
   r   r   r   increment_started   s    zProgress.increment_startedc                 C   sF   t | jts"td| jjj d| j jd7  _| j jd7  _d S )Nr9   z&` doesn't have a `processed` attributer7   )r:   r1   r,   r;   r*   r   r-   r2   r
   r   r   r   increment_processed   s    zProgress.increment_processedc                 C   s$   | j  jd7  _| j jd7  _d S r6   )r1   r!   r2   r
   r   r   r   increment_completed   s    zProgress.increment_completed)tracker_clskwargsr   c                 K   s    | |f i ||f i |dS )zZUtility function to easily create an instance from keyword arguments to both ``Tracker``s.)r1   r2   r   )r   r?   r@   r   r   r   from_defaults   s    zProgress.from_defaultsc                 C   s   | j   | j  d S r	   )r1   r   r2   r
   r   r   r   r      s    
zProgress.resetc                 C   s   | j   d S r	   )r2   r   r
   r   r   r   reset_on_run   s    zProgress.reset_on_runc                 C   s   | j   d S r	   )r2   r"   r
   r   r   r   r"      s    zProgress.reset_on_restartr   c                 C   s$   | j |d  | j|d  d S )Nr1   r2   )r1   r   r2   r   r   r   r   r      s    zProgress.load_state_dict)r   r   r   r   r   r,   r1   r   r$   r2   r5   r8   r<   r=   r>   r   r   r#   rA   r   rB   r"   r   r   r   r   r   r   r.   r   s   
r.   c                   @   s6   e Zd ZU dZeedZeed< eedZeed< dS )DataLoaderProgressa  Tracks dataloader progress.

    These counters are local to a trainer rank. By default, they are not globally synced across all ranks.

    Args:
        total: Tracks the total dataloader progress.
        current: Tracks the current dataloader progress.
    r/   r1   r2   N	r   r   r   r   r   r   r1   r$   r2   r   r   r   r   rC      s   
	rC   c                       sZ   e Zd ZU dZdZeed< dd fddZdd fdd	Ze	dd
 fddZ
  ZS )BatchProgressaV  Tracks batch progress.

    These counters are local to a trainer rank. By default, they are not globally synced across all ranks.

    Args:
        total: Tracks the total batch progress.
        current: Tracks the current batch progress.
        is_last_batch: Whether the batch is the last one. This is useful for iterable datasets.
    Fis_last_batchNr   c                    s   t    d| _d S NF)r(   r   rF   r
   r)   r   r   r      s    
zBatchProgress.resetc                    s   t    d| _d S rG   )r(   rB   rF   r
   r)   r   r   rB      s    
zBatchProgress.reset_on_runr   c                    s   t  | |d | _d S )NrF   )r(   r   rF   r   r)   r   r   r      s    zBatchProgress.load_state_dict)r   r   r   r   rF   boolr$   r   rB   r   r   r+   r   r   r)   r   rE      s
   

rE   c                   @   s6   e Zd ZU dZeedZeed< eedZeed< dS )SchedulerProgressa  Tracks scheduler progress.

    These counters are local to a trainer rank. By default, they are not globally synced across all ranks.

    Args:
        total: Tracks the total scheduler progress.
        current: Tracks the current scheduler progress.
    r/   r1   r2   NrD   r   r   r   r   rI      s   
	rI   c                   @   sx   e Zd ZU dZedd dZeed< edd dZeed< dd	d
dZ	dd	ddZ
dd	ddZeddddZdS )OptimizerProgresszTrack optimizer progress.

    Args:
        step: Tracks ``optimizer.step`` calls.
        zero_grad: Tracks ``optimizer.zero_grad`` calls.
    c                   C   s
   t tS r	   )r.   rA   r   r   r   r   r   <lambda>       zOptimizerProgress.<lambda>r/   stepc                   C   s
   t tS r	   )r.   rA   r%   r   r   r   r   rK      rL   	zero_gradNr   c                 C   s   | j   | j  d S r	   )rM   r   rN   r
   r   r   r   r      s    
zOptimizerProgress.resetc                 C   s   | j   | j  d S r	   )rM   rB   rN   r
   r   r   r   rB      s    
zOptimizerProgress.reset_on_runc                 C   s   | j   | j  d S r	   )rM   r"   rN   r
   r   r   r   r"      s    
z"OptimizerProgress.reset_on_restartr   c                 C   s$   | j |d  | j|d  d S )NrM   rN   )rM   r   rN   r   r   r   r   r      s    z!OptimizerProgress.load_state_dict)r   r   r   r   r   rM   r.   r$   rN   r   rB   r"   r   r   r   r   r   r   rJ      s   
rJ   c                   @   s|   e Zd ZU dZeedZeed< dZe	ed< e
e	dddZd	dd
dZd	dddZd	dddZed	dddZd	S )OptimizationProgressa  Track optimization progress.

    Args:
        optimizer: Tracks optimizer progress.
        optimizer_position: The index of the current optimizer amongst the currently active optimizers.
            Used to know which optimizer we were using when restarting.
            Since not all optimizers may be active at a given time, this index is different from the ``optimizer_idx``
            seen in the optimization loops.
    r/   	optimizerr   optimizer_positionr   c                 C   s   | j jjjS r	   )rP   rM   r1   r!   r
   r   r   r   optimizer_steps  s    z$OptimizationProgress.optimizer_stepsNc                 C   s   | j   d| _d S r'   )rP   r   rQ   r
   r   r   r   r     s    
zOptimizationProgress.resetc                 C   s   | j   d| _d S r'   )rP   rB   rQ   r
   r   r   r   rB     s    
z!OptimizationProgress.reset_on_runc                 C   s   | j   d S r	   )rP   r"   r
   r   r   r   r"     s    z%OptimizationProgress.reset_on_restartr   c                 C   s   | j |d  |d | _d S )NrP   rQ   )rP   r   rQ   r   r   r   r   r     s    z$OptimizationProgress.load_state_dict)r   r   r   r   r   rJ   rP   r$   rQ   r#   propertyrR   r   rB   r"   r   r   r   r   r   r   rO      s   
rO   N)Zdataclassesr   r   r   typingr   r   r   r%   r,   r.   rC   rE   rI   rJ   rO   r   r   r   r   <module>   s*   7