Skip to content

Make the polar AD rules a lot more GPU friendly - #331

Open
kshyatt wants to merge 3 commits into
mainfrom
ksh/polar
Open

kshyatt wants to merge 3 commits into
mainfrom
ksh/polar

Conversation

@kshyatt

@kshyatt kshyatt commented Nov 20, 2026

Copy link
Copy Markdown
Member

After staring at the polar PBs/PFs I convinced myself the input to sylvester is always Hermitian, so we can get away without using the Schur decomposition which GPUs don't support yet. This means we can get away with just using eigh which we do support. For the forward rules I added some logic similar to what we did for QR/LQ and focus only on the gauge invariant part. This also lets us handle rank-deficient inputs which is nice. I didn't go through super intensively to optimize this yet so there may be low hanging performance fruits.

@kshyatt
kshyatt requested a review from Jutho November 20, 2026 10:09
@codecov

codecov Bot commented Nov 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
...ixAlgebraKitAMDGPUExt/MatrixAlgebraKitAMDGPUExt.jl 87.35% <ø> (+2.91%) ⬆️
...MatrixAlgebraKitCUDAExt/MatrixAlgebraKitCUDAExt.jl 100.00% <ø> (ø)
src/MatrixAlgebraKit.jl 100.00% <ø> (ø)
src/common/pullbacks.jl 95.83% <100.00%> (+1.23%) ⬆️
src/pullbacks/polar.jl 100.00% <100.00%> (ø)
src/pushforwards/polar.jl 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread src/common/pullbacks.jl
function _sylvester_psd(U, d, C, tol)
Y = U' * C * U
dd = d .+ transpose(d)
Δ = maximum(abs, (abs.(dd) .< tol) .* Y; init = zero(real(eltype(Y))))

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.

There is a slight mismatch (by a factor of 2) between abs.(dd) .< tol used here, and

isnull = abs.(d) .< tol
isnull .& transpose(isnull)

used in the next function.

Comment thread src/pullbacks/polar.jl

# Extract and check the cotangents
ΔW, ΔP = ΔWP
D, U = eigh_full(P)

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.

One could of course ask the question, if we compute the polar via the svd, then we already have D and U, namely they are the S and V from the SVD. So do we just want to pass these along? Or do we even want pullbacks at all? AD through the primal polar calculation using SVD should yield the correct result.

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.

That's true and I got tunnel vision on the case that needed sylvester because it was really annoying me that we were copying back for that. Maybe we could specialize the AD rule just for non-SVD based polar and see if the AD engine(s) can work out the rest?

This branch has not been deployed

No deployments
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.

2 participants