Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gradient of SVD not working for complex input #1481

Open
GibbsJR opened this issue Dec 20, 2023 · 1 comment
Open

gradient of SVD not working for complex input #1481

GibbsJR opened this issue Dec 20, 2023 · 1 comment
Labels
ChainRules adjoint -> rrule, and further integration

Comments

@GibbsJR
Copy link

GibbsJR commented Dec 20, 2023

Hello,

I am looking to create a function that uses a truncated SVD and take the gradient for a complex input (but has a real output).
I find that with Zygote this works fine for real inputs, but does not work for complex inputs (e.g. if you uncomment the line in the below example), even though I believe Zygote supports gradients of functions on complex inputs.

Please could you suggest how to resolve this.

Thanks,
Joe

using LinearAlgebra, Zygote

X = kron(rand(Float64, 4,4), rand(Float64, 4,4)) + kron(rand(Float64, 4,4), rand(Float64, 4,4))
#X = kron(rand(ComplexF64, 4,4), rand(ComplexF64, 4,4)) + kron(rand(ComplexF64, 4,4), rand(ComplexF64, 4,4))

function foo(X)
    
    F = svd(X)
    
    return abs(sum(F.S[1:2]))
end

G = foo'(X)
@ToucheSir ToucheSir added the ChainRules adjoint -> rrule, and further integration label Dec 20, 2023
@ToucheSir
Copy link
Member

Support for complex inputs is very much a function-by-function thing in Zygote. Some may work without dedicated AD rules, but in the case of svd that likely isn't true. Zygote uses the SVD rule from https://github.com/JuliaDiff/ChainRules.jl and I think that only handles real-numbered inputs, so I'd recommend opening a feature request there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ChainRules adjoint -> rrule, and further integration
Projects
None yet
Development

No branches or pull requests

2 participants