class_docstr: An implementation of residual addition of an adapter module with its input.
  Supports stochastic depth regularization.
class_docstr_tok: ["An","implementation","of","residual","addition","of","an","adapter","module","with","its","input",".","Supports","stochastic","depth","regularization","."]
docstr: Compute and apply stochastic depth if probability is greater than 0.
  
  Args:
      output: The result tensor, after one of the active adapters has finished its forward passes.
      input: Original output tensor of the module, or the output of the previous adapter (if more than
          one adapters are enabled).
      adapter: The adapter module that is currently required to perform the forward pass.
      module: The calling module, in its entirety. It is a module that implements `AdapterModuleMixin`,
          therefore the strategy can access all other adapters in this module via `module.adapter_layer`.
  
  Returns:
      The result tensor, after stochastic depth has been potentially applied to it.
docstr_tok: ["Compute","and","apply","stochastic","depth","if","probability","is","greater","than","0",".","Args",":","output",":","The","result","tensor",",","after","one","of","the","active","adapters","has","finished","its","forward","passes",".","input",":","Original","output","tensor","of","the","module",",","or","the","output","of","the","previous","adapter","(","if","more","than","one","adapters","are","enabled",")",".","adapter",":","The","adapter","module","that","is","currently","required","to","perform","the","forward","pass",".","module",":","The","calling","module",",","in","its","entirety",".","It","is","a","module","that","implements","`","AdapterModuleMixin","`",",","therefore","the","strategy","can","access","all","other","adapters","in","this","module","via","`","module.adapter_layer","`",".","Returns",":","The","result","tensor",",","after","stochastic","depth","has","been","potentially","applied","to","it","."]
code: def apply_stochastic_depth(
      self,
      output: torch.Tensor,
      input: torch.Tensor,
      adapter: torch.nn.Module,
      *,
      module: "AdapterModuleMixin",
  ):
      """
      Compute and apply stochastic depth if probability is greater than 0.
  
      Args:
          output: The result tensor, after one of the active adapters has finished its forward passes.
          input: Original output tensor of the module, or the output of the previous adapter (if more than
              one adapters are enabled).
          adapter: The adapter module that is currently required to perform the forward pass.
          module: The calling module, in its entirety. It is a module that implements `AdapterModuleMixin`,
              therefore the strategy can access all other adapters in this module via `module.adapter_layer`.
  
      Returns:
          The result tensor, after stochastic depth has been potentially applied to it.
      """
      # Perform stochastic depth if needed.
      p = self.stochastic_depth
      if p < 0.0 or p > 1.0:
          raise ValueError(
              f"Stochastic depth probability has to be between 0 and 1, but got {p}"
          )
  
      # Apply stochastic depth to the output of adapter.
      keep_prob = 1.0 - p
      shape = [1] * output.ndim
      noise = torch.empty(
          shape, dtype=output.dtype, device=output.device
      )
      noise = noise.bernoulli_(keep_prob)
      if (
          keep_prob > 0.0
      ):  # Done to normalize activation for inference mode
          noise.div_(keep_prob)
  
      output = noise * output
  
      return output
  
imports: from abc import ABC
  from dataclasses import dataclass
  from typing import Any, Dict, List, Tuple, Union
  import torch
  from nemo.core.classes.mixins import AccessMixin
label_desc: Use image node_id 4 for calling the ResidualAddAdapterStrategy obj's underlying member method code with example usage: obj.apply_stochastic_depth(output, input, adapter) and returns: output