a
    d"                     @   sh  d Z ddlmZmZ ddl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 dd	lmZmZmZmZmZmZ dd
lmZ ddlmZmZ deee e!f  eee e!f  eee e!f  eee e!f  ee e"f ee e!f eee e!f  e dd
ddZ#eee e!f  e$ee e!f dddZ%deeee$f  ddddZ&dddddZ'dS )z.Houses the methods used to set up the Trainer.    )OptionalUnionN)PossibleUserWarning)CUDAAcceleratorHPUAcceleratorIPUAcceleratorMPSAcceleratorTPUAccelerator)_HPU_AVAILABLE)_IPU_AVAILABLE)DummyLogger)AdvancedProfilerPassThroughProfilerProfilerPyTorchProfilerSimpleProfilerXLAProfiler)MisconfigurationException)rank_zero_inforank_zero_warnz
pl.Trainer)
trainerlimit_train_batcheslimit_val_batcheslimit_test_batcheslimit_predict_batchesfast_dev_runoverfit_batchesval_check_intervalnum_sanity_val_stepsreturnc	                 C   s&  t |tr"|dk r"td|d|| _|dkr6d| _t|d| _|dk}	|rt|}
|	sf|
| _|
| _|
| _|
| _	|
| j
_d| _d| j
_d| _d| _| jrt gng | _td|
 d	 nV|	st|d
| _t|d| _t|d| _t|d| _	|dkrtdn|| _t|d| _|	r"|| _|| _d S )Nr   zfast_dev_run=z1 is not a valid configuration. It should be >= 0.   Tr         ?zBRunning in `fast_dev_run` mode: will run the requested loop using z4 batch(es). Logging and checkpointing is suppressed.r   r   r   r   infr   )
isinstanceintr   r   _determine_batch_limitsr   r   r   r   r   Zfit_loopZ	max_stepsr   Z
max_epochsr   Zcheck_val_every_n_epochloggersr   r   float)r   r   r   r   r   r   r   r   r   Zoverfit_batches_enabledZnum_batches r)   h/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/pytorch_lightning/trainer/setup.py_init_debugging_flags*   sF    

r+   )batchesnamer   c                 C   s   | d u rdS t | trT| dkrT|dkr,d}n|dkr:d}nd}td| d	|  nHt | tr| dkr|dkrtd
}n|dkrd}nd}td| d| d d|   krdkrn n| S | dkr| d dkrt| S td|  d| dd S )Nr!   r    r   z1 batch per epoch will be used.r   z&validation will run after every batch.z1 batch will be used.z	`Trainer(z=1)` was configured so z+100% of the batches per epoch will be used.z5validation will run at the end of the training epoch.z!100% of the batches will be used.z=1.0)` was configured so .r   zYou have passed invalid value z for z', it has to be in [0.0, 1.0] or an int.)r$   r%   r   r(   r   )r,   r-   messager)   r)   r*   r&   c   s.    r&   )r   profilerr   c                 C   s\   t |trLttttd}| }||vr>tdt|	  || }| }|pTt
 | _d S )N)simpleZadvancedZpytorchZxlaz[When passing string value for the `profiler` parameter of `Trainer`, it can only be one of )r$   strr   r   r   r   lowerr   listkeysr   r0   )r   r0   Z	PROFILERSZprofiler_classr)   r)   r*   _init_profiler   s     

r6   )r   r   c                 C   s  t  rd}d}nt r$d}d}nd}d}t| jt tf}td| | d|  t| jtrf| jnd}td	t  d
| d t| jtr| jnd}tdt	 d
| d t| jt
r| jnd}tdt d
| d t  rt| jt stdt   dtd t r8t| jts8tdt  d t	r`t| jts`tdt  d trt| jt
stdt
  d t rt| jtstdt  d d S )NTz (cuda)z (mps)F zGPU available: z, used: r   zTPU available: z	, using: z
 TPU coreszIPU available: z IPUszHPU available: z HPUszfGPU available but not used. Set `accelerator` and `devices` using `Trainer(accelerator='gpu', devices=z)`.)categoryzfTPU available but not used. Set `accelerator` and `devices` using `Trainer(accelerator='tpu', devices=zfIPU available but not used. Set `accelerator` and `devices` using `Trainer(accelerator='ipu', devices=zfHPU available but not used. Set `accelerator` and `devices` using `Trainer(accelerator='hpu', devices=zfMPS available but not used. Set `accelerator` and `devices` using `Trainer(accelerator='mps', devices=)r   Zis_availabler   r$   Zacceleratorr   r	   Znum_devicesr   r   r   r
   r   Zauto_device_countr   )r   Zgpu_availableZgpu_typeZgpu_usedZnum_tpu_coresZnum_ipusZnum_hpusr)   r)   r*   _log_device_info   s^    r9   )(__doc__typingr   r   Zpytorch_lightningplZ#lightning_fabric.utilities.warningsr   Zpytorch_lightning.acceleratorsr   r   r   r   r	   Z"pytorch_lightning.accelerators.hpur
   Z"pytorch_lightning.accelerators.ipur   Z pytorch_lightning.loggers.loggerr   Zpytorch_lightning.profilersr   r   r   r   r   r   Z&pytorch_lightning.utilities.exceptionsr   Z%pytorch_lightning.utilities.rank_zeror   r   r%   r(   boolr+   r2   r&   r6   r9   r)   r)   r)   r*   <module>   s0    

9&!