Conversation
Implements Einstein summation notation (einsum) for NKIPy, supporting: - Matrix multiplication and batch operations (ij,jk->ik, bij,bjk->bik) - Transpose and dimension permutation (ij->ji, ijk->kji) - Reductions and trace operations (ij->, ii->) - Outer products (i,j->ij) - Broadcasting patterns (ij,j->ij) - Complex tensor contractions (ijk,jkl->il) - N-ary operations (i,ij,j->) Implementation decomposes einsum patterns into HLO primitives: - dot_general for contractions - transpose for dimension reordering - reduce for summations - broadcast/multiply for outer products Includes comprehensive tests covering all major einsum patterns and examples demonstrating real-world usage including simplified attention mechanisms.
This script tests various einsum operations using NumPy and NKIPy. It includes matrix multiplication, batch matrix multiplication, dot product, outer product, and more, verifying results against NumPy outputs.
|
Thanks for submitting this PR! The einsum support is actually a long wanted feature! We are reviewing this now and will have feedback by EOW. |
vgene
left a comment
There was a problem hiding this comment.
This overall looks very promising. I'm merging it to a separate branch in the main repo first. It needs a few rounds of refactoring + adding tests.
|
Hi @jlonge4 We will need to
Absolutely feel free to submit more PRs to feat/einsum branch to address any of the above issues. It will eventually be merged onto main when all the issues are addressed. We will work on this as a part of the numpy API coverage improvement, with milestone set to the end of February. |
|
@vgene amazing thanks so much! I look forward to contributing further |
Issue #, if available:
N/A
Description of changes:
Adds support for core Einstein summation patterns and verification utilities.
Added
Verification:
Limitations
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.