code: def spsa_perturb(
      predict,
      loss_fn,
      x,
      y,
      eps,
      delta,
      lr,
      nb_iter,
      nb_sample,
      max_batch_size,
      clip_min=0.0,
      clip_max=1.0,
  ):
      """Perturbs the input `x` based on SPSA attack.
  
      :param predict: predict function (single argument: input).
      :param loss_fn: loss function (dual arguments: output, target).
      :param x: input argument for function `predict`.
      :param y: target argument for function `loss_fn`.
      :param eps: the L_inf budget of the attack.
      :param delta: scaling parameter of SPSA.
      :param lr: the learning rate of the `Adam` optimizer.
      :param nb_iter: number of iterations of the attack.
      :param nb_sample: number of samples for the SPSA gradient approximation.
      :param max_batch_size: maximum batch size to be evaluated at once.
      :param clip_min: upper bound of image values.
      :param clip_max: lower bound of image values.
  
      :return: the perturbated input.
      """
  
      dx = torch.zeros_like(x)
      dx.grad = torch.zeros_like(dx)
      optimizer = torch.optim.Adam([dx], lr=lr)
      for _ in range(nb_iter):
          optimizer.zero_grad()
          dx.grad = spsa_grad(
              predict,
              loss_fn,
              x + dx,
              y,
              delta,
              nb_sample,
              max_batch_size,
          )
          optimizer.step()
          dx = linf_clamp_(dx, x, eps, clip_min, clip_max)
      x_adv = x + dx
  
      return x_adv
  
file_path: advertorch/advertorch/attacks/spsa.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from __future__ import unicode_literals
  import warnings
  import torch
  from .base import Attack
  from .base import LabelMixin
  from .utils import MarginalLoss
  from ..utils import is_float_or_torch_tensor, batch_clamp, clamp
label_desc: Use image node_id 4 for calling a global function with example usage: spsa_perturb(predict, loss_fn, x, y, eps, delta, lr, nb_iter, nb_sample, max_batch_size, clip_min, clip_max) and returns: x_adv