opt_einsum icon indicating copy to clipboard operation
opt_einsum copied to clipboard

Fink optimal path for caching constant intermediates

Open fangzhangmnm opened this issue 2 years ago • 3 comments

For example:

i,ij,jk->k where sizes are [5],[5,100],[100,5], and the second and the third tensor is a constant Then it is a good idea to cache ij,jk->ik

fangzhangmnm avatar Sep 12 '22 01:09 fangzhangmnm

I believe the following will help you: https://dgasmith.github.io/opt_einsum/getting_started/sharing_intermediates/

dgasmith avatar Sep 13 '22 05:09 dgasmith

I meant doing the optimization under the consumption that the constant tensors can be contracted beforehand offline. The above functionality only cache the intermediates, but the path planning might not consider which tensor is a constant

fangzhangmnm avatar Sep 15 '22 01:09 fangzhangmnm

Yes, cache/intermediate aware paths are something we have discussed but have not implemented. It isn't clear that there is a general approach to solve the problem as straightforward approaches become combinatorial in nature.

Happy to take a PR which attempts this functionality!

dgasmith avatar Sep 21 '22 04:09 dgasmith