
    kh                         d dl Z d dlZ d dl mZmZ ddlmZ ddedededed	ef
d
Z	e j                  j                  d        G d dej                        Zy)    N)nnTensor   )_log_api_usage_onceinputpmodetrainingreturnc                 ,   t         j                  j                         s-t         j                  j                         st	        t
               |dk  s|dkD  rt        d|       |dvrt        d|       |r|dk(  r| S d|z
  }|dk(  r%| j                  d   gdg| j                  dz
  z  z   }ndg| j                  z  }t        j                  || j                  | j                  	      }|j                  |      }|dkD  r|j                  |       | |z  S )
a  
    Implements the Stochastic Depth from `"Deep Networks with Stochastic Depth"
    <https://arxiv.org/abs/1603.09382>`_ used for randomly dropping residual
    branches of residual architectures.

    Args:
        input (Tensor[N, ...]): The input tensor or arbitrary dimensions with the first one
                    being its batch i.e. a batch with ``N`` rows.
        p (float): probability of the input to be zeroed.
        mode (str): ``"batch"`` or ``"row"``.
                    ``"batch"`` randomly zeroes the entire input, ``"row"`` zeroes
                    randomly selected rows from the batch.
        training: apply stochastic depth if is ``True``. Default: ``True``

    Returns:
        Tensor[N, ...]: The randomly zeroed tensor.
    g        g      ?z4drop probability has to be between 0 and 1, but got )batchrowz0mode has to be either 'batch' or 'row', but got r   r      )dtypedevice)torchjitis_scripting
is_tracingr   stochastic_depth
ValueErrorshapendimemptyr   r   
bernoulli_div_)r   r   r	   r
   survival_ratesizenoises          \/var/www/teggl/fontify/venv/lib/python3.12/site-packages/torchvision/ops/stochastic_depth.pyr   r      s   $ 99!!#EII,@,@,B,-3w!c'OPQsSTT##KD6RSSqCx!GMu}A1#a"88sUZZKKEKKEE]+Es

=!5=    r   c                   L     e Zd ZdZdededdf fdZdedefdZdefd	Z	 xZ
S )
StochasticDepthz'
    See :func:`stochastic_depth`.
    r   r	   r   Nc                 T    t         |           t        |        || _        || _        y N)super__init__r   r   r	   )selfr   r	   	__class__s      r    r'   zStochasticDepth.__init__7   s$    D!	r!   r   c                 Z    t        || j                  | j                  | j                        S r%   )r   r   r	   r
   )r(   r   s     r    forwardzStochasticDepth.forward=   s    tvvtyy$--HHr!   c                 l    | j                   j                   d| j                   d| j                   d}|S )Nz(p=z, mode=))r)   __name__r   r	   )r(   ss     r    __repr__zStochasticDepth.__repr__@   s2    ~~&&'s466('$))AFr!   )r.   
__module____qualname____doc__floatstrr'   r   r+   r0   __classcell__)r)   s   @r    r#   r#   2   sD    % s t IV I I# r!   r#   )T)r   torch.fxr   r   utilsr   r4   r5   boolr   fxwrapModuler#    r!   r    <module>r>      s^       '$F $u $C $4 $SY $N   !bii r!   