Repository navigation
Conversation
LucaLM02
force-pushed
the
fix/14-gpu-round-trip
branch
from
October 6, 2026 14:26
84b32df to
8ba3ed8
Compare
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The two-site fallback still round-trips GPU data through the host, and the GPU SVD path lacks direct coverage.
Review effort: Balanced
Findings: 1
Open (3)
What changed in this PR
Moves GPU SVD work and optional outputs fully onto the selected device.
Changes:
- Adds
to_hostto public compression APIs. - Runs truncated SVD through the active array backend.
- Adds GPU output and chaining tests.
| File | Description |
|---|---|
src/src_method/apply.py |
Exposes to_host for application results. |
src/src_method/compress.py |
Exposes to_host for compression results. |
src/src_method/stack.py |
Propagates output-device selection. |
src/src_method/_sweep.py |
Avoids unconditional host conversion. |
src/src_method/utils/linalg.py |
Runs truncation SVD on the active backend. |
tests/test_gpu_backend.py |
Tests GPU-backed outputs and chaining. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+111
to
+112
| result = exact_stack(layers, chi_out, kind) | ||
| return result if to_host else [xp.asarray(t) for t in result] |
| Returns: | ||
| The site arrays of the compressed train in right-canonical form, as numpy | ||
| arrays. | ||
| arrays if ``to_host`` is ``True``, otherwise as arrays of ``xp``.. |
| Q, R = xp.linalg.qr(matrix.T if transpose else matrix) | ||
| R_np = R.get() if hasattr(R, "get") else np.asarray(R) | ||
| U, S, _ = np.linalg.svd(R_np.T if transpose else R_np, full_matrices=False) | ||
| U, S, _ = xp.linalg.svd(R.T if transpose else R, full_matrices=False) |
This branch has not been deployed
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.


Summary
Keeps data on the GPU on the
device="gpu"path (closes #14 ) :xp.linalg.svd) instead of copyingRto the host with.get()and callingnp.linalg.svd.to_host: bool = Trueargument onapply/compress. Withto_host=Falsethe result stays backed by CuPy arrays and can be fed straight into the next call without a device/host round trip. The default preserves the previous behaviour, so existing callers are unaffected.Performance
Measured on Google Colab:
fe1779b(main), after =fbec6ae(this branch)Method:
complex128,seed=0, random MPO × MPS, 20 sites,phys_dim=4, median of 10 runs. Each path is warmed up first, andbefore/afterare timed in separate processes on the same session.chi_out = 64(input bond dim 64)main)to_host=Trueto_host=Falseapplyapplychi_out = 128(input bond dim 128, after only)to_host=Trueto_host=FalseapplyapplyTesting
apply(..., to_host=False)calls accept CuPy inputs and run without host round trips of the result.Acceptance criteria
.get()/ D2H transfer inside the per-site loopapplycalls do not round-trip the result through host memory