PyTorch builds a graph of operations to do during the backward pass.
To use a more Pythonic notation, you can do:
A = torch.randn(5, 5, requires_grad=True)
B = torch.randn(5, 5, requires_grad=True)
C = A @ B
print(C.grad_fn)

The MmBackward object contains references to A, B (C.grad_fn._saved_self and C.grad_fn._saved_mat2) as well as the instructions how to matrix multiply the Jacobian to a vector in the sense of applying the chain rule (try C.grad_fn(grad_C) with grad_C having the same shape as C).
Best regards
Thomas