22/31
Part 5 of 6 · A Linear layer, proved by gradcheckLearn and do

gradcheck proves the backward

One call checks every entry of every gradient.

torch.manual_seed(0)
a = torch.randn(2, 3, 4, dtype=torch.float64, requires_grad=True)
b = torch.randn(4, 5, dtype=torch.float64, requires_grad=True)
print(torch.autograd.gradcheck(MatMul.apply, (a, b)))
True

True means your backward agrees with a numerical estimate at every entry. A wrong one raises a GradcheckError that says where.

In the editor, write check(fn, *shapes): gradcheck on random float64 inputs of the shapes you name.