ó
    Eñi±  ã                   ó  • S SK Jr  S SKJrJrJr  S SKJr  S SKrS SK	J
r
  S SKJrJr  SSKJrJr  \SS\
R                   S	\S-  4S
 jj5       r " S S\5      r\" \5      S\
R                   S\
R                   4S j5       rg)é    )Ú	Generator)ÚAbstractContextManagerÚcontextmanagerÚnullcontext)ÚAnyN)Ú'_checkpoint_without_reentrant_generatorÚ_DEFAULT_DETERMINISM_MODEé   )Ú_StateÚcontractÚmoduleÚuser_ctxc              #   óV  #   • U(       a  UO	[        5          [        R                  U 5      R                  nS[        R                  U 5      l         Sv •  U[        R                  U 5      l         SSS5        g! U[        R                  U 5      l        f = f! , (       d  f       g= f7f)zg
Disable hooks installed by checkpoint to avoid unintentional recursion
during backward recomputation.
FN)r   Ú
checkpointÚstateÚenable_hook)r   r   Úorig_enable_hooks      Úp/home/mande/repo/quber/.venv/lib/python3.13/site-packages/torch/distributed/_composable/checkpoint_activation.pyÚ_no_hookr      s�   é € ö ‰¤;£=Ñ	0Ü%×+Ñ+¨FÓ3×?Ñ?ÐØ/4Œ
×Ñ˜Ó Ô,ð	DÛà3CŒJ×Ñ˜VÓ$Õ0÷ 
1Ð	0øð 4DŒJ×Ñ˜VÓ$Õ0ú÷ 
1Õ	0üs4   ‚B)–:BÁA9ÁBÁ0	B)Á9BÂBÂ
B&Â"B)c                   ó:   • \ rS rSr% Sr\\S'   \S   S-  \S'   Srg)Ú_CheckpointStateé    Fr   )NNNNÚ_ac_generator© )	Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__r   ÚboolÚ__annotations__r   Ú__static_attributes__r   ó    r   r   r       s   ‡ Ø€K�ÓØÐ-Ñ.°Ñ5Ö5r"   r   Úreturnc                 óþ  ^^^^^	• [         R                  R                  S5        UR                  SS5      nU(       a  [	        S5      eUR                  SS5      mUR                  SS5      m	UR                  S	[
        5      mUR                  S
S5      mUR                  SS5      mU(       a$  [        SSR                  S U 5       5      -   5      eS[        R                  S[        [        S4   S[        [        [        4   SS4UUUUU	4S jjnS[        R                  S[        [        S4   S[        S[        4S jnS[        R                  U 5      l        U R#                  USS9  U R%                  USSS9  U $ )a;  
This is a composable activation checkpointing API. Unlike functional
activation checkpointing APIs, this one does not require changing model
source code. Unlike ``nn.Module`` wrapper activation checkpointing APIs,
this one does not modify model structure or fully-qualified names either.
Under the hood, it registers activation checkpointing logic as pre- and
post-forward hooks. Hence, this API can be easily applied to any model or
sub-modules in the model.

Args:
    module (nn.Module): the target model or sub-module to apply activation
        checkpointing.

Example::
    >>> # xdoctest: +SKIP
    >>> import torch.nn as nn
    >>>
    >>> class MyModel(nn.Module):
    >>>     def __init__(self) -> None:
    >>>         super().__init__()
    >>>         self.l1 = nn.Linear(10, 10)
    >>>         self.l2 = nn.Linear(10, 10)
    >>>
    >>>     def forward(self, x):
    >>>         return self.l2(self.l1(x))
    >>>
    >>> model = MyModel()
    >>> checkpoint(model.l1)  # apply activation checkpointing only to l1
    >>> model(torch.zeros(2, 10)).sum().backward()

ztorch.distributed.checkpointÚuse_reentrantFzsuse_reentrant=True is not supported in composable checkpoint. Please use torch.utils.checkpoint.checkpoint instead.Úpreserve_rng_stateTÚ
context_fnNÚdeterminism_checkÚdebugÚ
early_stopzUnexpected keyword arguments: Ú,c              3   ó$   #   • U  H  ov •  M     g 7f©Nr   )Ú.0Úargs     r   Ú	<genexpr>Úcheckpoint.<locals>.<genexpr>V   s   é € Ð7NÂvÀ¼Âvùs   ‚r   Úargs.Úkwargsr#   c                 óÒ   >^ • [         R                  T 5      R                  (       aA  U U	4S jn[        T TUTTT/UQ70 UD6nU[         R                  T 5      l        [        U5        g g )Nc                  ób   >• Tb  T" 5       u  pU [        TU5      4$ [        5       [        T5      4$ r-   )r   r   )Úctx1Úctx2r   Úuser_context_fnss     €€r   Úcontext_fnsÚ9checkpoint.<locals>.forward_pre_hook.<locals>.context_fns^   s7   ø€ Ø#Ñ/Ù!1Ó!3‘J�DØ¤¨&°$Ó!7Ð7Ð7ä&›=¬(°6Ó*:Ð:Ð:r"   )r   r   r   r   r   Únext)
r   r2   r3   r9   Úgenr)   r(   r*   r&   r8   s
   `    €€€€€r   Úforward_pre_hookÚ$checkpoint.<locals>.forward_pre_hookY   sq   ù€ ô ×Ñ˜FÓ#×/×/ö;ô :ØØ"ØØ!ØØð	ð ò	ð ñ	ˆCð 69ŒJ×Ñ˜VÓ$Ô2Ü��Ið) 0r"   ÚinputsÚoutputc                 ó  • [         R                  U 5      R                  (       a;   [         R                  U 5      R                  nUc   e[	        U5        [        S5      eS [         R                  U 5      l        g ! [         a     N'f = f)NzWExpected non-reentrant activation checkpoint generator to be exhausted, but it was not!)r   r   r   r   r;   ÚRuntimeErrorÚStopIteration)r   r?   r@   r<   s       r   Úforward_hookÚ checkpoint.<locals>.forward_hookr   s}   € Ü×Ñ˜FÓ#×/×/ð	Ü ×&Ñ& vÓ.×<Ñ<�Ø‘Ð&�Ü�S”	ô #Ømóð ð 26Œ
×Ñ˜Ó Õ.øô !ó Ùðús   ¦/A; Á;
BÂB)Úwith_kwargs)ÚprependÚalways_call)ÚtorchÚ_CÚ_log_api_usage_onceÚpopÚNotImplementedErrorr	   Ú
ValueErrorÚjoinÚnnÚModuleÚtupler   ÚdictÚstrr   r   r   Úregister_forward_pre_hookÚregister_forward_hook)
r   r3   r%   r=   rD   r)   r(   r*   r&   r8   s
        @@@@@r   r   r   %   sm  ü€ ôB 
‡H�H× Ñ Ð!?Ô@à—J‘J˜°Ó6€MÞÜ!ðDó
ð 	
ð  Ÿ™Ð$8¸$Ó?ÐØ—z‘z ,°Ó5ÐØŸ
™
Ð#6Ô8QÓRÐØ�J‰J�w Ó&€EØ—‘˜L¨$Ó/€JæÜØ,¨s¯x©xÑ7NÁvÓ7NÓ/NÑNó
ð 	
ðÜ—	‘	ðÜ!&¤s¨C x¡ðÜ:>¼sÄC¸x¹.ðà	÷ó ð26œRŸY™Yð 6´´c¸3°h±ð 6Ìð 6ÔQTô 6ð" ,0„J×Ñ�VÓÔ(Ø
×$Ñ$Ð%5À4Ð$ÑHØ
× Ñ  °tÈÐ ÑNØ€Mr"   r-   )Úcollections.abcr   Ú
contextlibr   r   r   Útypingr   rI   Útorch.nnrP   Útorch.utils.checkpointr   r	   r   r   rQ   r   r   r   r   r"   r   Ú<module>r\      s‘   ðå %ß JÑ JÝ ã Ý ÷÷
 'ð ñD�R—Y‘Yð DÐ*@À4Ñ*Gô Dó ðDô6�vô 6ñ
 
Ð
Óð`�r—y‘yð `¨r¯y©yó `ó ñ`r"   