Skip to content

Conversation

@kshyatt
Copy link
Member

@kshyatt kshyatt commented Dec 23, 2025

This lets us reuse a lot of the setup infrastructure for ChainRules, Mooncake, and (soon) Enzyme. Also starts testing the AD rules on GPU.

@kshyatt kshyatt requested review from Jutho and lkdvos December 23, 2025 07:58
L = kron(diagm(I_n), A) + kron(adjoint(B), diagm(I_m))
x_vec = L \ -vec(C)
X = CuMatrix(reshape(x_vec, m, n))=#
hX = sylvester(collect(A), collect(B), collect(C))
Copy link
Member Author

Choose a reason for hiding this comment

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

This is very awful but I wasn't able to find a correct way to do it in five minutes so there you go

Copy link
Member

Choose a reason for hiding this comment

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

Is there any chance we could:

  1. open an issue for CUDA and add the link in some comment here
  2. insert a function _sylvester to avoid type piracy

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes to both

Copy link
Member Author

Choose a reason for hiding this comment

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

We should open an issue at AMDGPU also

@github-actions
Copy link

github-actions bot commented Dec 23, 2025

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

@kshyatt kshyatt force-pushed the testsuite-ad branch 2 times, most recently from 0669d08 to 958dd36 Compare December 23, 2025 18:25
@kshyatt kshyatt force-pushed the testsuite-ad branch 6 times, most recently from fad3f4a to daeab4d Compare January 9, 2026 09:52
@codecov
Copy link

codecov bot commented Jan 19, 2026

Codecov Report

❌ Patch coverage is 0% with 111 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/pullbacks/lq.jl 0.00% 30 Missing ⚠️
src/pullbacks/qr.jl 0.00% 30 Missing ⚠️
ext/MatrixAlgebraKitChainRulesCoreExt.jl 0.00% 14 Missing ⚠️
src/pullbacks/svd.jl 0.00% 9 Missing ⚠️
...MatrixAlgebraKitCUDAExt/MatrixAlgebraKitCUDAExt.jl 0.00% 8 Missing ⚠️
src/pullbacks/eig.jl 0.00% 8 Missing ⚠️
src/pullbacks/eigh.jl 0.00% 8 Missing ⚠️
...gebraKitMooncakeExt/MatrixAlgebraKitMooncakeExt.jl 0.00% 3 Missing ⚠️
src/common/defaults.jl 0.00% 1 Missing ⚠️
Files with missing lines Coverage Δ
src/common/defaults.jl 21.42% <0.00%> (-40.11%) ⬇️
...gebraKitMooncakeExt/MatrixAlgebraKitMooncakeExt.jl 0.00% <0.00%> (-99.13%) ⬇️
...MatrixAlgebraKitCUDAExt/MatrixAlgebraKitCUDAExt.jl 55.88% <0.00%> (-7.46%) ⬇️
src/pullbacks/eig.jl 0.00% <0.00%> (-85.06%) ⬇️
src/pullbacks/eigh.jl 0.00% <0.00%> (-80.00%) ⬇️
src/pullbacks/svd.jl 0.00% <0.00%> (-88.34%) ⬇️
ext/MatrixAlgebraKitChainRulesCoreExt.jl 0.00% <0.00%> (-81.82%) ⬇️
src/pullbacks/lq.jl 0.00% <0.00%> (-95.32%) ⬇️
src/pullbacks/qr.jl 0.00% <0.00%> (-95.24%) ⬇️

... and 29 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kshyatt
Copy link
Member Author

kshyatt commented Jan 20, 2026

I think this is ready for review if CI passes, it's not testing the Diagonal stuff for now waiting on @lkdvos 's PR, but it will radically simplify adding tests for that and CUDA and Enzyme

Copy link
Member

@lkdvos lkdvos left a comment

Choose a reason for hiding this comment

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

I left a bunch of smaller comments through the code, and only quickly went through the actual test suites. Am I correct that these haven't changed much?

I think in general it would be nice to try and link some of the GPU issues we are facing with actual issue numbers and resolve them through dispatch alternatives, rather than having to alter the code for regular arrays as well.
In particular, isa(A, Array) seems a bit to strict since we also support views etc, which would then also take the slow path.

L = kron(diagm(I_n), A) + kron(adjoint(B), diagm(I_m))
x_vec = L \ -vec(C)
X = CuMatrix(reshape(x_vec, m, n))=#
hX = sylvester(collect(A), collect(B), collect(C))
Copy link
Member

Choose a reason for hiding this comment

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

Is there any chance we could:

  1. open an issue for CUDA and add the link in some comment here
  2. insert a function _sylvester to avoid type piracy

MatrixAlgebraKit.default_pullback_gauge_atol(A::AnyCuArray) = MatrixAlgebraKit.iszerotangent(A) ? 0 : eps(norm(CuArray(A), Inf))^(3 / 4)
function MatrixAlgebraKit.default_pullback_gauge_atol(A::AnyCuArray, As...)
As′ = filter(!MatrixAlgebraKit.iszerotangent, (A, As...))
return isempty(As′) ? 0 : eps(norm(CuArray.(As′), Inf))^(3 / 4)
Copy link
Member

Choose a reason for hiding this comment

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

Why was this needed? what breaks if we don't do CuArray.(As')?

Copy link
Member Author

Choose a reason for hiding this comment

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

norm doesn't work for Adjoint{CuArray} for example

Copy link
Member

Choose a reason for hiding this comment

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

Does it help if we use the regular norm instead of the Inf one?

:svd_compact, :svd_trunc, :svd_trunc_no_error, :svd_vals,
:left_polar, :right_polar,
)
copy_f = Symbol(:cr_copy_, f)
Copy link
Member

Choose a reason for hiding this comment

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

Why is this cr_ ? what does that mean?

Copy link
Member

Choose a reason for hiding this comment

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

I think I just got the difference with the mc_ ones, I thought this should all be run in separate modules though so there shouldn't necessarily be any nameclashing here?
I might be missing something though

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes they might be, I gave them different names just to be super clear but I guess it is not so clear 😓

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