Fix BufferizationStage IR blowup for runtime-parameterized Hamiltonians (Reroll)#3036
Open
jk20342 wants to merge 10 commits into
Open
Fix BufferizationStage IR blowup for runtime-parameterized Hamiltonians (Reroll)#3036jk20342 wants to merge 10 commits into
jk20342 wants to merge 10 commits into
Conversation
…tonians Add scalarize-tensor-extracts and reroll-loops passes and re-order the default pipeline so runtime-coefficient Trotterization no longer amplifies IR through bufferization (9.9x -> ~1.0x on the H2 QPE benchmark). Fixes PennyLaneAI#2759
…tonians Add scalarize-tensor-extracts and reroll-loops passes and re-order the default pipeline so runtime-coefficient Trotterization no longer amplifies IR through bufferization (9.9x -> ~1.0x on the H2 QPE benchmark). Fixes PennyLaneAI#2759
…tonians Add scalarize-tensor-extracts and reroll-loops passes and re-order the default pipeline so runtime-coefficient Trotterization no longer amplifies IR through bufferization (9.9x -> ~1.0x on the H2 QPE benchmark). Fixes PennyLaneAI#2759
…-loops pass (split from PennyLaneAI#3013) Co-authored-by: Cursor <cursoragent@cursor.com>
Updated pull request reference in changelog.
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.
Context:
qml.TrotterProduct with runtime coefficients (via qml.dot) causes severe IR
amplification: tracing unrolls all Trotter steps, and every gate angle drags a chain of
single-element tensor ops through bufferization, each becoming an alloc plus copies.
For an H2 QPE workload this meant ~62x total IR growth and ~19 GB of compiler memory.
Description of the Change:
New scalarize-tensor-extracts pass: folds tensor.extract through
extract_slice/collapse_shape/small elementwise linalg.generic, turning gate-angle
dataflow into scalar arithmetic.
New reroll-loops pass: detects repeated op sequences via structural hashing and
rebuilds them as scf.for loops.
Default pipeline (HLO stage only): scalarize + linalg-fuse-elementwise-ops before
reroll-loops, and a second scalarize after detensorization (which materializes the
extract chains).
Benefits:
On the H2 QPE benchmark, before/after measured on the same machine, same build, same
input IR, differing only in the pipeline: compile time 1h41m -> ~25s (~240x), peak
memory 15.4 GB -> 1.2 GB (12.8x), final IR 18.4 MB -> 5.4 MB (3.4x), post-bufferization
IR 7.45 MB -> 2.64 MB (2.8x). Output probabilities are bit-identical to the old pipeline.
these baseline numbers differ from the issue report (306 s, 21.3 GB, 241 MB final
IR) because the issue predates current main, which already reduced the
baseline's bufferization blowup (60 MB -> 7.45 MB post-bufferization; input IR drifted
3.86 -> 4.69 MB), and these measurements use an assertions-enabled dev build, ~20x
slower in wall time than the release wheel the issue used. Ratios within this PR are
apples-to-apples; absolute times are not comparable to the issue's.
Possible Drawbacks:
Both passes are conservative (size caps, semantic verification, high min-savings
default) but rerolling may miss non-contiguous repeats; overhead on workloads without
the pattern is negligible.
Related GitHub Issues:
Fixes #2759. Related: #1464, #1507.