Skip to content

Deduplicate SVD rrule and improve pullback inference - #495

Merged
Yue-Zhengyuan merged 12 commits into
QuantumKitHub:mainfrom
Yue-Zhengyuan:codex/svd-rrule-dedup
Nov 18, 2026
Merged

Yue-Zhengyuan merged 12 commits into
QuantumKitHub:mainfrom
Yue-Zhengyuan:codex/svd-rrule-dedup

Conversation

@Yue-Zhengyuan

Copy link
Copy Markdown
Member

No description provided.

@Yue-Zhengyuan Yue-Zhengyuan changed the title Deduplicate rrule for svd_trunc! and svd_trunc_no_error! Deduplicate SVD rrule and improve pullback inference Nov 18, 2026
@Yue-Zhengyuan
Yue-Zhengyuan marked this pull request as ready for review November 18, 2026 08:50
Comment thread src/utility/eigh.jl Resolved
Comment thread src/utility/eigh.jl Resolved
Comment thread src/utility/svd.jl Outdated

function svd_trunc!_full_pullback(ΔUSV′)
ΔUSV = unthunk.(ΔUSV′)
ΔUSV = map(unthunk, ChainRulesCore.backing(ΔUSV′))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know why we need the backing here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using ChainRulesCore

old(Δ) = unthunk.(Δ)
new(Δ) = map(unthunk, ChainRulesCore.backing(Δ))

Δ = Tangent{Any}(
    Thunk(() -> [1.0]),
    2.0,
    Thunk(() -> [3.0]),
    ZeroTangent(),
)

@info typeof(old(Δ))
# Vector{Any}

@info typeof(new(Δ))
# Tuple{Vector{Float64}, Float64, Vector{Float64}, ZeroTangent}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting, did not know! Is this also relevant in the MatrixAlgebraKit/TensorKit implementations?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAK uses unthunk.(ΔUSVᴴ) in several places. Worth investigation.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QuantumKitHub/MatrixAlgebraKit.jl#329

When working on it, 🤖 discovered that one more unthunk inside backing is needed in general.

Comment thread src/utility/svd.jl Resolved
Comment thread src/utility/svd.jl Resolved
@Yue-Zhengyuan
Yue-Zhengyuan enabled auto-merge (squash) November 18, 2026 15:47
@Yue-Zhengyuan
Yue-Zhengyuan merged commit b6e2e48 into QuantumKitHub:main Nov 18, 2026
31 of 32 checks passed
@Yue-Zhengyuan
Yue-Zhengyuan deleted the codex/svd-rrule-dedup branch November 19, 2026 03:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants