class_docstr: Wrapper which allows computing sample-wise gradients in a single backward pass.
  
  This is accomplished by adding hooks to capture activations and output
  gradients for supported modules, and using these activations and gradients
  to compute the parameter gradients per-sample.
  
  Currently, only nn.Linear and nn.Conv2d modules are supported.
  
  Similar reference implementations of sample-based gradients include:
  - https://github.com/cybertronai/autograd-hacks
  - https://github.com/pytorch/opacus/tree/main/opacus/grad_sample
class_docstr_tok: ["Wrapper","which","allows","computing","sample-wise","gradients","in","a","single","backward","pass",".","This","is","accomplished","by","adding","hooks","to","capture","activations","and","output","gradients","for","supported","modules",",","and","using","these","activations","and","gradients","to","compute","the","parameter","gradients","per-sample",".","Currently",",","only","nn.Linear","and","nn.Conv2d","modules","are","supported",".","Similar","reference","implementations","of","sample-based","gradients","include",":","-","https",":","\/\/github.com\/cybertronai\/autograd-hacks","-","https",":","\/\/github.com\/pytorch\/opacus\/tree\/main\/opacus\/grad_sample"]
code: def remove_hooks(self) -> None:
      self.hooks_added = False
  
      for hook in self.forward_hooks:
          hook.remove()
  
      for hook in self.backward_hooks:
          hook.remove()
  
      self.forward_hooks = []
      self.backward_hooks = []
  
imports: from collections import defaultdict
  from enum import Enum
  from typing import cast, DefaultDict, Iterable, List, Optional, Tuple, Union
  import torch
  from captum._utils.common import _format_tensor_into_tuples, _register_backward_hook
  from torch import Tensor
  from torch.nn import Module
label_desc: Use image node_id 6 for calling the SampleGradientWrapper obj's underlying member method code with example usage: obj.remove_hooks() without return types