Skip to content

Conversation

@TheRealMichaelWang
Copy link
Collaborator

  • Added support for GetAttribute Einsum AST Node
    • Currently supports shape, elems, and coords which query attributes from sparse tnesors
    • Has a dim field which is required for some queries
  • Added support for indirect access
    • Includes support for indirect access with one index-operand (i.e. B[ACoords[k]])
    • Includes support for mixing indirect accessors and regular indices (i.e. B[AcoordsI[k], j])

* Uses COO internally
* Lookup is currently naive and O(n)
* Get Attribute is a general purpose node that can be used to retreive the coordinate and element arrays from a sparse tensor
* Currently only supports querying the non-zero elements/data array of a sparse tensor and querying the coordinate array (either for all indicies or a specified dimension
* Currently requires the number of input indicies to match the number of dimensions of a tensor
…[B], where B is a 2d array where each row is an index, and each col represents a different dimension for that index
…ensions for indirect access, ensuring compatibility with parent indices.
…eduction in the einsum interpreter, enhancing tensor evaluation and index handling.
…uction operations, enhancing tensor evaluation and index management. Updated assertions and added context for evaluation, ensuring proper handling of output tensors.
Copy link
Member

@willow-ahrens willow-ahrens left a comment

Choose a reason for hiding this comment

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

Great work, thanks! My first request: Please rename to GetAttr (like it is in FinchAssembly, FinchNotation). Additionally, please just use e.g. coords3 rather than coords, 3, to keep a uniform interface to attributes in finch-lite. Once you've fixed this I'll take another look.

…preter, raising a NotImplementedError for unsupported operations. This change is temporary, and is simply for the purpose for a PR and version control
…mensions during tensor permutation. Updated test to flatten the result of multiplication for sparse tensors.
…iplication without indirect assignment in einsum functionality.
Implemented multiple test cases for indirect elementwise addition, multiple reads, operations with constants, nested operations, and direct access only. These tests enhance coverage for the einsum functionality, ensuring proper handling of sparse tensors and indirect indexing.
…add extensive tests for various indirect indexing scenarios. This includes double, triple, and mixed direct/indirect indexing cases, ensuring robust handling of sparse tensors and arithmetic operations.
…nd tensor reshaping. Introduced flattening for index evaluations, optimized axis reordering, and ensured compatibility with parent indices. Updated tests to reflect changes in expected behavior for sparse tensor operations.
…o streamline indirect indexing logic. This change simplifies the code and maintains the integrity of index assertions.
…rating ein.Index and indirect access positions. Improved cartesian product computation and reshaping of tensors, ensuring correct handling of index sizes. Updated tests to reflect changes in expected behavior for indirect indexing scenarios.
…Index and indirect access positions. Enhanced cartesian product computation and index size tracking, ensuring accurate evaluation of tensor indices. Updated logic for processing indirect accesses and their dependencies on true indices.
…ng logic. Improved handling of parent indices for both ein.Index and indirect access, optimizing cartesian product computation and index size tracking. Streamlined the process of building index combinations for tensor evaluation.
@TheRealMichaelWang
Copy link
Collaborator Author

Great work, thanks! My first request: Please rename to GetAttr (like it is in FinchAssembly, FinchNotation). Additionally, please just use e.g. coords3 rather than coords, 3, to keep a uniform interface to attributes in finch-lite. Once you've fixed this I'll take another look.

I renamed GetAttribute to GetAttr. But I am not sure if removing the dim: int field from the Einsum GetAttr is a good idea or not. The dim field is particularly important for the shape query. This is useful to get the size of a specific axis/dimension, which is required for calculating the size of the reduced fiber when lowering from regular einsums to indirect einsums.

Furthermore querying coords as a hardcoded value like coords3 will greatly limit the type of einsums one can write.

…g logic. Consolidated steps for handling unique parent indices and optimized meshgrid creation for index combinations. Enhanced final shape calculation and tensor permutation to ensure accurate evaluation of tensor expressions.
@TheRealMichaelWang TheRealMichaelWang changed the title Add Support for GetAttribute and Indirect Access/Assignment to Einsum Interpreter Add Support for GetAttribute and Indirect Access to Einsum Interpreter Nov 23, 2025
@TheRealMichaelWang TheRealMichaelWang self-assigned this Nov 23, 2025
@TheRealMichaelWang
Copy link
Collaborator Author

I have greatly implemented the implementation for all cases of ein.Access.

  • There are now only two cases to handle ein.Access
    • One case for handling one giant index tensor that covers all dimensions of the tensor being accessed
    • A greatly simplified ein.Access that handles multiple indices mixed with indirect and direct accesses.

The new implementation is slightly longer than 10 lines/statements (it clocks in at 13 statements), but avoids any meshgrid calls, and does so recursively (like A[B[i], j, C[i]] -> A2[i, j])

Essentially, while an ein.Access has any indirect access indices.

  • We find the first indirect access index and collect all associated indices (which share the same top level iterator).
  • We use those indices to metaphorically "shave" off fibers in the tensor.
  • Given the smaller tensor, we replace the set of current indices with the top level iterator index
  • Repeat until no indirect accesses remain; then proceed with permuting and expanding dimensions as the old ein.Access did

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.

3 participants