This should do the trick, I think (still learning my ropes around autograd):
B = torch.rand((4, 10), requires_grad=True)
W = torch.rand((20, 10))
A = torch.matmul(B, W.T)

A.backward(gradient=torch.ones_like(A))
B.grad