Repository navigation
Fix type instabilities in foreachblock - #621
Merged
kshyatt merged 2 commits intoNov 12, 2026
Merged
Conversation
- `foreachblock(f, t, ts...)`: specialize on `ts` and use `map` instead of broadcasting over the heterogeneous tuple of tensors, so the call infers - svd wrappers: same `map` instead of broadcast for the block sectors - `foldright`/`foldleft`: use fresh locals for `b` and `c` so the closures capturing them do not box them Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
|
Not a fan of the inline comments (not sure how helpful they will be in the future) so maybe those could be removed, otherwise LGTM |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
|
Done. Thanks for the comment! |
lkdvos
approved these changes
Nov 11, 2026
Member
|
GPU fails aren't related |
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.
foreachblock(f, t, ts...)with more than one tensor was not type stable:ts...was not specialized on, andblocksectors.(tensors)broadcasts over a heterogeneous tuple, which does not infer. Every call therefore went through dynamic dispatch, including the calls from the factorizations (svd, qr, ...) that loop over blocks with it. The svd wrappers had the same broadcast in their block-sector loop.Changes
foreachblock: annotatets::Vararg{Any, N}so it specializes, and usemapinstead of broadcasting over the tuple of tensors.matrixalgebrakit.jl:map(blocksectors, (t, U, S, Vᴴ))instead ofblocksectors.((t, U, S, Vᴴ)).foldright/foldleft: the loop reassigned the outerbandc, which are captured by theget!closures, so they were boxed. They are now fresh locals inside the loop.Benchmarks
Julia 1.13.3, upstream
main(b5db69b) vs this PR, same fresh environment. Runtime is the minimum over 30 trials, averaged over two runs, forV ⊗ P ← V ⊗ Ptensors withV = U1Space(0 => 3, 1 => 2, -1 => 2),P = U1Space(0 => 1, 1 => 1)andV = SU2Space(0 => 2, 1//2 => 2, 1 => 1),P = SU2Space(1//2 => 1).foreachblock(f, t, U, S, Vᴴ)svd_compact!qr_compact!@tensorcontractionbraidPrecompilation (full TensorKit build) is unchanged within noise (381 s → 364 s, pkgimage 308 MB → 299 MB); in a fresh session, a few MPS-style contractions plus an
svd_compacton spaces/eltypes outside the precompile workload infer fewer frames (403 → 325, 5.1 s → 4.9 s).🤖 Generated with Claude Code