class_docstr: Define a backward pass for a blackbox function using extra queries.
  Once wrapped, the blackbox function will become compatible with any attack
  in Advertorch, so long as self.training is True.
  
  Disclaimer: This wrapper assumes inputs will have shape [nbatch, ndim].
  For models that operate on images, you will need to wrap the function
  inside a reshaper.  See NESAttack for an example.
  
  :param func: A blackbox function.
      - This function must accept, and output, torch tensors.
class_docstr_tok: ["Define","a","backward","pass","for","a","blackbox","function","using","extra","queries",".","Once","wrapped",",","the","blackbox","function","will","become","compatible","with","any","attack","in","Advertorch",",","so","long","as","self.training","is","True",".","Disclaimer",":","This","wrapper","assumes","inputs","will","have","shape","[","nbatch",",","ndim","]",".","For","models","that","operate","on","images",",","you","will","need","to","wrap","the","function","inside","a","reshaper",".","See","NESAttack","for","an","example",".",":","param","func",":","A","blackbox","function",".","-","This","function","must","accept",",","and","output",",","torch","tensors","."]
code: def __init__(self, func):
      super().__init__()
      self.func = func
  
      class _Func(torch.autograd.Function):
          @staticmethod
          def forward(ctx, input):
              # grad_est does not require grad
              output = self.func(input)
              grad_est = self.estimate_grad(input)
              ctx.save_for_backward(grad_est)
              return output
  
          @staticmethod
          def backward(ctx, grad_output):
              # Note: this is not general! May not work for images
              # Be careful about dimensions
              (grad_est,) = ctx.saved_tensors
              grad_input = None
  
              if ctx.needs_input_grad[0]:
                  grad_input = torch.bmm(
                      grad_output.unsqueeze(1), grad_est
                  )
                  grad_input = grad_input.squeeze(1)
              return grad_input
  
      self.diff_func = _Func.apply
  
file_path: advertorch/advertorch/attacks/blackbox/estimators.py
imports: import torch
  import numpy
label_desc: Use image node_id 1 to create a new GradientWrapper object from inherited base classes: torch.nn with example: obj = GradientWrapper(func)