-
Notifications
You must be signed in to change notification settings - Fork 5
Implement SafeSVD algorithm
#145
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
base: main
Are you sure you want to change the base?
Conversation
|
You shouldn't need to add anything for mooncake btw, the algorithm is marked as a non differentiable type |
|
BTW can this also support the AMD algorithms |
|
any reason why DivideAndConquer and Bisection are left out of: |
|
Oh I got it mixed up, neither gpu library has It might nevertheless be nice to do this in a way that's easily extensible to non LAPACK backends for the future, in case either does add |
Codecov Report❌ Patch coverage is
... and 3 files with indirect coverage changes 🚀 New features to boost your workflow:
|
lkdvos
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given the remark about the GPU implementations, it might really make sense to just spend the time and make it a bit more generic:
struct FallbackAlgorithm{A <: AbstractAlgorithm, B <: AbstractAlgorithm} <: AbstractAlgorithm
alg1::A
alg2::B
end
for f in (:svd_compact, :svd_full)
f! = Symbol(f, :!)
# hijack non-mutating function to avoid double-copy
@eval function $f(A, alg::FallbackAlgorithm)
Ac = copy_input($f, A)
out = initialize_output($f!, A, alg.alg1)
return try
$f!(Ac, out, alg.alg1)
catch
copy!(Ac, A)
$f!(Ac, out, alg.alg2)
end
end
# implement mutating function to make copy
@eval function $f!(A, out, alg::FallbackAlgorithm)
Ac = copy_input($f, A)
return try
$f!(Ac, out, alg.alg1)
catch
$f!(A, out, alg.alg2)
end
end
endI think our implementations of the other functions might even be generic enough to make this "just work".
This also needs some additional tests, and possibly some select_algorithm overloads or additional constructors to make this a bit more convenient
|
Possibly might find some failure cases here: Reference-LAPACK/lapack#672 (comment) |
|
While I am typically among the first to consider possible generalisations, in this case I am not sure if this is really the right approach. In fact, I would go further and say that I think this should probably be called something like |
|
|
When performing a singular value decomposition it can be beneficial to try to use
LAPACK_DivideAndConquerfor its speed but if it fails, use the more stable but slowerLAPACK_QRIterationalgorithm.Thereto I implemented a very minimal
SafeSVDalgorithm that makes an extra copy of the input data, triesLAPACK_DivideAndConqueron the copy, and if it fails performsLAPACK_QRIterationon the original data.Feel free to comment on what other magic functions I need to add to make things like Mooncake happy.
I haven't added any tests yet, does anyone know a pathological matrix that will fail with
YALAPACK.gesdd!but succeed withYALAPACK.gesvd!?