I have a bunch of matrices M1, M2, …, Mk in a tensor of shape (k, d, d). I want to compute the matrix product M1 @ M2 @ … @ Mk. This would give an output tensor of shape (d, d). Is there a fast way to do this in PyTorch?

I looked at some questions that claim to be about this How do do matrix multiplication (matmal) along certain axis? and Matrix multiplication along specific dimension , but they seem to be concerned with normal tensor contraction, as can be done with einsum. I don’t think einsum can solve my problem. Or am I missing something?