Forward and reverse Enzyme rules and tests for TensorOperations#451
Draft
kshyatt wants to merge 3 commits into
Draft
Forward and reverse Enzyme rules and tests for TensorOperations#451kshyatt wants to merge 3 commits into
kshyatt wants to merge 3 commits into
Conversation
Codecov Report❌ Patch coverage is
... and 17 files with indirect coverage changes 🚀 New features to boost your workflow:
|
Jutho
reviewed
Jun 18, 2026
Member
Author
|
Good points on both. I’ve tried moving the shared functions into the main
part of TK and encountered very strange errors (also for Mooncake) that I
punted on investigating too hard. I can try asking enzyme to generate its
own rules but given that wasn’t a blocker for the Mooncake version I’d be
ok with keeping this for now so at least something is working, then
iteratively pruning both sets of roles back.
…On Thu, Jun 18, 2026 at 11:01 AM Jutho ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In ext/TensorKitEnzymeExt/tensoroperations.jl
<#451 (comment)>
:
> +function blas_contract_pullback_ΔA!(
+ ΔA, ΔC, A, pA, B, pB, pAB, α, backend, allocator
+ )
+ ipAB = invperm(linearize(pAB))
+ pΔC = _repartition(ipAB, TO.numout(pA))
+ ipA = _repartition(invperm(linearize(pA)), A)
+
+ tB = twist(
+ B,
+ TupleTools.vcat(
+ filter(x -> !isdual(space(B, x)), pB[1]),
+ filter(x -> isdual(space(B, x)), pB[2])
+ ); copy = false
+ )
+
+ project_contract!(
+ ΔA,
+ ΔC, pΔC, false,
+ tB, reverse(pB), true,
+ ipA, conj(α), backend, allocator
+ )
+
+ return nothing
+end
These generic rules should probably appear somewhere more centrally, in
the main TensorKit module? Also, same question as always: do we really need
to redefine all these rules? Can't AD do this for us, using only the rules
for the lower level primitives?
—
Reply to this email directly, view it on GitHub
<#451?email_source=notifications&email_token=AAGKJY7XTXYHV5EXTFC7E4D5AOVUXA5CNFSNUABKM5UWIORPF5TWS5BNNB2WEL2QOVWGYUTFOF2WK43UKJSXM2LFO4XTINJSGMZTGMBQGM22M4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2KYZTPN52GK4S7MNWGSY3L#pullrequestreview-4523330035>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAGKJY6PUDFHVQ5BOM72MNL5AOVUXAVCNFSNUABFKJSXA33TNF2G64TZHMYTANJXGAYDAMZRHNEXG43VMU5TINRUG44TCMBZGEY2C5QC>
.
Triage notifications, keep track of coding agent tasks and review pull
requests on the go with GitHub Mobile for iOS
<https://github.com/notifications/mobile/ios/AAGKJY77N7OUPIT2CQFARP35AOVUXA5CNFSNUABKM5UWIORPF5TWS5BNNB2WEL2QOVWGYUTFOF2WK43UKJSXM2LFO4XTINJSGMZTGMBQGM22M4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2KUZTPN52GK4S7NFXXG>
and Android
<https://github.com/notifications/mobile/android/AAGKJYYST5IMFVJGXE73HI35AOVUXA5CNFSNUABKM5UWIORPF5TWS5BNNB2WEL2QOVWGYUTFOF2WK43UKJSXM2LFO4XTINJSGMZTGMBQGM22M4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2K4ZTPN52GK4S7MFXGI4TPNFSA>.
Download it today!
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.