-
Notifications
You must be signed in to change notification settings - Fork 1
Optimize einsum contraction order #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thanks! I suppose that's logarithmic? I feel like Einsum is such a rabbit hole, and the time-to-optimize vs time-to-contract is a tricky dilemma, and I obviously want both to be good. I don't really know how optimized einsum expressions are found/used in practice. Does it get resolved at runtime on every loop or are tensors mostly of fixed size, and it can be optimized by knowing sizes before-hand? Would something like Reactant.jl be able to remove duplicate optimization work, since it compiles functions while keeping track of sizes? Was surprised by how slow e.g. julia> @be optimize_code(ein"ij,jk,j->", Dict('i' => 30, 'j' => 40, 'k' => 20), OMEinsum.TreeSA())
Benchmark: 15 samples with 1 evaluation
min 6.055 ms (605052 allocs: 30.000 MiB, 8.83% gc time)
median 6.772 ms (605052 allocs: 30.000 MiB, 12.98% gc time)
mean 6.857 ms (605052 allocs: 30.000 MiB, 13.93% gc time)
max 7.934 ms (605052 allocs: 30.000 MiB, 19.68% gc time) Inclined to drop einsum in a breaking release, since it would be so difficult to get right, and my main contribution is really my zero-overhead |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #30 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 12 12
Lines 296 313 +17
=========================================
+ Hits 296 313 +17 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Tensor network contraction order are useful when you have 50+ tensors that beyond human capability to do it right. Usually, we have more than 1000+ tensors in many using cases. If you have small nets,
Also, it is deliberately made type unstable, because we have too many array shape combination in a 1000+ size tensor network, type pollution is a much more deadly issue. The only way out is to give up Julia Array, and just use vectors and strides, which takes a lot of time. Practical using cases are needed to make it happen. |
Since
einsum
isn't a generated function, and theOMEinsum
backend is mostly not type stable anyway (under-Peter/OMEinsum.jl#97), array sizes are known. This PR is meant to allow einsum contraction order optimization. I don't know exactly what setsTreeSA
and the different optimizers apart, and I don't know if I'd like them to be user-facing here. Related is #26.Closes #24