
    ڧg                         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
                            d            G d dej                  ZdS )    N)nnTensor   )_log_api_usage_onceTinputpmodetrainingreturnc                 2   t           j                                        s2t           j                                        st	          t
                     |dk     s|dk    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        	          }|                    |          }|dk    r|                    |           | |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/html/ai-engine/env/lib/python3.11/site-packages/torchvision/ops/stochastic_depth.pyr   r      s5   $ 9!!## .EI,@,@,B,B .,---3ww!c''SPQSSTTT###RDRRSSS qCxx!GMu}}A1#a"88sUZKEKEE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          |            || _        || _        d S N)super__init__r   r   r	   )selfr   r	   	__class__s      r    r'   zStochasticDepth.__init__7   s9    D!!!			r!   r   c                 D    t          || j        | j        | j                  S r%   )r   r   r	   r
   )r(   r   s     r    forwardzStochasticDepth.forward=   s    tvty$-HHHr!   c                 D    | j         j         d| j         d| j         d}|S )Nz(p=z, mode=))r)   __name__r   r	   )r(   ss     r    __repr__zStochasticDepth.__repr__@   s.    ~&FF46FF$)FFFr!   )r.   
__module____qualname____doc__floatstrr'   r   r+   r0   __classcell__)r)   s   @r    r#   r#   2   s         % s t      IV I I I 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   ! ! !    bi     r!   