class_docstr: Custom checkpointed function to compute the target score.
class_docstr_tok: ["Custom","checkpointed","function","to","compute","the","target","score","."]
docstr: Forward and backward again, assign or accumulate the gradients.
docstr_tok: ["Forward","and","backward","again",",","assign","or","accumulate","the","gradients","."]
code: def backward(ctx: Any, *args: Any) -> Any:
      """Forward and backward again, assign or accumulate the gradients."""
      if DEBUG and dist.is_initialized() and dist.get_rank() == 0:
          print("DEBUG target bwd")
      assert len(args) == 1
      i, w, target = ctx.saved_tensors
      assert i.requires_grad
      assert w.requires_grad
      assert not target.requires_grad
      i = i.detach().requires_grad_(True)
      w = w.detach().requires_grad_(True)
      with torch.enable_grad():
          scores = TargetScoreFunction.get_target_score(
              i,
              w,
              target,
              ctx.kernel_obj.fp_target,
              ctx.kernel_obj.margin,
              ctx.kernel_obj.scale,
          )
      torch.autograd.backward(scores, *args)
      if ctx.kernel_obj.proj_weight.grad is not None:
          # This means we accumulate full grad between iters. Not memory efficient.
          ctx.kernel_obj.proj_weight.grad.add_(w.grad)
      else:
          ctx.kernel_obj.proj_weight.grad = w.grad
      return i.grad, None, None, None
  
imports: from typing import Any, Optional, Tuple
  import torch
  from torch import nn
  import torch.distributed
  import torch.nn.functional
label_desc: Use image node_id 3 for calling the TargetScoreFunction obj's underlying member method code with example usage: obj.backward(ctx) and returns: i,  None,  None,  None