Skip to content

fix: upgrade Mooncake compat to v0.5#961

Merged
gdalle merged 9 commits intomainfrom
gd/mooncake05
Jan 31, 2026
Merged

fix: upgrade Mooncake compat to v0.5#961
gdalle merged 9 commits intomainfrom
gd/mooncake05

Conversation

@gdalle
Copy link
Member

@gdalle gdalle commented Jan 29, 2026

  • Bump Mooncake compat to v0.5.1
  • Take Config as a whole instead of parsing it
  • Remove useless _righttype caches
  • Add tests with StaticArrays for new friendly tangents mode

Supersedes #960

See also chalk-lab/Mooncake.jl#979

Note that this still uses internal conversion machinery from Mooncake

@codecov
Copy link

codecov bot commented Jan 29, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.21%. Comparing base (a266e80) to head (6639952).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #961      +/-   ##
==========================================
- Coverage   98.21%   98.21%   -0.01%     
==========================================
  Files         135      135              
  Lines        8002     7995       -7     
==========================================
- Hits         7859     7852       -7     
  Misses        143      143              
Flag Coverage Δ
DI 98.97% <100.00%> (-0.01%) ⬇️
DIT 96.22% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

@gdalle gdalle marked this pull request as ready for review January 29, 2026 09:38
@Technici4n
Copy link

This is OK but you should at least carry over the dy_righttype changes, it never made sense to do that and breaks friendly tangents.

Copy link

@Technici4n Technici4n left a comment

Choose a reason for hiding this comment

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

I guess this is fine if you just want to get this out of the door!

@gdalle
Copy link
Member Author

gdalle commented Jan 29, 2026

What do you mean by "never really made sense to do that"?

@gdalle
Copy link
Member Author

gdalle commented Jan 29, 2026

Perhaps we should just merge the Mooncake PR and do everything at once

@Technici4n
Copy link

What I mean is that _copy_output is just a copy, it doesn't change the object's type, so I don't understand why it is there unless the intention is specifically to make a copy. This PR is fine and should fix Mooncake CI (including docs).

@AstitvaAggarwal
Copy link
Contributor

looks good, thanks!

@gdalle
Copy link
Member Author

gdalle commented Jan 29, 2026

Let's just get https://github.com/chalk-lab/Mooncake.jl/pull/980/changes merged and we'll clean up the DI bindings as we bump our compat bound to Mooncake v0.5.1

@gdalle
Copy link
Member Author

gdalle commented Jan 30, 2026

So I tracked down the reason behind the existence of dx_righttype and dy_righttype to #513. At first, it was just a way to safeguard against the user providing, say, x::Vector{Float64} and dx::Vector{Float32}, similar to what is done in the Enzyme extension. For lack of friendly tangents infrastructure, the best one could do is make sure that the primal type was equal to the tangent type, and this would work for simple numbers and arrays (which is all I test on).

Initially, this used the handrolled function

copyto!!(dst::Number, src::Number) = convert(typeof(dst), src)
copyto!!(dst, src) = copyto!(dst, src)

But then, in #809, I replaced this function with the one from Mooncake, neglecting the fact that it doesn't accept inputs of different (el)types. Which means the functionality has been essentially useless for a while and we should remove it during the switch to Mooncake 0.5, now that friendly tangents take care of conversion.

@Technici4n
Copy link

I see, that makes sense, thanks for investigating. ^^

@gdalle gdalle marked this pull request as draft January 30, 2026 13:20
@gdalle
Copy link
Member Author

gdalle commented Jan 30, 2026

Tests currently fail in forward mode with friendly tangents and in-place function because the dy provided by the user is not necessarily the one that gets modified. I think I have to use the same trick as for reverse mode and define a new

f!_with_return(y, x) = begin
    f!(y, x)
    return y
end

@gdalle gdalle linked an issue Jan 31, 2026 that may be closed by this pull request
@gdalle gdalle merged commit bf17102 into main Jan 31, 2026
68 of 69 checks passed
@gdalle gdalle deleted the gd/mooncake05 branch January 31, 2026 22:40
@sunxd3
Copy link

sunxd3 commented Feb 1, 2026

Thanks for the work!

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.

Mooncake Backend doesn't handle functions with StaticArrays output

4 participants