Skip to content

Some basic svd forward rules and tests#247

Open
kshyatt wants to merge 14 commits into
mainfrom
ksh/svd_fwd
Open

Some basic svd forward rules and tests#247
kshyatt wants to merge 14 commits into
mainfrom
ksh/svd_fwd

Conversation

@kshyatt

@kshyatt kshyatt commented Jun 8, 2026

Copy link
Copy Markdown
Member

Definitely not optimized...

Comment thread src/pushforwards/svd.jl Outdated
@kshyatt

kshyatt commented Jun 11, 2026

Copy link
Copy Markdown
Member Author

Took another look at this. The Enzyme tests seem to be failing because of finite differences, for svd_full for example when size(A) == (17, 19), the finite differences result for dU is all over the place compared to that from the rule for the section of U which is only present in the full case. I'll try to think of a nice way to handle this, I think it is not occurring for Mooncake because Mooncake uses a different technique for checking against FD.

Comment thread src/pushforwards/svd.jl Outdated
@github-actions

github-actions Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Your PR no longer requires formatting changes. Thank you for your contribution!

Comment thread src/common/initialization.jl Outdated
Comment thread src/pushforwards/svd.jl Outdated
Comment thread src/pushforwards/svd.jl
@Jutho

Jutho commented Jun 15, 2026

Copy link
Copy Markdown
Member

In the gauge fixing parts, we could use more views for the slicing ΔU₁[I] etc, but I did not want to push my luck on the GPU with views into views using CartesianIndices.

@Jutho

Jutho commented Jun 15, 2026

Copy link
Copy Markdown
Member

Anyway, I will leave this aside now for a while and look at some other PRs. In principle, tests can now be expanded to cover the complex case and svd_compact of rectangular matrices as well (but as always, I would only consider double precision for finite difference comparisons).

@lkdvos lkdvos left a comment

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.

Left some final small comments, otherwise good to go?

Comment thread src/pushforwards/svd.jl
Comment on lines +23 to +24
hUᴴΔAV₁ = inv_safe.(transpose(S₁) .- S₁) .* project_hermitian(UᴴΔAV₁)
aUᴴΔAV₁ = inv_safe.(transpose(S₁) .+ S₁) .* project_antihermitian(UᴴΔAV₁)

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.

I think below only the sum and difference are actually used, we could use a kernel like

function _avgdiff!(A::AbstractArray, B::AbstractArray)
axes(A) == axes(B) || throw(DimensionMismatch())
@simd for I in eachindex(A, B)
@inbounds begin
a = A[I]
b = B[I]
A[I] = (a + b) / 2
B[I] = b - a
end
end
return A, B
end
to avoid the two extra allocations, but I'm also happy to just leave them as-is, it's hard to imagine this really making that huge of a difference

Comment thread src/pushforwards/svd.jl
end

function svd_trunc_pushforward!(ΔA, A, USVᴴ, ΔUSVᴴ, ind; rank_atol = default_pullback_rank_atol(A), kwargs...)
# TODO

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.

Probably best to either not define this or explicitly error()?

@kshyatt

kshyatt commented Jun 15, 2026

Copy link
Copy Markdown
Member Author

The GPU tests will probably fail until a new version is tagged at GPUArrays (JuliaGPU/GPUArrays.jl#738)

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