We were using einsum from numpy. We have some 2 and 4 (and perhaps 6) dimensional arrays. I'm not sure what happens under the hood, but trying to replicate it explicitly to make some tweaks requires a lot of magic. It was like two year ago, I forgot the details.
Protip: "optimize=True" is equivalent to "optimize='greedy'", but you may prefer "optimize='optimal'" for big cases or use a list precalculated by einsum_path.