parameters: (self, hook)
return_statement: return handle
docstring: r"""Registers a backward hook.
  
          The hook will be called every time a gradient with respect to the
          Tensor is computed. The hook should have the following signature::
  
              hook(grad) -> Tensor or None
  
  
          The hook should not modify its argument, but it can optionally return
          a new gradient which will be used in place of :attr:`grad`.
  
          This function returns a handle with a method ``handle.remove()``
          that removes the hook from the module.
  
          Example::
  
              >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
              >>> h = v.register_hook(lambda grad: grad * 2)  # double the gradient
              >>> v.backward(torch.tensor([1., 2., 3.]))
              >>> v.grad
  
               2
               4
               6
              [torch.FloatTensor of size (3,)]
  
              >>> h.remove()  # removes the hook
docstring_summary: r"""Registers a backward hook.
docstring_tokens: r Registers a backward hook .
function: def register_hook(self, hook):
          r"""Registers a backward hook.
  
          The hook will be called every time a gradient with respect to the
          Tensor is computed. The hook should have the following signature::
  
              hook(grad) -> Tensor or None
  
  
          The hook should not modify its argument, but it can optionally return
          a new gradient which will be used in place of :attr:`grad`.
  
          This function returns a handle with a method ``handle.remove()``
          that removes the hook from the module.
  
          Example::
  
              >>> v = torch.tensor([0., 0., 0.], requires_grad=True)
              >>> h = v.register_hook(lambda grad: grad * 2)  # double the gradient
              >>> v.backward(torch.tensor([1., 2., 3.]))
              >>> v.grad
  
               2
               4
               6
              [torch.FloatTensor of size (3,)]
  
              >>> h.remove()  # removes the hook
          """
          if has_torch_function_unary(self):
              return handle_torch_function(Tensor.register_hook, (self,), self, hook)
          if not self.requires_grad:
              raise RuntimeError("cannot register a hook on a tensor that "
                                 "doesn't require gradient")
          if self._backward_hooks is None:
              self._backward_hooks = OrderedDict()
              if self.grad_fn is not None:
                  self.grad_fn._register_hook_dict(self)
          handle = hooks.RemovableHandle(self._backward_hooks)
          self._backward_hooks[handle.id] = hook
          return handle
function_tokens: def register_hook ( self , hook ) : if has_torch_function_unary ( self ) : return handle_torch_function ( Tensor . register_hook , ( self , ) , self , hook ) if not self . requires_grad : raise RuntimeError ( "cannot register a hook on a tensor that " "doesn't require gradient" ) if self . _backward_hooks is None : self . _backward_hooks = OrderedDict ( ) if self . grad_fn is not None : self . grad_fn . _register_hook_dict ( self ) handle = hooks . RemovableHandle ( self . _backward_hooks ) self . _backward_hooks [ handle . id ] = hook return handle