Open pimdh opened 1 year ago
opt_einsum
isn't natively aware of broadcasting rules and likely gets a bit confused on the size of the dimension (i_dim=32
). Likely the easiest way to solve this is with preprocessing as seen in https://github.com/dgasmith/opt_einsum/issues/114.
Hi, I'm not sure if there's an immediate solution possible, but it seems like opt_einsum first considers broadcasting, then optimizes the contraction path. This leads to sub-optimal results:
Gives
We see that in the first case, the third tensor is broadcasted to (b, 32) and then the optimizer decides it's best to contract the latter two tensors. Ideally, we'd strip off the to-be-broadcasted dim from the third tensor, which allows for a much faster computation, as shown in the second case.
Any ideas on how this could be addressed? I understand that this doesn't involve just choosing a contraction path, so might not be solvable by this library. Thanks!