Repository navigation
feat(kernels): ⚡ contract along opt_einsum's dp paths by default - #73
Merged
Merged
Conversation
SiteKernels now plans every contraction with opt_einsum's "dp" optimizer instead of the default "auto" heuristic, and peak_elements walks the same path, so the planner sizes batches for the path the kernel executes. On an A100, "auto" made the projection kernel cost twice dp's flops and, at the reference bonds, plan an 8.2e9-element intermediate that held the projection batch to 16 rows. With dp the full D_M = 1000 sweep runs 1.95x faster on one GPU and 1.86x on four, with the same batches and outputs equal to rounding. SRC_EINSUM_OPTIMIZE selects another opt_einsum optimizer (e.g. "auto") at import; an unknown name raises ValueError. Documented under large problems. Assisted-by: Claude Code:claude-opus-5-5
Contributor
Add benches/large/bench_einsum_dp.py: kernel timings at the reference shapes (both optimizers in one process, CUDA events, planned peaks), full sweeps with the optimizer of the process, and the QR distance between their outputs. The results of the A100-SXM-64GB runs are in benches/large/README.md. Assisted-by: Claude Code:claude-sonnet-5-5
Panadestein
force-pushed
the
perf/einsum-dp
branch
from
October 27, 2026 10:23
2ff6f48 to
5efda53
Compare
The results live in benches/large/README.md, like the other benches, so the report command, its plotting and the default results folder inside the repository go. The commands write JSON lines under ./einsum_dp instead. Assisted-by: Claude Code:claude-sonnet-5-5
robertodr
reviewed
Oct 27, 2026
robertodr
previously approved these changes
Oct 27, 2026
robertodr
left a comment
Member
There was a problem hiding this comment.
LGTM, wouldn't it be simpler to just add it as an option exposed through the API though (instead of an env-var)? This way whatever new method becomes available in opt-einsum, it could be immediately used, without having to update the PathOptimizer list.
The version of src_method already records the commit and whether the tree was dirty, so the einsum benchmark no longer shells out to git. Assisted-by: Claude Code:claude-sonnet-5-5
Replace the SRC_EINSUM_OPTIMIZE environment variable with an optimize argument on src, apply and compress, defaulting to "dp". It takes any name opt_einsum resolves, including those added with register_path_fn, or a PathOptimizer instance, so new optimizers work without a list to maintain. Validation defers to opt_einsum's own resolver. The value reaches the kernels and the memory plan, so batches are still sized for the path that runs. Assisted-by: Claude Code:claude-opus-5-5
Member
Author
|
🤖 AI text below 🤖 @robertodr Agreed, done in 507b768. The env var is gone. It accepts anything opt_einsum can plan every kernel with:
Booleans and explicit paths are refused with a |
robertodr
approved these changes
Oct 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 AI text below 🤖
What
SiteKernelsplans every contraction with opt_einsum'sdpoptimizer instead of the defaultautoheuristic.peak_elementswalks the same path, so the planner sizes batches for the path the kernel runs. Planner policy and batch rounding are unchanged.src,applyandcompresstakeoptimize(default"dp"): any path optimizer name opt_einsum resolves, including ones added withregister_path_fn, or aPathOptimizerinstance. An unknown name raisesValueError, and anything else raisesTypeError. Documented in Large problems → Contraction paths and the README.benches/large/bench_einsum_dp.py, with the results inbenches/large/README.md(no raw results or job scripts, like the other benches).Why: measured on A100-SXM-64GB, complex128
Full sweep, D_M = 1000, chi_out = 500, 60 GB budget, 3 repeats:
automedian (range)dpmedian (range)dp's planned peaks are lower: 50.3 against 58.8 GB on one GPU, and 12.2 against 32.3 GB per GPU on four.auto's sketch costs 3.9xdp's flops, and its projection 2.0x.Kernels at the reference shapes (D = (4, 4, 4000, 4), eta = 2000):
dphalves the time per row (25.2 → 11.8 ms at 8 rows, 22.1 → 11.0 ms at 16). From 32 rows up,autoplans an 8.2e9-element intermediate (265-283 GB), which holds the planner to 16 rows.dpruns up to 128 rows in 10-25 GB.dpis 3.7-3.8% slower. Its path has only 0.5% fewer flops.dp. Paths are cached persrccall, so a sweep pays 0.03-0.10 s.Not measured: a reference-size sweep. The kernel times reproduce its old right-to-left pass (3140 s estimated, 3112 s measured), and predict about 1.5x with
dp.Testing
pytest -m "not slow": 370 passed and 6 skipped (multi-GPU tests, on one GPU), on a Leonardo A100. The latest run, withoptimizeas an argument, gave 387 passed.auto,greedy, aDynamicProgramminginstance and a registered name give the same result, that invalid values raise through all three entry points, and thatpeak_elementsfollows the optimizer.prek run --all-filespasses.Notes for review
🤖 Generated with Claude Code