class_docstr: Fast Gradient Sign Method is a one-step method that can generate
  adversarial examples.
  
  For non-targeted attack, the formulation is::
  
      x' = x + epsilon * sign(gradient of L(theta, x, y))
  
  For targeted attack on t, the formulation is::
  
      x' = x - epsilon * sign(gradient of L(theta, x, t))
  
  ``L(theta, x, y)`` is the model's loss function with respect to model
  parameters, inputs and labels.
  
  More details on Fast Gradient Sign Method can be found in the original
  paper: https://arxiv.org/abs/1412.6572
class_docstr_tok: ["Fast","Gradient","Sign","Method","is","a","one-step","method","that","can","generate","adversarial","examples",".","For","non-targeted","attack",",","the","formulation","is",":",":","x","'","=","x","+","epsilon","*","sign","(","gradient","of","L","(","theta",",","x",",","y",")",")","For","targeted","attack","on","t",",","the","formulation","is",":",":","x","'","=","x","-","epsilon","*","sign","(","gradient","of","L","(","theta",",","x",",","t",")",")","``","L","(","theta",",","x",",","y",")","``","is","the","model","'s","loss","function","with","respect","to","model","parameters",",","inputs","and","labels",".","More","details","on","Fast","Gradient","Sign","Method","can","be","found","in","the","original","paper",":","https",":","\/\/arxiv.org\/abs\/1412.6572"]
docstr: Args:
      forward_func (Callable): The pytorch model for which the attack is
                  computed.
      loss_func (Callable, optional): Loss function of which the gradient
                  computed. The loss function should take in outputs of the
                  model and labels, and return a loss tensor.
                  The default loss function is negative log.
      lower_bound (float, optional): Lower bound of input values.
                  Default: ``float("-inf")``
      upper_bound (float, optional): Upper bound of input values.
                  e.g. image pixels must be in the range 0-255
                  Default: ``float("inf")``
  
  Attributes:
      bound (Callable): A function that bounds the input values based on
                  given lower_bound and upper_bound. Can be overwritten for
                  custom use cases if necessary.
      zero_thresh (float): The threshold below which gradient will be treated
                  as zero. Can be modified for custom use cases if necessary.
docstr_tok: ["Args",":","forward_func","(","Callable",")",":","The","pytorch","model","for","which","the","attack","is","computed",".","loss_func","(","Callable",",","optional",")",":","Loss","function","of","which","the","gradient","computed",".","The","loss","function","should","take","in","outputs","of","the","model","and","labels",",","and","return","a","loss","tensor",".","The","default","loss","function","is","negative","log",".","lower_bound","(","float",",","optional",")",":","Lower","bound","of","input","values",".","Default",":","``","float","(","``","-inf","''",")","``","upper_bound","(","float",",","optional",")",":","Upper","bound","of","input","values",".","e.g",".","image","pixels","must","be","in","the","range","0-255","Default",":","``","float","(","``","inf","''",")","``","Attributes",":","bound","(","Callable",")",":","A","function","that","bounds","the","input","values","based","on","given","lower_bound","and","upper_bound",".","Can","be","overwritten","for","custom","use","cases","if","necessary",".","zero_thresh","(","float",")",":","The","threshold","below","which","gradient","will","be","treated","as","zero",".","Can","be","modified","for","custom","use","cases","if","necessary","."]
code: def __init__(
      self,
      forward_func: Callable,
      loss_func: Optional[Callable] = None,
      lower_bound: float = float("-inf"),
      upper_bound: float = float("inf"),
  ) -> None:
      r"""
      Args:
          forward_func (Callable): The pytorch model for which the attack is
                      computed.
          loss_func (Callable, optional): Loss function of which the gradient
                      computed. The loss function should take in outputs of the
                      model and labels, and return a loss tensor.
                      The default loss function is negative log.
          lower_bound (float, optional): Lower bound of input values.
                      Default: ``float("-inf")``
          upper_bound (float, optional): Upper bound of input values.
                      e.g. image pixels must be in the range 0-255
                      Default: ``float("inf")``
  
      Attributes:
          bound (Callable): A function that bounds the input values based on
                      given lower_bound and upper_bound. Can be overwritten for
                      custom use cases if necessary.
          zero_thresh (float): The threshold below which gradient will be treated
                      as zero. Can be modified for custom use cases if necessary.
      """
      super().__init__()
      self.forward_func = forward_func
      self.loss_func = loss_func
      self.bound = lambda x: torch.clamp(
          x, min=lower_bound, max=upper_bound
      )
      self.zero_thresh = 10**-6
  
file_path: captum/captum/robust/_core/fgsm.py
imports: from typing import Any, Callable, Optional, Tuple, Union
  import torch
  from captum._utils.common import _format_additional_forward_args, _format_output, _format_tensor_into_tuples, _is_tuple, _select_targets
  from captum._utils.gradient import apply_gradient_requirements, compute_gradients, undo_gradient_requirements
  from captum._utils.typing import TensorOrTupleOfTensorsGeneric
  from captum.log import log_usage
  from captum.robust._core.perturbation import Perturbation
  from torch import Tensor
label_desc: Use image node_id 1 to create a new FGSM object from inherited base classes: Perturbation with example: obj = FGSM(forward_func, loss_func, lower_bound, upper_bound)