
      i'                        d Z ddlm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 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ddeeeef      deeeef      deeeef      deeeef      deeef   deeef   deeeeeee f      deddfdZ!deeeef      dedeeef   fdZ"dddeeeef      ddfdZ#ddZ$deeee f   defdZ%y) z.Houses the methods used to set up the Trainer.    )	timedelta)OptionalUnionN)PossibleUserWarning)CUDAAcceleratorMPSAcceleratorXLAAccelerator)DummyLogger)AdvancedProfilerPassThroughProfilerProfilerPyTorchProfilerSimpleProfilerXLAProfiler)MisconfigurationException)rank_zero_inforank_zero_warntrainer
pl.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	                 D   t        |t              r|dk  rt        d|d      || _        |dk(  rd| _        t	        |d      | _        |dkD  }	|rt        |      }
|	s|
| _        |
| _        |
| _        |
| _	        |
| j                  j                  _        d| _        d| j                  _        d| _        d | _        d| _        | j$                  rt'               gng | _        t)        d|
 d	       n|	s"t	        |d
      | _        t	        |d      | _        t	        |d      | _        t	        |d      | _	        |dk(  rt+        d      n|| _        d | _        t        |t,        t.        t0        f      rt3        |      | _        nt	        |d      | _        |	r|| _        || _        y y )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   fit_loop
epoch_loop	max_stepsr   
max_epochsr   _val_check_time_intervalcheck_val_every_n_epochloggersr
   r   floatstrdictr   _parse_time_interval_seconds)r   r   r   r   r   r   r   r   r   overfit_batches_enablednum_batchess              t/Volumes/fast/ai/experiments/voice-extract-mac/.venv/lib/python3.12/site-packages/pytorch_lightning/trainer/setup.py_init_debugging_flagsr5   #   s    ,$,*:'L++\]
 	
 (G q#5oGXYG-1,'&*5G'(3G%%0"(3%0;##-'($&'#%("+/(*+'-4__;=/"PQ\P] ^7 7	

 '*ABUWl*mG'(?@QSf(gG%%<=OQe%f"(?@UWn(o%7Kr7QuU|Wk$ ,0((3i*@A/KL^/_G,)@ASUi)jG&&5#$3!     batchesnamec                 \   | yt        | t              r)| dk(  r$|dk(  rd}n
|dk(  rd}nd}t        d| d	|        n9t        | t              r)| dk(  r$|dk(  rd
}n
|dk(  rd}nd}t        d| d| d       d| cxk  rdk  r| S  | dkD  r| dz  dk(  rt        |       S t	        d|  d| d      )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   )r7   r8   messages      r4   r&   r&   d   s      '3GqL((7G))>G-G4&(?yIJ	GU	#3((CG))MG9G4&(A'!LMGq {w})7|
#
(	tf<cd r6   profilerc                    t        |t              r\t        t        t        t
        d}|j                         }||vr%t        dt        |j                                      ||   } |       }|xs
 t               | _        y )N)simpleadvancedpytorchxlaz[When passing string value for the `profiler` parameter of `Trainer`, it can only be one of )r$   r/   r   r   r   r   lowerr   listkeysr   r<   )r   r<   	PROFILERSprofiler_classs       r4   _init_profilerrG      s    (C $(&	
	 >>#9$+**.y~~/?*@)AC  #8,!#8#6#8Gr6   c                    t        j                         rd}d}nt        j                         rd}d}nd}d}t        | j                  t         t        f      }t        d| | d|        t        | j                  t              r| j                  nd}t        d	t        j                          d
| d       t        j                         rt        | j                  t               r.t        j                         r+t        | j                  t              st        dt               t        j                         r't        | j                  t              st        d       y y y )NTz (cuda)z (mps)F zGPU available: z, used: r   zTPU available: z	, using: z
 TPU coreszQGPU available but not used. You can set it by doing `Trainer(accelerator='gpu')`.)categoryzQTPU available but not used. You can set it by doing `Trainer(accelerator='tpu')`.)
r   is_availabler   r$   acceleratorr   r	   num_devicesr   r   )r   gpu_availablegpu_typegpu_usednum_tpu_coress        r4   _log_device_inforR      s   ##%		$	$	&'--/PQH_]OH:XhZPQ+5g6I6I>+ZG''`aM_^%@%@%B$C9]O[efg 	$$&7..@&&(7..?_(	

 ""$Z8K8K^-\jk .]$r6   valuec                     t        | t              r| j                         S t        | t              rt        d	i | }|j                         S t        | t              r| j                  d      }t        |      dk7  rt        d| d      |\  }}}}	 t        |      }t        |      }t        |      }	t        |      }
t        |||	|
      }|j                         S t        dt        |             # t        $ r t        d| d      w xY w)
a]  Convert a time interval into seconds.

    This helper parses different representations of a time interval and
    normalizes them into a float number of seconds.

    Supported input formats:
      * `timedelta`: The total seconds are returned directly.
      * `dict`: A dictionary of keyword arguments accepted by
        `datetime.timedelta`, e.g. `{"days": 1, "hours": 2}`.
      * `str`: A string in the format `"DD:HH:MM:SS"`, where each
        component must be an integer.

    Args:
        value (Union[str, timedelta, dict]): The time interval to parse.

    Returns:
        float: The duration represented by `value` in seconds.

    Raises:
        MisconfigurationException: If the input type is unsupported, the
        string format is invalid, or any string component is not an integer.

    Examples:
        >>> _parse_time_interval_seconds("01:02:03:04")
        93784.0

        >>> _parse_time_interval_seconds({"hours": 2, "minutes": 30})
        9000.0

        >>> from datetime import timedelta
        >>> _parse_time_interval_seconds(timedelta(days=1, seconds=30))
        86430.0

    :   z.Invalid time format for `val_check_interval`: z. Expected 'DD:HH:MM:SS'.z6Non-integer component in `val_check_interval` string: z. Use 'DD:HH:MM:SS'.)dayshoursminutessecondsz+Unsupported type for `val_check_interval`:  )r$   r   total_secondsr0   r/   splitlenr   r%   
ValueErrortype)rS   tdpartsdhmsrW   rX   rY   rZ   s              r4   r1   r1      s    F %#""$$%!!%C u:?+@	Ibc  
1a	q6DFE!fG!fG
 DwP!!
#&QRVW\R]Q`$a
bb  	+H	Qef 	s   ,C4 4D)r   r   r   N)&__doc__datetimer   typingr   r   pytorch_lightningpl#lightning_fabric.utilities.warningsr   pytorch_lightning.acceleratorsr   r   r	    pytorch_lightning.loggers.loggerr
   pytorch_lightning.profilersr   r   r   r   r   r   &pytorch_lightning.utilities.exceptionsr   %pytorch_lightning.utilities.rank_zeror   r   r%   r.   boolr/   r0   r5   r&   rG   rR   r1   r[   r6   r4   <module>rs      s   5  "  C Z Z 8  M P>4>4!%U
"34>4  c5j 12>4 !sEz!23	>4
 $E#u*$56>4 T	">4 3:&>4 !sE3	4'G!HI>4 >4 
>4BXeCJ.?%@  PUVY[`V`Pa B9L 9HU8S==Q4R 9W[ 9&l@;cc9d.B(C ;c ;cr6   