Ë
      çiÆJ  ã            
       ó   — d dl Z d dlmZmZ d dlmZ d dlmZmZ d dl	m
Z
mZmZmZmZmZ d dl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 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# d dl$m%Z% d dl&m'Z' d dl(m)Z)m*Z*m+Z+m,Z, e
rd dl-m.Z.  ed«      Z/ ed«      Z0 e jb                  e2«      Z3 G d„ de«      Z4 G d„ de«      Z5 G d„ de«      Z6dee7   dee7   de8ddfd „Z9d!e7d"e:e7ee7ege8f   f   d#e;d$e:e7ef   ddf
d%„Z<y)&é    N)ÚABCÚabstractmethod)ÚIterable)ÚAbstractContextManagerÚ	ExitStack)ÚTYPE_CHECKINGÚAnyÚCallableÚOptionalÚTypeVarÚUnion)ÚTensor)ÚModule)Ú	Optimizer)Ú
DataLoader)ÚAccelerator)ÚCheckpointIO)ÚTorchCheckpointIO)Ú	Precision)Ú	_Launcher)Ú_StrategyRegistry)Úmove_data_to_device)Ú
_EmptyInit)Ú_PATHÚOptimizableÚReduceOpÚ	_Stateful)Ú_LRSchedulerÚ
TBroadcastÚTReducec                   óâ  — e Zd ZdZ	 	 	 dNdee   dee   dee   ddfd„Ze	e
dej                  fd„«       «       Ze	e
defd	„«       «       Ze	dee   fd
„«       Ze	dee   fd„«       Zej&                  deddfd„«       Ze	defd„«       Zej&                  deddfd„«       Ze	defd„«       Zej&                  dee   ddfd„«       ZdOd„ZdOd„Zdedefd„Zdefd„ZdPdee   defd„Z	 dPdedee   ded   de eee   ed   f   fd„Z!dedefd„Z"dedefd „Z#e
deddfd!„«       Z$dPd"e%d#eej                     de%fd$„Z&d%e'dee   d&e%d'e%ddf
d(„Z(de)d'e%de%fd)„Z*e
dQd%e'd*ee%   d+ede'fd,„«       Z+e
	 	 dRd%e,e'e%f   d*ee%   d-ee,e-e.f      de,e'e%f   fd.„«       Z/e
dPd/ee.   ddfd0„«       Z0e
dSd1e1d2e2de1fd3„«       Z3dTd4ed5edefd6„Z4	 	 dUd7e5d8e6e.e,eee%f   f   d9ee%   d:ee6e.e7e.e%gef   f      ddf
d;„Z8dede6e.e,e%e'f   f   fd<„Z9	 dTded=e6e.e,e%e'f   f   d>eddfd?„Z:dede6e.e'f   fd@„Z;	 	 	 dVd7e5d8ee,eee6e.e,eee%f   f   f      d>edAee   de6e.e%f   f
dB„Z<dOdC„Z=	 	 dWdej|                  j:                  dedDe,e?e2f   dEe,e?e2f   dFedejN                  fdG„Z@dej|                  j:                  dedHe,e?e2f   ddfdI„ZAeBdJeCddfdK„«       ZDde.fdL„ZEd8e6e.e,eee%f   f   d:e6e.e7e.e%gef   f   de6e.e%f   fdM„ZFy)XÚStrategyzcBase class for all strategies that change the behaviour of the training, validation and test- loop.NÚacceleratorÚcheckpoint_ioÚ	precisionÚreturnc                 óX   — || _         || _        d | _        || _        d | _        d | _        y ©N)Ú_acceleratorÚ_checkpoint_ioÚ
_precisionr%   Ú	_launcherÚ_backward_sync_control)Úselfr#   r$   r%   s       úy/Volumes/fast/ai/experiments/voice-extract-mac/.venv/lib/python3.12/site-packages/lightning_fabric/strategies/strategy.pyÚ__init__zStrategy.__init__0   s1   € ð 4?ˆÔØ6CˆÔØ/3ˆŒà"ˆŒØ.2ˆŒØFJˆÕ#ó    c                  ó   — y)zReturns the root device.N© ©r.   s    r/   Úroot_devicezStrategy.root_device>   ó   � r1   c                  ó   — y)zcWhether the current process is the rank zero process not only on the local node, but for all nodes.Nr3   r4   s    r/   Úis_global_zerozStrategy.is_global_zeroC   r6   r1   c                 ó   — | j                   S r(   )r,   r4   s    r/   ÚlauncherzStrategy.launcherH   s   € à�~‰~Ðr1   c                 ó   — | j                   S r(   ©r)   r4   s    r/   r#   zStrategy.acceleratorL   s   € à× Ñ Ð r1   c                 ó   — || _         y r(   r<   )r.   r#   s     r/   r#   zStrategy.acceleratorP   s
   € à'ˆÕr1   c                 óP   — | j                   €t        «       | _         | j                   S r(   )r*   r   r4   s    r/   r$   zStrategy.checkpoint_ioT   s%   € à×ÑÐ&Ü"3Ó"5ˆDÔØ×"Ñ"Ð"r1   Úioc                 ó   — || _         y r(   )r*   )r.   r?   s     r/   r$   zStrategy.checkpoint_ioZ   s
   € à ˆÕr1   c                 óF   — | j                   �| j                   S t        «       S r(   )r+   r   r4   s    r/   r%   zStrategy.precision^   s   € à"&§/¡/Ð"=ˆt�‰ÐNÄ9Ã;ÐNr1   c                 ó   — || _         y r(   )r+   )r.   r%   s     r/   r%   zStrategy.precisionb   s	   € à#ˆ�r1   c                  ó   — y)z&Attach the launcher based on Strategy.Nr3   r4   s    r/   Ú_configure_launcherzStrategy._configure_launcherf   r6   r1   c                 ój   — | j                   €J ‚| j                   j                  | j                  «       y)zÄSetup any processes or distributed connections.

        This must be called by the framework at the beginning of every process, before any distributed communication
        takes place.

        N)r#   Úsetup_devicer5   r4   s    r/   Úsetup_environmentzStrategy.setup_environmenti   s0   € ð ×ÑÐ+Ð+Ð+Ø×Ñ×%Ñ% d×&6Ñ&6Õ7r1   Ú
dataloaderc                 ó   — |S )z“Wraps the dataloader if necessary.

        Args:
            dataloader: iterable. Ideally of type: :class:`torch.utils.data.DataLoader`

        r3   )r.   rH   s     r/   Úprocess_dataloaderzStrategy.process_dataloaders   s
   € ð Ðr1   c                 ó¦   — | j                   j                  «       }t        «       }|j                  | j                  «       |j                  |«       |S )z1Controls how tensors get created (device, dtype).)r%   Útensor_init_contextr   Úenter_contextr5   )r.   Úprecision_init_ctxÚstacks      r/   rL   zStrategy.tensor_init_context|   sD   € à!Ÿ^™^×?Ñ?ÓAÐÜ“ˆØ×Ñ˜D×,Ñ,Ô-Ø×ÑÐ.Ô/Øˆr1   Ú
empty_initc                 óî   — | j                   j                  «       }t        «       }|j                  | j                  «       |j                  t        t        |«      ¬«      «       |j                  |«       |S )a¨  A context manager wrapping the model instantiation.

        Here, the strategy can control how the parameters of the model get created (device, dtype) and or apply other
        patches to the model.

        Args:
            empty_init: Whether to initialize the model with empty weights (uninitialized memory).
                If ``None``, the strategy will decide. Some strategies may not support all options.

        )Úenabled)r%   Úmodule_init_contextr   rM   r5   r   Úbool)r.   rP   Úprecision_module_ctxrO   s       r/   rS   zStrategy.module_init_context„   s^   € ð  $Ÿ~™~×AÑAÓCÐÜ“ˆØ×Ñ˜D×,Ñ,Ô-Ø×ÑœJ¬t°JÓ/?Ô@ÔAØ×ÑÐ0Ô1Øˆr1   ÚmoduleÚ
optimizersÚ	schedulerr   c                 ót   — | j                  |«      }|D �cg c]  }| j                  |«      ‘Œ }}|||fS c c}w )zÿSet up a model and multiple optimizers together.

        The returned objects are expected to be in the same order they were passed in. The default implementation will
        call :meth:`setup_module` and :meth:`setup_optimizer` on the inputs.

        )Úsetup_moduleÚsetup_optimizer)r.   rV   rW   rX   Ú	optimizers        r/   Úsetup_module_and_optimizersz$Strategy.setup_module_and_optimizers–   sF   € ð ×"Ñ" 6Ó*ˆÙGQÓRÁz¸)�d×*Ñ*¨9Õ5Àzˆ
ÐRØ�z 9Ð,Ð,ùò Ss   –5c                 ó   — |S )zDPerforms setup for the model, e.g., by wrapping it by another class.r3   ©r.   rV   s     r/   rZ   zStrategy.setup_module£   s   € àˆr1   r\   c                 ó   — |S )zHPerforms setup for the optimizer, e.g., by wrapping it by another class.r3   ©r.   r\   s     r/   r[   zStrategy.setup_optimizer§   s   € àÐr1   c                  ó   — y)z&Moves the model to the correct device.Nr3   r_   s     r/   Úmodule_to_devicezStrategy.module_to_device«   r6   r1   ÚbatchÚdevicec                 ó:   — |xs | j                   }t        ||«      S )a&  Moves the batch to the correct device.

        The returned batch is of the same type as the input batch, just
        having all tensors on the correct device.

        Args:
            batch: The batch of samples to move to the correct device
            device: The target device

        )r5   r   )r.   rd   re   s      r/   Úbatch_to_devicezStrategy.batch_to_device¯   s!   € ð Ò+˜4×+Ñ+ˆÜ" 5¨&Ó1Ð1r1   ÚtensorÚargsÚkwargsc                 ó¶   — | j                   j                  ||«        | j                   j                  ||g|¢­i |¤Ž | j                   j                  ||«       y)z0Forwards backward-calls to the precision plugin.N)r%   Úpre_backwardÚbackwardÚpost_backward)r.   rh   rV   ri   rj   s        r/   rm   zStrategy.backward½   sJ   € à�‰×#Ñ# F¨FÔ3Øˆ�‰×Ñ ¨Ð@°Ò@¸Ò@Ø�‰×$Ñ$ V¨VÕ4r1   c                 ó<   —  | j                   j                  |fi |¤ŽS )zµPerforms the actual optimizer step.

        Args:
            optimizer: the optimizer performing the step
            **kwargs: Any extra arguments to ``optimizer.step``

        )r%   Úoptimizer_step)r.   r\   rj   s      r/   rp   zStrategy.optimizer_stepÃ   s    € ð -ˆt�~‰~×,Ñ,¨YÑA¸&ÑAÐAr1   ÚgroupÚ
sync_gradsc                  ó   — y)a  Perform an all_gather on all processes.

        Args:
            tensor: the tensor to all_gather
            group: the process group to gather results from
            sync_grads: flag that allows users to synchronize gradients for all_gather op

        Nr3   )r.   rh   rq   rr   s       r/   Ú
all_gatherzStrategy.all_gatherÑ   r6   r1   Ú	reduce_opc                  ó   — y)a,  Reduces the given tensor (e.g. across GPUs/processes).

        Args:
            tensor: the tensor to sync and reduce
            group: the process group to reduce
            reduce_op: the reduction operation. Defaults to 'mean'.
                Can also be a string 'sum' or ReduceOp.

        Nr3   )r.   rh   rq   ru   s       r/   Ú
all_reducezStrategy.all_reduceÜ   r6   r1   Únamec                  ó   — y)z¯Synchronizes all processes which blocks processes until the whole group enters this function.

        Args:
            name: an optional name to pass into barrier.

        Nr3   )r.   rx   s     r/   ÚbarrierzStrategy.barrierí   r6   r1   ÚobjÚsrcc                  ó   — y)z…Broadcasts an object to all processes.

        Args:
            obj: the object to broadcast
            src: source rank

        Nr3   )r.   r{   r|   s      r/   Ú	broadcastzStrategy.broadcastö   r6   r1   ÚdecisionÚallc                 ó   — |S )z/Reduce a boolean decision across all processes.r3   )r.   r   r€   s      r/   Úreduce_boolean_decisionz Strategy.reduce_boolean_decision   s   € àˆr1   ÚpathÚstateÚstorage_optionsÚfilterc                 óˆ   — | j                  ||xs i ¬«      }| j                  r| j                  j                  |||¬«       yy)aÝ  Save model, optimizer, and other state as a checkpoint file.

        Args:
            path: A path to where the file(s) should be saved
            state: A dictionary with contents to be saved. If the dict contains modules or optimizers, their
                state-dict will be retrieved and converted automatically.
            storage_options: Additional options for the ``CheckpointIO`` plugin
            filter: An optional dictionary containing filter callables that return a boolean indicating whether the
                given item should be saved (``True``) or filtered out (``False``). Each filter key should match a
                state key, where its filter will be applied to the ``state_dict`` generated.

        )r†   )Ú
checkpointrƒ   r…   N)Ú"_convert_stateful_objects_in_stater8   r$   Úsave_checkpoint)r.   rƒ   r„   r…   r†   s        r/   rŠ   zStrategy.save_checkpoint  sH   € ð& ×7Ñ7¸ÀvÂ|ÐQSÐ7ÓUˆØ×ÒØ×Ñ×.Ñ.¸%ÀdÐ\kÐ.Õlð r1   c                 ó"   — |j                  «       S )zReturns model state.)Ú
state_dictr_   s     r/   Úget_module_state_dictzStrategy.get_module_state_dict  s   € à× Ñ Ó"Ð"r1   rŒ   Ústrictc                 ó*   — |j                  ||¬«       y)z%Loads the given state into the model.©rŽ   N)Úload_state_dict)r.   rV   rŒ   rŽ   s       r/   Úload_module_state_dictzStrategy.load_module_state_dict  s   € ð 	×Ñ˜z°&ÐÕ9r1   c                 ó–   — t        |d«      r.|j                  «        | j                  r|j                  «       S i S |j                  «       S )z€Returns state of an optimizer.

        Allows for syncing/collating optimizer state from processes in custom plugins.

        Úconsolidate_state_dict)Úhasattrr”   r8   rŒ   ra   s     r/   Úget_optimizer_statezStrategy.get_optimizer_state%  sJ   € ô �9Ð6Ô7ð ×,Ñ,Ô.Ø-1×-@Ò-@�9×'Ñ'Ó)ÐHÀbÐHð ×#Ñ#Ó%Ð%r1   Úweights_onlyc                 ó²  — t         j                  j                  «        | j                  j	                  ||¬«      }|s|S t        |t        «      r| j                  |||¬«       i S t        |t        «      r|j                  |«       i S t        |j                  «       |j                  «       |¬«       |j                  «       j                  «       D ]ƒ  \  }}||vrŒt        |t        «      rUt        |t        «      r$| j                  ||j                  |«      |¬«       ŒO|j                  |j                  |«      «       Œp|j                  |«      ||<   Œ… |S )aÍ  Load the contents from a checkpoint and restore the state of the given objects.

        Args:
            path: A path to where the file is located
            state: Can be one of:

                - A dictionary of objects whose state will be restored in-place from the checkpoint path.
                - ``None`` or the empty dict: The loaded checkpoint will be returned in full.
                - A :class:`~torch.nn.Module` instance, if the checkpoint file contains a raw module state dict.
                - A :class:`~torch.optim.Optimizer` instance, if the checkpoint file contains a raw optimizer state.

            strict: Whether to enforce that the keys in `state` match the keys in the checkpoint.
            weights_only: Defaults to ``None``. If ``True``, restricts loading to ``state_dicts`` of plain
                ``torch.Tensor`` and other primitive types. If loading a checkpoint from a trusted source that contains
                an ``nn.Module``, use ``weights_only=False``. If loading checkpoint from an untrusted source, we
                recommend using ``weights_only=True``. For more information, please refer to the
                `PyTorch Developer Notes on Serialization Semantics <https://docs.pytorch.org/docs/main/notes/serialization.html#id3>`_.

        Returns:
            The remaining items that were not restored into the given state dictionary. If no state dictionary is
            given, the full checkpoint will be returned.

        )r—   )rV   rŒ   rŽ   r�   )ÚtorchÚcudaÚempty_cacher$   Úload_checkpointÚ
isinstancer   r’   r   r‘   Ú!_validate_keys_for_strict_loadingÚkeysÚcopyÚitemsr   Úpop)r.   rƒ   r„   rŽ   r—   rˆ   rx   r{   s           r/   rœ   zStrategy.load_checkpoint4  s!  € ô< 	�
‰
×ÑÔ Ø×'Ñ'×7Ñ7¸È<Ð7ÓXˆ
ÙØÐä�eœVÔ$Ø×'Ñ'¨uÀÐTZÐ'Ô[ØˆIä�eœYÔ'Ø×!Ñ! *Ô-ØˆIä)¨%¯*©*«,¸
¿¹Ó8IÐRXÕYØŸ™›×+Ñ+Ö-‰IˆD�#Ø˜:Ñ%ØÜ˜#œyÔ)Ü˜c¤6Ô*Ø×/Ñ/°sÀzÇ~Á~ÐVZÓG[ÐdjÐ/Õkà×'Ñ'¨
¯©°tÓ(<Õ=à(Ÿn™n¨TÓ2��d’ð .ð Ðr1   c                 ó¼   — | j                   j                  «        | j                  €J ‚| j                  j                  «        | j                  j                  «        y)zŒThis method is called to teardown the training process.

        It is the right place to release memory and free other resources.

        N)r%   Úteardownr#   r$   r4   s    r/   r¤   zStrategy.teardownl  sJ   € ð 	�‰×ÑÔ!Ø×ÑÐ+Ð+Ð+Ø×Ñ×!Ñ!Ô#Ø×Ñ×#Ñ#Õ%r1   Úmax_normÚ	norm_typeÚerror_if_nonfinitec                 óÈ   — | j                   j                  |«       | j                   j                  |«      }t        j                  j
                  j                  ||||¬«      S )zClip gradients by norm.)r¥   r¦   r§   )r%   Úunscale_gradientsÚmain_paramsr™   ÚnnÚutilsÚclip_grad_norm_)r.   rV   r\   r¥   r¦   r§   Ú
parameterss          r/   Úclip_gradients_normzStrategy.clip_gradients_normw  sT   € ð 	�‰×(Ñ(¨Ô3Ø—^‘^×/Ñ/°	Ó:ˆ
Ü�x‰x�~‰~×-Ñ-Ø °YÐSeð .ó 
ð 	
r1   Úclip_valc                 óÄ   — | j                   j                  |«       | j                   j                  |«      }t        j                  j
                  j                  ||¬«      S )zClip gradients by value.)Ú
clip_value)r%   r©   rª   r™   r«   r¬   Úclip_grad_value_)r.   rV   r\   r°   r®   s        r/   Úclip_gradients_valuezStrategy.clip_gradients_value†  sF   € à�‰×(Ñ(¨Ô3Ø—^‘^×/Ñ/°	Ó:ˆ
Ü�x‰x�~‰~×.Ñ.¨zÀhÐ.ÓOÐOr1   Ústrategy_registryc                  ó   — y r(   r3   )Úclsrµ   s     r/   Úregister_strategieszStrategy.register_strategiesŒ  s   € àr1   c                 ó4   — dt        | «      j                  › d�S )NzThe `z£` does not support setting up the module and optimizer(s) independently. Please call `setup_module_and_optimizers(model, [optimizer, ...])` to jointly set them up.)ÚtypeÚ__name__r4   s    r/   Ú_err_msg_joint_setup_requiredz&Strategy._err_msg_joint_setup_required�  s%   € à”D˜“J×'Ñ'Ð(ð )jð jð	
r1   c                 ó(  — i }|j                  «       D ]|  \  }}t        |t        «      r| j                  |¬«      }nFt        |t        «      r| j                  |¬«      }n#t        |t        «      r|j                  «       }n|}t        ||||«       Œ~ |S )N)rV   )r\   )	r¡   r�   r   r�   r   r–   r   rŒ   Ú_apply_filter)r.   r„   r†   Úconverted_stateÚkeyr{   Ú	converteds          r/   r‰   z+Strategy._convert_stateful_objects_in_state–  sˆ   € ð +-ˆØŸ™ž‰HˆC�ä˜#œvÔ&Ø ×6Ñ6¸cÐ6ÓB‘	Ü˜C¤Ô+Ø ×4Ñ4¸sÐ4ÓC‘	Ü˜C¤Ô+ØŸN™NÓ,‘	à�	Ü˜#˜v y°/ÕBð &ð Ðr1   )NNN)r&   Nr(   )NF)NÚmean)r   )T)NN)NTN)g       @T)Gr»   Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r0   Úpropertyr   r™   re   r5   rT   r8   r   r:   r#   Úsetterr$   r%   rD   rG   r   rJ   r   rL   rS   r   Úlistr   Útupler]   rZ   r[   rc   r	   rg   r   rm   r   rp   rt   r   r   Ústrrw   rz   r   Úintr~   r‚   r   Údictr
   rŠ   r�   r’   r–   rœ   r¤   r«   Úfloatr¯   r´   Úclassmethodr   r¸   r¼   r‰   r3   r1   r/   r"   r"   -   s‚  „ Ùmð .2Ø04Ø)-ñ	Kà˜kÑ*ðKð   Ñ-ðKð ˜IÑ&ð	Kð
 
óKð Øð'˜UŸ\™\ò 'ó ó ð'ð Øðr ò ró ó ðrð ð˜( 9Ñ-ò ó ðð ð!˜X kÑ2ò !ó ð!ð ×Ñð( {ð (°tò (ó ð(ð ð#˜|ò #ó ð#ð
 ×Ñð! ð !°ò !ó ð!ð ðO˜9ò Oó ðOð ×Ñð$ 8¨IÑ#6ð $¸4ò $ó ð$ó5ó8ð¨Zð ¸Jó ðÐ%;ó ñ¨h°t©nð ÐH^ó ð& bfñ-Øð-Ø*.¨y©/ð-ØFNÈ~ÑF^ð-à	ˆv�t˜I‘¨°Ñ(@Ð@Ñ	Aó-ð 6ð ¨fó ð¨ð °yó ð ð5 vð 5°$ò 5ó ð5ñ2 Sð 2°(¸5¿<¹<Ñ2Hð 2ÐTWó 2ð5˜vð 5¨x¸Ñ/?ð 5Èð 5ÐWZð 5Ð_có 5ðBàðBð ðBð 
ó	Bð ñ ð °¸±ð ÐRVð Ðciò ó ðð ð  $Ø4:ñ	à�f˜c�kÑ"ðð ˜‰}ðð ˜E (¨C -Ñ0Ñ1ð	ð
 
ˆv�sˆ{Ñ	òó ðð  ñ˜H S™Mð °Tò ó ðð ñ˜Zð ¨cð ¸*ò ó ðñ°ð ¸4ð È4ó ð *.ØBFñmàðmð �C˜˜v y°#Ð5Ñ6Ð6Ñ7ðmð " #™ð	mð
 ˜˜c 8¨S°#¨J¸Ð,<Ñ#=Ð=Ñ>Ñ?ðmð 
ómð.#¨Fð #°t¸CÀÀsÈFÀ{ÑASÐ<SÑ7Tó #ð
 Y]ñ:Øð:Ø*.¨s°E¸#¸v¸+Ñ4FÐ/FÑ*Gð:ØQUð:à	ó:ð&¨Yð &¸4ÀÀVÀÑ;Ló &ð$ _cØØ'+ñ6àð6ð ˜˜f i°°c¸5ÀÈÐTWÐAWÑ;XÐ6XÑ1YÐYÑZÑ[ð6ð ð	6ð
 ˜t‘nð6ð 
ˆc�3ˆh‰ó6óp	&ð  (+Ø#'ñ
à—‘—‘ð
ð ð
ð ˜˜s˜
Ñ#ð	
ð
 ˜ ˜Ñ$ð
ð !ð
ð 
�‰ó
ðP¨5¯8©8¯?©?ð PÀyð PÐ\aÐbgÐilÐblÑ\mð PÐrvó Pð ðÐ4Eð È$ò ó ðð
¨só 
ðØ˜#˜u V¨Y¸Ð%;Ñ<Ð<Ñ=ðØGKÈCÐQYÐ[^Ð`cÐZdÐfjÐZjÑQkÐLkÑGlðà	ˆc�3ˆh‰ôr1   r"   c                   ó.   — e Zd ZdZedededefd„«       Zy)Ú_BackwardSyncControla†  Interface for any :class:`Strategy` that wants to offer a functionality to enable or disable gradient
    synchronization during/after back-propagation.

    The most common use-case is gradient accumulation. If a :class:`Strategy` implements this interface, the user can
    implement their gradient accumulation loop very efficiently by disabling redundant gradient synchronization.

    rV   rR   r&   c                  ó   — y)z©Blocks the synchronization of gradients during the backward pass.

        This is a context manager. It is only effective if it wraps a call to `.backward()`.

        Nr3   )r.   rV   rR   s      r/   Úno_backward_syncz%_BackwardSyncControl.no_backward_sync±  r6   r1   N)	r»   rÃ   rÄ   rÅ   r   r   rT   r   rÒ   r3   r1   r/   rÐ   rÐ   ¨  s1   „ ñð ð vð ¸ð ÐAWò ó ñr1   rÐ   c                   ó&   — e Zd ZdZedefd„«       Zy)Ú_ShardedzkMixin-interface for any :class:`Strategy` that wants to expose functionality for sharding model parameters.r&   c                  ó   — y)a  A context manager that goes over the instantiation of an :class:`torch.nn.Module` and handles sharding of
        parameters on creation.

        By sharding layers directly on instantiation, one can reduce peak memory usage and initialization time.

        Nr3   r4   s    r/   Úmodule_sharded_contextz_Sharded.module_sharded_context½  r6   r1   N)r»   rÃ   rÄ   rÅ   r   r   rÖ   r3   r1   r/   rÔ   rÔ   º  s   „ ÙuàðÐ(>ò ó ñr1   rÔ   Úrequested_keysÚcheckpoint_keysrŽ   r&   c                 ód   — | D �cg c]	  }||vsŒ|‘Œ }}|r|rt        d|d   › d�«      ‚y y c c}w )Nz$The requested state contains a key 'r   z^' that does not exist in the loaded checkpoint. To disable strict loading, set `strict=False`.)ÚKeyError)r×   rØ   rŽ   ÚkÚinvalid_keyss        r/   rž   rž   Ç  sU   € ñ  .ÓJ™~˜!°¸/Ò1I’A˜~€LÐJÙ‘,ÜØ2°<À±?Ð2Cð D>ð ?ó
ð 	
ð €vùò Ks   …	-�-rÀ   r†   Úsource_dictÚtarget_dictc                 óº   — | |v rRt        |t        «      rB||    }|j                  «       D ])  \  }} |||«      sŒ|j                  | i «       |||    |<   Œ+ y ||| <   y r(   )r�   rÌ   r¡   Ú
setdefault)rÀ   r†   rÝ   rÞ   Ú	filter_fnrÛ   Úvs          r/   r¾   r¾   Ò  sh   € ð ˆf�}œ K´Ô6Ø˜3‘Kˆ	Ø×%Ñ%Ö'‰DˆAˆqÙ˜˜A�à×&Ñ& s¨BÔ/Ø&'�˜CÑ  Ò#ñ	 (ð 'ˆ�CÒr1   )=ÚloggingÚabcr   r   Úcollections.abcr   Ú
contextlibr   r   Útypingr   r	   r
   r   r   r   r™   r   Útorch.nnr   Útorch.optimr   Útorch.utils.datar   Úlightning_fabric.acceleratorsr   Ú)lightning_fabric.plugins.io.checkpoint_ior   Ú$lightning_fabric.plugins.io.torch_ior   Ú"lightning_fabric.plugins.precisionr   Ú.lightning_fabric.strategies.launchers.launcherr   Ú$lightning_fabric.strategies.registryr   Ú%lightning_fabric.utilities.apply_funcr   Úlightning_fabric.utilities.initr   Ú lightning_fabric.utilities.typesr   r   r   r   Útorch.optim.lr_schedulerr   r   r    Ú	getLoggerr»   Úlogr"   rÐ   rÔ   rÊ   rT   rž   rÌ   Úobjectr¾   r3   r1   r/   Ú<module>rø      s  ðó ß #Ý $ß 8ß I× Iã Ý Ý Ý !Ý 'å 5Ý BÝ BÝ 8Ý DÝ BÝ EÝ 6ß TÓ TáÝ5á�\Ó"€
Ù
�)Ó
€à€g×Ñ˜Ó!€ôxˆsô xôv˜3ô ô$
ˆsô 
ð
Ø˜S‘Mð
Ø4<¸S±Mð
ØKOð
à	ó
ð'Ø	ð'Ø˜3 ¨#¨s¨°TÐ)9Ñ :Ð:Ñ;ð'ØJPð'Ø_cÐdgÐilÐdlÑ_mð'à	ô'r1   