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: A helper function to calculate the perturbed inputs given original
  inputs, gradient of loss function and epsilon. The calculation is
  different for targeted v.s. non-targeted as described above.
docstr_tok: ["A","helper","function","to","calculate","the","perturbed","inputs","given","original","inputs",",","gradient","of","loss","function","and","epsilon",".","The","calculation","is","different","for","targeted","v.s",".","non-targeted","as","described","above","."]
code: def _perturb(
      self,
      inputs: Tuple,
      grads: Tuple,
      epsilon: float,
      targeted: bool,
      masks: Tuple,
  ) -> Tuple:
      r"""
      A helper function to calculate the perturbed inputs given original
      inputs, gradient of loss function and epsilon. The calculation is
      different for targeted v.s. non-targeted as described above.
      """
      multiplier = -1 if targeted else 1
      inputs = tuple(
          torch.where(
              torch.abs(grad) > self.zero_thresh,
              inp + multiplier * epsilon * torch.sign(grad) * mask,
              inp,
          )
          for grad, inp, mask in zip(grads, inputs, masks)
      )
      return inputs
  
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 3 for calling the FGSM obj's underlying member method code with example usage: obj._perturb(inputs, grads, epsilon, targeted, masks) and returns: inputs