Ë
    g^(hu  ã                   ó  — d dl mZ d dlmZmZ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 ddlmZmZ eddej"                  d	ee   fd
„«       Z G d„ de«      Z ee«      dej"                  dej"                  fd„«       Zy)é    )Ú	Generator)ÚAbstractContextManagerÚcontextmanagerÚnullcontext)ÚAnyÚOptionalN)Ú'_checkpoint_without_reentrant_generatorÚ_DEFAULT_DETERMINISM_MODEé   )Ú_StateÚcontractÚmoduleÚuser_ctxc              #   óB  K  — |r|n	t        «       5  t        j                  | «      j                  }dt        j                  | «      _        	 d–— |t        j                  | «      _        	 ddd«       y# |t        j                  | «      _        w xY w# 1 sw Y   yxY w­w)zs
    Disable hooks installed by checkpoint to avoid unintentional recursion
    during backward recomputation.
    FN)r   Ú
checkpointÚstateÚenable_hook)r   r   Úorig_enable_hooks      úq/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/torch/distributed/_composable/checkpoint_activation.pyÚ_no_hookr      s�   è ø€ ñ ‰¤;£=ñ DÜ%×+Ñ+¨FÓ3×?Ñ?ÐØ/4Œ
×Ñ˜Ó Ô,ð	DÛà3CŒJ×Ñ˜VÓ$Õ0÷Dð Døð 4DŒJ×Ñ˜VÓ$Õ0ú÷Dð Düs4   ‚B‘:BÁA4ÁBÁ+	BÁ4BÂBÂBÂBc                   ó2   — e Zd ZU dZeed<   eed      ed<   y)Ú_CheckpointStateFr   )NNNÚ_ac_generatorN)Ú__name__Ú
__module__Ú__qualname__r   ÚboolÚ__annotations__r   r   © ó    r   r   r       s   … Ø€K�ÓØ˜IÐ&6Ñ7Ñ8Ô8r    r   Úreturnc                 óÈ  ‡‡‡‡— t         j                  j                  d«       |j                  dd«      }|rt	        d«      ‚|j                  dd«      Š|j                  dd«      Š|j                  d	t
        «      Š|j                  d
d«      Š|r$t        ddj                  d„ |D «       «      z   «      ‚dt        j                  dt        t        df   dt        t        t        f   ddfˆˆˆˆfd„}dt        j                  dt        t        df   dt        dt        fd„}dt        j                  | «      _        | j#                  |d¬«       | j%                  |dd¬«       | S )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ÚdebugzUnexpected keyword arguments: ú,c              3   ó    K  — | ]  }|–— Œ y ­w©Nr   )Ú.0Úargs     r   ú	<genexpr>zcheckpoint.<locals>.<genexpr>U   s   è ø€ Ò7NÀ¼Ñ7Nùs   ‚r   Úargs.Úkwargsr!   c                 óÄ   •‡ — t         j                  ‰ «      j                  r?ˆ ˆfd„}t        ‰ ‰|‰‰g|¢­i |¤Ž}|t         j                  ‰ «      _        t        |«       y y )Nc                  ób   •— ‰� ‰«       \  } }| t        ‰|«      fS t        «       t        ‰«      fS r*   )r   r   )Úctx1Úctx2r   Úuser_context_fnss     €€r   Úcontext_fnsz9checkpoint.<locals>.forward_pre_hook.<locals>.context_fns]   s9   ø€ Ø#Ð/Ù!1Ó!3‘J�D˜$Ø¤¨&°$Ó!7Ð7Ð7ä&›=¬(°6Ó*:Ð:Ð:r    )r   r   r   r	   r   Únext)	r   r.   r/   r5   Úgenr'   r&   r$   r4   s	   `    €€€€r   Úforward_pre_hookz$checkpoint.<locals>.forward_pre_hookX   sn   ù€ ô ×Ñ˜FÓ#×/Ò/õ;ô :ØØ"ØØ!Øðð òð ñˆCð 69ŒJ×Ñ˜VÓ$Ô2Ü��Ið' 0r    ÚinputsÚoutputc                 ó  — t         j                  | «      j                  r:	 t         j                  | «      j                  }|€J ‚t	        |«       t        d«      ‚d t         j                  | «      _        y # t        $ r Y Œ&w xY w)NzWExpected non-reentrant activation checkpoint generator to be exhausted, but it was not!)r   r   r   r   r6   ÚRuntimeErrorÚStopIteration)r   r9   r:   r7   s       r   Úforward_hookz checkpoint.<locals>.forward_hookp   s}   € Ü×Ñ˜FÓ#×/Ò/ð	Ü ×&Ñ& vÓ.×<Ñ<�Ø�Ð&�Ü�S”	ô #Ømóð ð 26Œ
×Ñ˜Ó Õ.øô !ò Ùðús   ¡.A5 Á5	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   r/   r#   r8   r>   r'   r&   r$   r4   s	        @@@@r   r   r   %   s]  û€ ôB 
‡H�H× Ñ Ð!?Ô@à—J‘J˜°Ó6€MÙÜ!ðDó
ð 	
ð  Ÿ™Ð$8¸$Ó?ÐØ—z‘z ,°Ó5ÐØŸ
™
Ð#6Ô8QÓRÐØ�J‰J�w Ó&€EáÜØ,¨s¯x©xÑ7NÀvÔ7NÓ/NÑNó
ð 	
ðÜ—	‘	ðÜ!&¤s¨C x¡ðÜ:>¼sÄC¸x¹.ðà	÷ð ð0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   r   rB   Útorch.nnrI   Útorch.utils.checkpointr	   r
   r   r   rJ   r   r   r   r   r    r   ú<module>rU      s‘   ðå %ß JÑ Jß  ã Ý ÷÷
 'ð ñD�R—Y‘Yð D¨(Ð3IÑ*Jò Dó ðDô9�vô 9ñ
 
Ð
Óð^�r—y‘yð ^¨r¯y©yò ^ó ñ^r    