Skip to content

Conversation

@kshyatt
Copy link
Member

@kshyatt kshyatt commented Jan 12, 2026

Reimplements many of the rules (I couldn't get the automated importer to work well) using Mooncake. Tests currently do not cover complex elements as I need to make a quick PR to StridedViews first, once that is done, I will enable the tests here.

@kshyatt kshyatt requested review from Jutho and lkdvos January 12, 2026 18:56
@codecov
Copy link

codecov bot commented Jan 12, 2026

Codecov Report

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

Files with missing lines Patch % Lines
...erationsMooncakeExt/TensorOperationsMooncakeExt.jl 0.00% 102 Missing ⚠️
src/utils.jl 0.00% 11 Missing ⚠️
Files with missing lines Coverage Δ
ext/TensorOperationsChainRulesCoreExt.jl 0.00% <ø> (ø)
src/TensorOperations.jl 100.00% <ø> (ø)
src/utils.jl 0.00% <0.00%> (ø)
...erationsMooncakeExt/TensorOperationsMooncakeExt.jl 0.00% <0.00%> (ø)
🚀 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 12, 2026

Should help with #237

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.

Nice work, looks like things are coming together!

We can go over it in a bit more detail in the coming week, but I already have some global comments.

First, I think this is missing the allocator argument right now, which will typically be filled in by the macro calls. Since this shouldn't be differentiated that's not too hard to add, but there are some interesting questions surrounding how to handle how temporaries are dealt with.
For example, I know that for chain rules we effectively have to disable marking intermediates as temporary, which we don't need to do here, but there might be some complications if the allocator is a preallocated buffer for example?

A secondary question is just about code organizing, where all of the indexing logic is now duplicated in 3 places- chain rules, mooncake rules and TensorKit rules. There might be some argument for defining pullbacks that can be shared, similar to how matrixalgebrakit handles this. (However, as I'm typing this, I also don't think we should block this progress because of that)

@lkdvos
Copy link
Member

lkdvos commented Jan 13, 2026

Also, would you mind splitting of the minimal supported version increase in a separate PR? I think this is a good change in any case, but then I can also update the branch protection rules separately

@kshyatt
Copy link
Member Author

kshyatt commented Jan 13, 2026

A secondary question is just about code organizing, where all of the indexing logic is now duplicated in 3 places- chain rules, mooncake rules and TensorKit rules. There might be some argument for defining pullbacks that can be shared, similar to how matrixalgebrakit handles this. (However, as I'm typing this, I also don't think we should block this progress because of that)

I agree with the conclusion here but (you're probably tired of hearing this) we should open an issue. I tried to move some of the logic into the src/utils.jl to be shared by ChainRules, Mooncake, and (soon) Enzyme, but certainly more can be done there.

@kshyatt
Copy link
Member Author

kshyatt commented Jan 13, 2026

Also, would you mind splitting of the minimal supported version increase in a separate PR? I think this is a good change in any case, but then I can also update the branch protection rules separately

#241

@kshyatt kshyatt requested a review from lkdvos January 13, 2026 14:19
@kshyatt
Copy link
Member Author

kshyatt commented Jan 13, 2026

@lkdvos is this then good to go?

@Jutho
Copy link
Member

Jutho commented Jan 13, 2026

Can I take a quick look? Maybe a good way to refresh my Mooncake understanding.

@kshyatt
Copy link
Member Author

kshyatt commented Jan 13, 2026

Can I take a quick look? Maybe a good way to refresh my Mooncake understanding.

Please do! We have freedom of information on this PR :)

@Jutho
Copy link
Member

Jutho commented Jan 13, 2026

Great PR, I still find Mooncake easier to read than Enzyme.

@Jutho
Copy link
Member

Jutho commented Jan 13, 2026

Good te merge for me (if CI passes)

Jutho
Jutho previously approved these changes Jan 13, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Jan 14, 2026

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

@Jutho
Copy link
Member

Jutho commented Jan 14, 2026

One final comment and a question. Otherwise this is ready I think.

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.

Overall looks really good, I only have one final annoying thing that we should probably discuss how to deal with.
Bringing up the allocator again (I know, apologies), the thing I'm slightly worried about is introducing silent mistakes in our generic rules because we might be intercepting too many signatures.
For example, in the Bumper extension we are simply passing a buffer as allocator argument, which will be modified, but the contributions are completely discarded.
In principle, if you then use the state of that buffer, this would now give wrong results (although it might be fair that you shouldn't ever do this but oh well).

This might not even be an issue, since it might be reasonable to claim that a cost function should never depend on the state of some caches anyways, but these are quite hard to catch silent bugs, so perhaps we should extend the docs section and make note of this?

Otherwise happy to merge this!

@kshyatt
Copy link
Member Author

kshyatt commented Jan 15, 2026

This might not even be an issue, since it might be reasonable to claim that a cost function should never depend on the state of some caches anyways, but these are quite hard to catch silent bugs, so perhaps we should extend the docs section and make note of this?

I agree that we should document and possibly revisit this (maybe not using the Varargs?) -- do you think it's a blocker to merge this or should we add the doc note now so we don't forget?

@lkdvos
Copy link
Member

lkdvos commented Jan 15, 2026

I think it might be nice to just add a cautionary note in the docs for this. I'm definitely happy with not blocking this until we have a grasp of whether or not this is important, but I also really want to have this written down somewhere to avoid someone else using this and getting unexpected results without us having somewhere to point to like "you've been warned" 😉

@kshyatt
Copy link
Member Author

kshyatt commented Jan 15, 2026

Since you're more familiar with the TO docs, do you have a suggested place to put the warning? Feel free to just push a commit if you want.

lkdvos
lkdvos previously approved these changes Jan 15, 2026
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.

Spotted a typo in my own previous text, otherwise good to go from my end!

@kshyatt kshyatt enabled auto-merge (squash) January 15, 2026 10:56
@kshyatt
Copy link
Member Author

kshyatt commented Jan 15, 2026

We may need to bypass merge here also because the GPU runners are having a very sad day

@Jutho Jutho disabled auto-merge January 15, 2026 12:51
@Jutho Jutho merged commit 22ef6dc into master Jan 15, 2026
11 of 12 checks passed
@Jutho Jutho deleted the ksh/mooncake branch January 15, 2026 12:51
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.

4 participants