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 119 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 ⚠️
ext/TensorOperationsChainRulesCoreExt.jl 0.00% 3 Missing ⚠️
src/implementation/abstractarray.jl 0.00% 3 Missing ⚠️
Files with missing lines Coverage Δ
src/TensorOperations.jl 100.00% <ø> (ø)
ext/TensorOperationsChainRulesCoreExt.jl 0.00% <0.00%> (ø)
src/implementation/abstractarray.jl 77.58% <0.00%> (-4.24%) ⬇️
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 :)

Comment on lines 56 to 59
if Tα == Zero && Tβ == Zero
scale!(dC, zero(TC))
return ntuple(i -> NoRData(), 12)
end
Copy link
Member

Choose a reason for hiding this comment

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

Is it worth special casing this? Without this, I think you still get the correct result, only less efficiently. But this case should probably never happen anyway.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree it should not happen but in case it does, why not exit early and save some cycles?

@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!

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