I would recommend to use torch.chain_matmul as it should be more efficient.
From the docs:

This product is efficiently computed using the matrix chain order algorithm which selects the order in which incurs the lowest cost in terms of arithmetic operations.