
    Ph                         d dl Z d dlZd dlZ	 d dlZdZd dlmZ g dZ	 G d dej                  j                  j                        Zd Zdddd	Zd
 Zy# e$ r dZY Jw xY w)    NT)Any)autocast
custom_fwd
custom_bwdc                        e Zd ZdZdej
                  dfdedej                  def fdZ fdZ	de
d	e
d
e
f fdZ fdZ xZS )r   zSee :class:`torch.autocast`.

    ``torch.cuda.amp.autocast(args...)`` is equivalent to ``torch.autocast("cuda", args...)``
    Tenableddtypecache_enabledc                     t         j                  j                         r|| _        d| _        || _        y t        |   d|||       y )Ncuda)r   r	   r
   )torch_jit_internalis_scripting_enableddevice
fast_dtypesuper__init__)selfr   r	   r
   	__class__s       gC:\Users\daisl\Desktop\realtime-object-detection\venv\Lib\site-packages\torch/cuda/amp/autocast_mode.pyr   zautocast.__init__   sJ     ++-#DM DK#DOG5 	 	
    c                 `    t         j                  j                         r| S t        |          S N)r   r   r   r   	__enter__)r   r   s    r   r   zautocast.__enter__&   s(    ++-Kw ""r   exc_typeexc_valexc_tbc                 d    t         j                  j                         ry t        |   |||      S r   )r   r   r   r   __exit__)r   r   r   r   r   s       r   r    zautocast.__exit__,   s,    ++-w'6::r   c                 b    t         j                  j                         r|S t        |   |      S r   )r   r   r   r   __call__)r   funcr   s     r   r"   zautocast.__call__1   s*    ++-Kw%%r   )__name__
__module____qualname____doc__r   float16boolr	   r   r   r   r    r"   __classcell__)r   s   @r   r   r      se     "]]"	

 {{
 	
#; ;s ;C ;
& &r   r   c           	         t        | t        j                        rQ| j                         xr* | j                  xr | j
                  t        j                  u}|r| j                        S | S t        | t        t        f      r| S t        rt        | t        j                        r| S t        | t        j                  j                        r8| j!                         D ci c]  \  }}t#        |      t#        |       c}}S t        | t        j                  j$                        r4fd| D        }t        | t&        t(        f      r t+        |       |      S |S | S c c}}w )Nc              3   6   K   | ]  }t        |        y wr   )_cast).0vr	   s     r   	<genexpr>z_cast.<locals>.<genexpr>H   s     3UE!UOUs   )
isinstancer   Tensoris_floating_pointis_cudar	   float64tostrbytes	HAS_NUMPYnpndarraycollectionsabcMappingitemsr-   Iterablelisttupletype)valuer	   is_eligiblekr/   iterables    `    r   r-   r-   9   s   %&##% 33EMM1 	
 #.uxx858	EC<	(	z%4	E;??22	3=B[[]K]TQaq%0]KK	E;??33	43U3edE]+4;x((O Ls   !Ecast_inputsc                      t        j                  t              S t        j                          fd       }|S )aa  
    Create a helper decorator for ``forward`` methods of custom autograd functions.

    Autograd functions are subclasses of :class:`torch.autograd.Function`.
    See the :ref:`example page<amp-custom-examples>` for more detail.

    Args:
        cast_inputs (:class:`torch.dtype` or None, optional, default=None):  If not ``None``,
            when ``forward`` runs in an autocast-enabled region, casts incoming
            floating-point CUDA Tensors to the target dtype (non-floating-point Tensors are not affected),
            then executes ``forward`` with autocast disabled.
            If ``None``, ``forward``'s internal ops execute with the current autocast state.

    .. note::
        If the decorated ``forward`` is called outside an autocast-enabled region,
        :func:`custom_fwd<custom_fwd>` is a no-op and ``cast_inputs`` has no effect.
    rH   c            	      T   t        j                         | d   _        $t        j                         | d   _         | i |S t        j                         }d| d   _        |r2t        d      5   t        |       i t        |      cd d d        S  | i |S # 1 sw Y   y xY w)Nr   F)r   )r   get_autocast_gpu_dtype_dtypeis_autocast_enabled_fwd_used_autocastr   r-   )argskwargsautocast_contextrI   fwds      r   decorate_fwdz custom_fwd.<locals>.decorate_fwdn   s    557Q).)B)B)DDG&'''$88:).DG&e,dK 8WE&+<VW -, D+F++ -,s   0BB')	functoolspartialr   wraps)rS   rI   rT   s   `` r   r   r   Y   s@    $ {  EE__S, , r   c                 B     t        j                          fd       }|S )a7  Create a helper decorator for backward methods of custom autograd functions.

    Autograd functions are subclasses of :class:`torch.autograd.Function`.
    Ensures that ``backward`` executes with the same autocast state as ``forward``.
    See the :ref:`example page<amp-custom-examples>` for more detail.
    c                      t        | d   j                  | d   j                        5   | i |cd d d        S # 1 sw Y   y xY w)Nr   )r   r	   )r   rO   rM   )rP   rQ   bwds     r   decorate_bwdz custom_bwd.<locals>.decorate_bwd   s9    d1g88QO'' POOs	   ;A)rU   rW   )rZ   r[   s   ` r   r   r      s(     __S( ( r   r   )r<   rU   r   numpyr:   r9   ModuleNotFoundErrortypingr   __all__ampautocast_moder   r-   r   r    r   r   <module>rc      sq      I 
2#&uyy&&// #&P@$ $Ts  	Bs   A AA