Same way you debug forwards:
import pdb
pdb.set_trace()

Here’s a more complete snippet:
import torch

class MyLoss(torch.autograd.Function):
  def forward(self, x):
    return x.view(-1).sum(0)
  def backward(self, x):
    import pdb
    pdb.set_trace()
    return x

v = torch.autograd.Variable(torch.randn(5, 5), requires_grad=True)
loss = MyLoss()(v)
loss.backward()