Ë
    ÿÍ:j�Z  ã                   óæ  — d dl Z d dl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 d dlmZmZmZmZ d dlmZ d dl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 d dl m!Z!  G d„ de«      Z"de#de$fd„Z%de#dee&   fd„Z'de#dee   fd„Z(dedeeef   defd„Z)dedeeef   de*e*e   e+e,ef   f   fd„Z-dedeeef   de+e,ef   fd„Z.de#de&ddfd„Z/ddœdededee0   dedef
d „Z1d7d!ed"ee,   defd#„Z2d$ed%e"defd&„Z3e
d7d'e0d"ee,   ded(   fd)„«       Z4d*e,d+ede*ed,f   de+e,ef   d-e+e,ef   d.e*e,d,f   de*e$e*ed,f   e+e,ef   f   fd/„Z5de#d0e&ddfd1„Z6d2e&de&fd3„Z7de&fd4„Z8 G d5„ d6e+«      Z9y)8é    N)ÚOrderedDict)Ú	GeneratorÚIterableÚSized)Úcontextmanager)Úpartial)ÚAnyÚCallableÚOptionalÚUnion)Úget_all_subclasses)ÚBatchSamplerÚ
DataLoaderÚIterableDatasetÚSampler)Ú	TypeGuard)ÚLightningEnum)ÚMisconfigurationException)Úrank_zero_warn)Úpl_worker_init_functionc                   ó$   — e Zd ZdZdZdeddfd„Zy)Ú_WrapAttrTagÚsetÚdelÚargsÚreturnNc                 óB   — | | j                   k(  rt        nt        } ||Ž S ©N)ÚSETÚsetattrÚdelattr)Úselfr   Úfns      út/home/mcse/projects/srt_converter/srt-converter-venv/lib/python3.12/site-packages/lightning_fabric/utilities/data.pyÚ__call__z_WrapAttrTag.__call__&   s   € à §¡Ò(�W¬gˆÙ�4ˆyÐó    )Ú__name__Ú
__module__Ú__qualname__r   ÚDELr	   r%   © r&   r$   r   r   "   s   „ Ø
€CØ
€Cð˜cð  dô r&   r   Ú
dataloaderr   c                 óR   — t        | d«      xr t        | j                  t        «      S )NÚdataset)ÚhasattrÚ
isinstancer.   r   )r,   s    r$   Úhas_iterable_datasetr1   ,   s!   € Ü�:˜yÓ)Ò]¬j¸×9KÑ9KÌ_Ó.]Ð]r&   c                 óN   — 	 t        | «      }|S # t        t        f$ r d}Y |S w xY w)z>Try to get the length of an object, return ``None`` otherwise.N)ÚlenÚ	TypeErrorÚNotImplementedError©r,   Úlengths     r$   Ú	sized_lenr8   0   s8   € ðä�Z“ˆð €Møô Ô*Ð+ò Ø‰Ø€Mðús   ‚ �$£$c                 ó    — t        | «      }|dk(  r#t        d| j                  j                  › d�«       |�t	        | «      rt        d«       |duS )z<Checks if a given object has ``__len__`` method implemented.r   ú`z>` returned 0 length. Please make sure this was your intention.NzáYour `IterableDataset` has `__len__` defined. In combination with multi-process data loading (when num_workers > 1), `__len__` could be inaccurate if each worker is not configured independently to avoid having duplicate data.)r8   r   Ú	__class__r'   r1   r6   s     r$   Úhas_lenr<   :   s_   € ä�zÓ"€FØ�‚{ÜØ�
×$Ñ$×-Ñ-Ð.Ð.lÐmô	
ð ÐÔ2°:Ô>Üð/ô	
ð ˜ÐÐr&   Úsamplerc                 ó>   — t        | |«      \  }}t        | g|¢­i |¤ŽS r   )Ú$_get_dataloader_init_args_and_kwargsÚ_reinstantiate_wrapped_cls)r,   r=   Údl_argsÚ	dl_kwargss       r$   Ú_update_dataloaderrC   K   s(   € Ü=¸jÈ'ÓRÑ€GˆYÜ% jÐH°7ÒH¸iÑHÐHr&   c                 ó¾  — t        | t        «      st        d| › d�«      ‚t        | d«      }|r1| j                  }| j
                  }| j                  }| j                  }nQt        | «      j                  «       D ��ci c]  \  }}|j                  d«      rŒ||“Œ }	}}d }| j                  |	d<   d}t        t        j                  | j                  «      j                   «      }
t#        d„ |
j%                  «       D «       «      }|rÈ|rx|
j'                  t        j                  t        j                  «      j                   j                  «       D ��ci c]!  \  }}|j(                  |j*                  usŒ||“Œ# c}}«       nN|
j'                  t        j                  t        j                  «      j                   «       |
j-                  dd «       |st|
j                  «       D ��ch c]  \  }}|	v sŒ|j(                  |	|   usŒ|’Œ  }}}|j/                  d	«       	j                  «       D ��ci c]  \  }}||v sŒ||“Œ }}}d}j1                  d	|«      }t        |t2        «      rd |d
<   d |d<   n|j'                  t5        | |«      «       |
j%                  «       D �ch c]f  }|j6                  |j8                  |j:                  fv r@|j(                  |j*                  u r(|j<                  |vr|j<                  |vr|j<                  ’Œh }}|rQt?        |«      }| j@                  jB                  }djE                  d„ |D «       «      }tG        d|› d|› d|› d|› d�	«      ‚|s`tI        |«      tI        |«      z  |
jK                  «       z
  }|r6t?        |«      }| j@                  jB                  }tM        d|› d|› d|› d�«      ‚|fS c c}}w c c}}w c c}}w c c}}w c c}w )NzThe dataloader z0 needs to subclass `torch.utils.data.DataLoader`Ú__pl_saved_argsÚ_Úmultiprocessing_contextr+   c              3   óL   K  — | ]  }|j                   |j                  u –— Œ y ­wr   )ÚkindÚVAR_KEYWORD)Ú.0Úps     r$   ú	<genexpr>z7_get_dataloader_init_args_and_kwargs.<locals>.<genexpr>i   s   è ø€ ÒO¸!˜aŸf™f¨¯©Ô5ÑOùs   ‚"$r"   r.   Úbatch_samplerr=   z, c              3   ó(   K  — | ]
  }d |› d�–— Œ y­w)z`self.r:   Nr+   )rK   Úarg_names     r$   rM   z7_get_dataloader_init_args_and_kwargs.<locals>.<genexpr>”   s   è ø€ Ò(cÀ(¨6°(°¸1Ô)=Ñ(cùs   ‚z,Trying to inject custom `Sampler` into the `z…` instance. This would fail as some of the `__init__` arguments are not available as instance attributes. The missing attributes are z. If you instantiate your `zZ` inside a `*_dataloader` hook of your module, we will do this for you. Otherwise, define z inside your `__init__`.z&Trying to inject parameters into the `z{` instance. This would fail as it doesn't expose all its attributes in the `__init__` signature. The missing arguments are z. HINT: If you wrote the `zA` class, add the `__init__` arguments or allow passing `**kwargs`)'r0   r   Ú
ValueErrorr/   rE   Ú__pl_saved_kwargsÚ__pl_saved_arg_namesÚ	__datasetÚvarsÚitemsÚ
startswithrG   ÚdictÚinspectÚ	signatureÚ__init__Ú
parametersÚanyÚvaluesÚupdateÚdefaultÚemptyÚpopÚaddÚgetr   Ú'_dataloader_init_kwargs_resolve_samplerrI   ÚPOSITIONAL_ONLYÚPOSITIONAL_OR_KEYWORDÚnameÚsortedr;   r'   Újoinr   r   Úkeysr4   )r,   r=   Úwas_wrappedrA   rB   Ú	arg_namesÚoriginal_datasetÚkÚvÚattrsÚparamsÚhas_variadic_kwargsrh   rL   Únon_defaultsr.   Úrequired_argsÚsorted_required_argsÚdataloader_cls_nameÚmissing_args_messageÚmissing_kwargsÚsorted_missing_kwargss                         r$   r?   r?   P   sÎ  € ô �j¤*Ô-Ü˜?¨:¨,Ð6fÐgÓhÐhä˜*Ð&7Ó8€KÙØ×,Ñ,ˆØ×0Ñ0ˆ	Ø×3Ñ3ˆ	Ø%×/Ñ/Ñô #' zÓ"2×"8Ñ"8Ó":×T™$˜!˜QÀ!Ç,Á,ÈsÕBS��A‘ÐTˆÑTð  Ðà+5×+MÑ+MˆÐ'Ñ(Øˆ	ô ”'×#Ñ# J×$7Ñ$7Ó8×CÑCÓD€FÜÑO¸v¿}¹}»ÔOÓOÐÙñ ð �M‰MÜ!(×!2Ñ!2´:×3FÑ3FÓ!G×!RÑ!R×!XÑ!XÓ!Z÷Ù˜˜AÐ^_×^gÑ^gÐop×ovÑovÒ^v��1‘óõ ð �M‰Mœ'×+Ñ+¬J×,?Ñ,?Ó@×KÑKÔLØ�J‰J�v˜tÔ$áà,2¯L©L«N×m¡  q¸dÀeºmÐPQ×PYÑPYÐafÐgkÑalÒPlšÐmˆÑmð 	×Ñ˜Ô#à&+§k¡k£m×I™d˜a °q¸LÒ7H�Q˜‘TÐIˆ	ÑIØˆà�m‰m˜IÐ'7Ó8€GÜ�'œ?Ô+Ø%)ˆ	�/Ñ"Ø#ˆ	�)Òà×ÑÔ@ÀÈWÓUÔVð —‘“öàØ�6‰6�a×'Ñ'¨×)@Ñ)@ÐAÑAØ�I‰I˜Ÿ™Ñ Ø�F‰F˜)Ñ#Ø�F‰F˜)Ñ#ð 	
�‹ð€Mð ñ Ü% mÓ4ÐØ(×2Ñ2×;Ñ;ÐØ#Ÿy™yÑ(cÐNbÔ(cÓcÐÜ'Ø:Ð;NÐ:Oð P*à*>Ð)?Ð?ZÐ[nÐZoð p"à"6Ð!7Ð7Oð	Qó
ð 	
ñ ä˜i›.¬3¨y«>Ñ9¸V¿[¹[»]ÑJˆÙÜ$*¨>Ó$:Ð!Ø",×"6Ñ"6×"?Ñ"?ÐÜØ8Ð9LÐ8Mð N-à-BÐ,CÐC]Ð^qÐ]rð sRðRóð ð �IÐÐùóW Uùó"ùó nùó
 Jùòs=   Á;OÂOÅ O
Å0O
Ç!OÇ.OÈ OÈ+OÈ8OÊA+Oc                 ón  — t        | d«      }|�ãt        |«      t        urÒt        |«      }t        |d«      ro|j                  }|j
                  }|j                  }|j                  }t        d|||||«      \  }}}|st        d|j                  › d�«      ‚t        |g|¢­i |¤Ž}nDt        |d«      r-t        |d«      r!	  |||j                  |j                  ¬	«      }nt        d«      ‚dd|dddœS |dddœS # t        $ r3}	d
dl}
|
j                  dt!        |	«      «      }|s‚ t        d«      |	‚d}	~	ww xY w)z‚This function is used to handle the sampler, batch_sampler arguments associated within a DataLoader for its re-
    instantiation.rN   NrE   r=   zYTrying to inject a modified sampler into the batch sampler; however, it seems the class `z‹` does not have an argument called `sampler.` To mitigate this, expose an argument `sampler` in the `__init__` method of your custom class.Ú
batch_sizeÚ	drop_last)r|   r}   r   z:.*__init__\(\) (got multiple values)|(missing \d required)ak   Lightning can't inject a (distributed) sampler into your batch sampler, because it doesn't subclass PyTorch's `BatchSampler`. To mitigate this, either follow the API of `BatchSampler` or set`.setup_dataloaders(..., use_distributed_sampler=False)`. If you choose the latter, you will be responsible for handling the distributed sampling within your batch sampler.Fé   )r=   ÚshufflerN   r|   r}   )r=   r   rN   )ÚgetattrÚtyper   r/   rE   rR   Ú__pl_saved_default_kwargsrS   Ú_replace_value_in_saved_argsr4   r)   r@   r|   r}   ÚreÚmatchÚstr)r,   r=   rN   Úbatch_sampler_clsr   ÚkwargsÚdefault_kwargsrm   ÚsuccessÚexr„   r…   s               r$   re   re   ­   s‹  € ô ˜J¨Ó8€MàÐ ¤T¨-Ó%8ÄÑ%LÜ  Ó/ÐÜ�=Ð"3Ô4à ×0Ñ0ˆDØ"×4Ñ4ˆFØ*×DÑDˆNØ%×:Ñ:ˆIä$@Ø˜7 D¨&°.À)ó%Ñ!ˆG�T˜6ñ ÜðØ)×6Ñ6Ð7ð 8hðhóð ô 7°}ÐVÀtÒVÈvÑV‰MÜ�] LÔ1´g¸mÈ[Ô6YðÙ 1ØØ,×7Ñ7Ø+×5Ñ5ô!‘ô. ðhóð ð ØØ*ØØñ
ð 	
ð ¨5À4ÑHÐHøôC ò ÛàŸ™Ð!^Ô`cÐdfÓ`gÓh�Ùàô  ðlóð
 ðûðús   Â?C8 Ã8	D4Ä.D/Ä/D4Úrankc                 ó¸   — t        | d«      sy t        t        j                  j	                  dd«      «      r$| j
                  €t        t        |¬«      | _        y y y )NÚworker_init_fnÚPL_SEED_WORKERSr   )rŒ   )r/   ÚintÚosÚenvironrd   rŽ   r   r   )r,   rŒ   s     r$   Ú_auto_add_worker_init_fnr“   ö   sL   € Ü�:Ð/Ô0ØÜ
Œ2�:‰:�>‰>Ð+¨QÓ/Ô0°Z×5NÑ5NÐ5VÜ$+Ô,CÈ$Ô$Oˆ
Õ!ð 6WÐ0r&   )Úexplicit_clsÚorig_objectr   r”   rˆ   c          
      óL  — |€t        | «      n|}	  ||i |¤Ž}t        | dg «      }|D ]  \  }} ||g|¢­Ž  Œ |S # t        $ r_}dd l}|j                  dt	        |«      «      }|s‚ |j                  «       d   }	d|j                  › d|	› d|	› d|	› d�	}
t        |
«      |‚d }~ww xY w)	Nr   z-.*__init__\(\) got multiple values .* '(\w+)'zThe zd implementation has an error where more than one `__init__` argument can be passed to its parent's `zr=...` `__init__` argument. This is likely caused by allowing passing both a custom argument that will map to the `zc` argument as well as `**kwargs`. `kwargs` should be filtered to make sure they don't contain the `zR` key. This argument was automatically passed to your object by PyTorch Lightning.Ú__pl_attrs_record)	r�   r4   r„   r…   r†   Úgroupsr'   r   r€   )r•   r”   r   rˆ   ÚconstructorÚresultr‹   r„   r…   ÚargumentÚmessageÚattrs_recordr#   s                r$   r@   r@   ý   sò   € Ø'3Ð';”$�{Ô#À€Kð9Ù˜dÐ- fÑ-ˆô( ˜;Ð(;¸RÓ@€LØ ò ‰ˆˆbÙ
ˆ6Ð�DÔðð €Møô/ ò 9ó 	à—‘ÐIÌ3ÈrË7ÓSˆÙàØ—<‘<“> !Ñ$ˆà�;×'Ñ'Ð(ð )/Ø/7¨jð 9EØEMÀJð OQØQYÐPZð [[ð[ð 	ô (¨Ó0°bÐ8ûð#9ús   ‘; »	B#ÁABÂB#ÚinitÚstore_explicit_argc           	      óp   ‡ ‡— t        j                  ‰ «      dt        dt        dt        ddfˆ ˆfd„«       }|S )zÄWraps the ``__init__`` method of classes (currently :class:`~torch.utils.data.DataLoader` and
    :class:`~torch.utils.data.BatchSampler`) in order to enable re-instantiation of custom subclasses.Úobjr   rˆ   r   Nc                 óT  •— t        | dd«      }t        j                  | dd«       t        j                  ‰
«      j
                  }t        d„ |j                  «       D «       «      }t        |«      d t        |«       }|j                  «       D ��ci c]-  \  }}||vr$||vr |t        j                  j                  k7  r||“Œ/ }	}}t        | d«      s\t        j                  | d|«       t        j                  | d|«       t        j                  | d|«       t        j                  | d|	«       ‰�R‰|v r-t        j                  | d	‰› �||j                  ‰«         «       n!‰|v rt        j                  | d	‰› �|‰   «        ‰
| g|¢­i |¤Ž t        j                  | d|«       y c c}}w )
NÚ__pl_inside_initFTc              3   ó²   K  — | ]O  }|j                   d k7  r>|j                  |j                  |j                  fvr|j                   |j                  f–— ŒQ y­w)r"   N)rh   rI   ÚVAR_POSITIONALrJ   r`   )rK   Úparams     r$   rM   z5_wrap_init_method.<locals>.wrapper.<locals>.<genexpr>(  sN   è ø€ ò *
àØ�z‰z˜VÒ#¨¯
©
¸5×;OÑ;OÐQV×QbÑQbÐ:cÑ(cð �Z‰Z˜Ÿ™Ô'ñ*
ùs   ‚AArE   rR   rS   r‚   Ú__)r€   ÚobjectÚ__setattr__rY   rZ   r\   r   r^   Útupler3   rV   Ú	Parameterra   r/   Úindex)r¡   r   rˆ   Úold_inside_initrr   Úparameters_defaultsÚparam_namesrh   Úvaluer‰   rž   rŸ   s             €€r$   Úwrapperz"_wrap_init_method.<locals>.wrapper   s­  ø€ ô " #Ð'9¸5ÓAˆÜ×Ñ˜3Ð 2°DÔ9Ü×"Ñ" 4Ó(×3Ñ3ˆä)ñ *
àŸ™›ô*
ó 
Ðô Ð/Ó0°´3°t³9Ð=ˆð  3×8Ñ8Ó:÷
á��eØ˜6Ñ! d°+Ñ&=À%Ì7×K\ÑK\×KbÑKbÒBbð �%‰Kð
ˆñ 
ô �sÐ-Ô.Ü×Ñ˜sÐ$5°tÔ<Ü×Ñ˜sÐ$7¸Ô@Ü×Ñ˜sÐ$:¸KÔHÜ×Ñ˜sÐ$?ÀÔPð
 Ð)Ø! [Ñ0Ü×"Ñ" 3¨"Ð-?Ð,@Ð(AÀ4È×HYÑHYÐZlÓHmÑCnÕoØ# vÑ-Ü×"Ñ" 3¨"Ð-?Ð,@Ð(AÀ6ÐJ\ÑC]Ô^áˆSÐ"�4Ò"˜6Ò"Ü×Ñ˜3Ð 2°OÕDùó-
s   Â2F$©Ú	functoolsÚwrapsr	   )rž   rŸ   r±   s   `` r$   Ú_wrap_init_methodrµ     sJ   ù€ ô ‡_�_�TÓð%E”Sð %E¤ð %E´ð %E¸õ %Eó ð%EðN €Nr&   ÚmethodÚtagc                 ód   ‡ ‡— t        j                  ‰ «      dt        dt        ddfˆ ˆfd„«       }|S )zÛWraps the ``__setattr__`` or ``__delattr__`` method of classes (currently :class:`~torch.utils.data.DataLoader`
    and :class:`~torch.utils.data.BatchSampler`) in order to enable re- instantiation of custom subclasses.r¡   r   r   Nc                 óJ  •— |^}}t        | dd«      \  }}||k(  xr |‰	k(   }t        j                  | d|‰	f«        ‰| g|¢­Ž  |rDt        | dd«      s7t        | dg «      }|j                  |‰	f«       t        j                  | d|«       t        j                  | d||f«       y )NÚ__pl_current_call)Nr¶   r£   Tr—   )r€   r¨   r©   Úappend)
r¡   r   rh   rF   Úprev_call_nameÚprev_call_methodÚ
first_callr�   r¶   r·   s
           €€r$   r±   z"_wrap_attr_method.<locals>.wrapperO  sÂ   ø€ ð ˆˆˆqÜ+2°3Ð8KÐM]Ó+^Ñ(ˆÐ(Ø(¨DÑ0ÒLÐ5EÈÑ5LÐMˆ
ô 	×Ñ˜3Ð 3°d¸C°[ÔAñ 	ˆsÐ�TÓÙœg cÐ+=¸tÔDô # 3Ð(;¸RÓ@ˆLØ×Ñ  s Ô,Ü×Ñ˜sÐ$7¸ÔFÜ×Ñ˜3Ð 3°nÐFVÐ5WÕXr&   r²   )r¶   r·   r±   s   `` r$   Ú_wrap_attr_methodr¿   K  sA   ù€ ô ‡_�_�VÓðY”Sð Y¤ð Y¨õ Yó ðYð& €Nr&   Úbase_cls)NNNc              #   ó>  K  — t        | «      | hz  }|D ]¸  }d|j                  v r,|j                  |_        t	        |j                  |«      |_        dt
        j                  fdt
        j                  ffD ]U  \  }}||j                  v s|| u sŒd|› �}t        ||t        ||«      «       t        ||t        t        ||«      |«      «       ŒW Œº d–— |D ]D  }dD ]=  }d|› �|j                  v sŒt        ||t        |d|› �«      «       t        |d|› �«       Œ? ŒF y­w)z»This context manager is used to add support for re-instantiation of custom (subclasses) of `base_cls`.

    It patches the ``__init__``, ``__setattr__`` and ``__delattr__`` methods.

    r[   r©   Ú__delattr__Ú__oldN)r©   rÂ   r[   )r   Ú__dict__r[   Ú__old__init__rµ   r   r   r*   r    r€   r¿   r!   )rÀ   rŸ   ÚclassesÚclsÚpatch_fn_namer·   Ú
saved_nameÚpatched_names           r$   Ú_replace_dunder_methodsrË   f  s;  è ø€ ô ! Ó*¨h¨ZÑ7€GØò aˆð ˜Ÿ™Ñ%Ø #§¡ˆCÔÜ,¨S¯\©\Ð;MÓNˆCŒLð %2´<×3CÑ3CÐ#DÀ}ÔVb×VfÑVfÐFgÐ"hò 	aÑˆM˜3Ø §¡Ñ,°°x²Ø$ ] OÐ4�
Ü˜˜Z¬°°mÓ)DÔEÜ˜˜]Ô,=¼gÀcÈ=Ó>YÐ[^Ó,_Õ`ñ		aðaó 
Øò 5ˆØFò 	5ˆLð �|�nÐ%¨¯©Ò5Ü˜˜\¬7°3¸%À¸~Ð8NÓ+OÔPÜ˜˜u \ NÐ3Õ4ñ	5ñ5ùs   ‚BDÂA DÃ/.DÚreplace_keyÚreplace_value.r‰   rm   c                 óˆ   — | |v r(|j                  | «      }|d| |fz   ||dz   d z   }d||fS | |v s| |v r
||| <   d||fS d||fS )z¨Tries to replace an argument value in a saved list of args and kwargs.

    Returns a tuple indicating success of the operation and modified saved args and kwargs

    Nr~   TF)r¬   )rÌ   rÍ   r   rˆ   r‰   rm   Úreplace_indexs          r$   rƒ   rƒ   †  s€   € ð �iÑØ!Ÿ™¨Ó4ˆØ�N�]Ð# }Ð&6Ñ6¸¸mÈaÑ>OÐ>QÐ9RÑRˆØ�T˜6Ð!Ð!Ø�fÑ ¨~Ñ =Ø+ˆˆ{ÑØ�T˜6Ð!Ð!à�$˜ÐÐr&   Úepochc                 ó  — i }t        | dd«      x}�||t        |«      <   t        | dd«      x}�t        |dd«      x}	 �||t        |«      <   |j                  «       D ]#  }t        |dd«      }t        |«      sŒ ||«       Œ% y)a�  Calls the ``set_epoch`` method on either the sampler of the given dataloader.

    Every PyTorch dataloader has either a sampler or a batch sampler. If the sampler is wrapped by a
    :class:`~torch.utils.data.distributed.DistributedSampler`, ``set_epoch`` must be called at the beginning
    of every epoch to ensure shuffling applies a new ordering. This has no effect if shuffling is off.

    r=   NrN   Ú	set_epoch)r€   Úidr^   Úcallable)r,   rÐ   Úobjectsr=   rN   r¡   rÒ   s          r$   Ú_set_sampler_epochrÖ   Ÿ  s�   € ð !€Gä˜: y°$Ó7Ð7ˆÐDØ&ˆ”�7“Ñä  ¨_¸dÓCÐCˆÐPÜ˜=¨)°TÓ:Ð:ˆØðVð  'ˆ”�7“ÑØ�~‰~Óò ˆÜ˜C ¨dÓ3ˆ	Ü�IÕÙ�eÕñr&   Úlocal_world_sizec                 ób   — | dk  rt        d| › d�«      ‚t        «       }t        d|| z  dz
  «      S )aœ  Suggests an upper bound of ``num_workers`` to use in a PyTorch :class:`~torch.utils.data.DataLoader` based on
    the number of CPU cores available on the system and the number of distributed processes in the current machine.

    Args:
        local_world_size: The number of distributed processes running on the current machine. Set this to the number
            of devices configured in Fabric/Trainer.

    r~   z'`local_world_size` should be >= 1, got ú.)rQ   Ú_num_cpus_availableÚmax)r×   Ú	cpu_counts     r$   Úsuggested_max_num_workersrÝ   ·  sD   € ð ˜!ÒÜÐBÐCSÐBTÐTUÐVÓWÐWÜ#Ó%€IÜˆq�)Ð/Ñ/°!Ñ3Ó4Ð4r&   c                  ó’   — t        t        d«      rt        t        j                  d«      «      S t        j                  «       } | €dS | S )NÚsched_getaffinityr   r~   )r/   r‘   r3   rß   rÜ   )rÜ   s    r$   rÚ   rÚ   Æ  s>   € ÜŒrÐ&Ô'Ü”2×'Ñ'¨Ó*Ó+Ð+ä—‘“€IØÐ!ˆ1Ð0 yÐ0r&   c                   óP   — e Zd ZdZdedefd„Zdededdfd„Zdeddfd	„Zdefd
„Z	y)ÚAttributeDicta  A container to store state variables of your program.

    This is a drop-in replacement for a Python dictionary, with the additional functionality to access and modify keys
    through attribute lookup for convenience.

    Use this to define the state of your program, then pass it to
    :meth:`~lightning_fabric.fabric.Fabric.save` and :meth:`~lightning_fabric.fabric.Fabric.load`.

    Example:
        >>> import torch
        >>> model = torch.nn.Linear(2, 2)
        >>> state = AttributeDict(model=model, iter_num=0)
        >>> state.model
        Linear(in_features=2, out_features=2, bias=True)
        >>> state.iter_num += 1
        >>> state.iter_num
        1
        >>> state
        "iter_num": 1
        "model":    Linear(in_features=2, out_features=2, bias=True)

    Úkeyr   c                 ó|   — 	 | |   S # t         $ r+}t        dt        | «      j                  › d|› d�«      |‚d }~ww xY w)Nú'z' object has no attribute ')ÚKeyErrorÚAttributeErrorr�   r'   )r"   râ   Úes      r$   Ú__getattr__zAttributeDict.__getattr__æ  sP   € ð	dØ˜‘9ÐøÜò 	dÜ  1¤T¨$£Z×%8Ñ%8Ð$9Ð9TÐUXÐTYÐYZÐ![Ó\ÐbcÐcûð	dús   ‚ ‡	;�&6¶;ÚvalNc                 ó   — || |<   y r   r+   )r"   râ   ré   s      r$   r©   zAttributeDict.__setattr__ì  s   € ØˆˆSŠ	r&   Úitemc                 ó(   — || vrt        |«      ‚| |= y r   )rå   )r"   rë   s     r$   rÂ   zAttributeDict.__delattr__ï  s   € Ø�tÑÜ˜4“.Ð Ø�‰Jr&   c                 ó  — t        | «      syt        d„ | D «       «      }dt        |dz   «      z   dz   }t        | j	                  «       «      D �cg c]  }|j                  d|› d�| |   «      ‘Œ }}dj                  |«      S c c}w )	NÚ c              3   óD   K  — | ]  }t        t        |«      «      –— Œ y ­wr   )r3   r†   )rK   ro   s     r$   rM   z)AttributeDict.__repr__.<locals>.<genexpr>÷  s   è ø€ Ò7¨QœS¤ Q£Ÿ[Ñ7ùs   ‚ z{:é   zs} {}ú"z":ú
)r3   rÛ   r†   ri   rk   Úformatrj   )r"   Úmax_key_lengthÚtmp_nameÚnÚrowss        r$   Ú__repr__zAttributeDict.__repr__ô  s~   € Ü�4ŒyØÜÑ7°$Ô7Ó7ˆØœ#˜n¨qÑ0Ó1Ñ1°GÑ;ˆÜ=CÀDÇIÁIÃKÓ=PÖQ¸�—‘ ! A 3 b 	¨4°©7Õ3ÐQˆÐQØ�y‰y˜‹Ðùò Rs   Á B)
r'   r(   r)   Ú__doc__r†   r	   rè   r©   rÂ   rø   r+   r&   r$   rá   rá   Î  sV   „ ñð.d˜sð d só dð˜sð ¨ð °ó ð ð ¨ó ð
˜#ô r&   rá   r   ):r³   rY   r‘   Úcollectionsr   Úcollections.abcr   r   r   Ú
contextlibr   r   Útypingr	   r
   r   r   Ú$lightning_utilities.core.inheritancer   Útorch.utils.datar   r   r   r   Útyping_extensionsr   Ú lightning_fabric.utilities.enumsr   Ú%lightning_fabric.utilities.exceptionsr   Ú$lightning_fabric.utilities.rank_zeror   Úlightning_fabric.utilities.seedr   r   r¨   Úboolr1   r�   r8   r<   rC   rª   rX   r†   r?   re   r“   r�   r@   rµ   r¿   rË   rƒ   rÖ   rÝ   rÚ   rá   r+   r&   r$   ú<module>r     s¿  ðó Û Û 	Ý #ß 6Ñ 6Ý %Ý ß 1Ó 1å Cß OÓ OÝ 'å :Ý KÝ ?Ý Cô�=ô ð^ Vð ^°ó ^ð˜&ð  X¨c¡]ó ð˜ð  9¨UÑ#3ó ð"I :ð I¸¸gÀxÐ>OÑ8Pð IÐU_ó Ið
ZØðZà�7˜HÐ$Ñ%ðZð ˆ5�‰:�t˜C ˜H‘~Ð%Ñ&óZðzFIØðFIà�7˜HÐ$Ñ%ðFIð 
ˆ#ˆsˆ(�^óFIðRP¨ð P°sð P¸tó Pð ]aò ¨Cð ¸ð È8ÐTXÉ>ð Ðloð Ðtwó ñ>,˜Hð ,¸(À3¹-ð ,ÐS[ó ,ð^˜hð ¨\ð ¸hó ð6 ñ5 dð 5ÀÈÁð 5ÐYbÐcsÑYtò 5ó ð5ð>Øðàðð ��S�‰/ðð ��c�‰Nð	ð
 ˜˜c˜‘Nðð �S˜#�X‰ðð ˆ4��s˜C�x‘ $ s¨C x¡.Ð0Ñ1óð2 6ð °#ð ¸$ó ð05°ð 5¸ó 5ð1˜Só 1ô,�Dõ ,r&   