Skip to content

Einsum, initial PR#2265

Closed
HubertKrawczyk wants to merge 32 commits into
apache:mainfrom
HubertKrawczyk:einsum
Closed

Einsum, initial PR#2265
HubertKrawczyk wants to merge 32 commits into
apache:mainfrom
HubertKrawczyk:einsum

Conversation

@HubertKrawczyk

@HubertKrawczyk HubertKrawczyk commented May 18, 2025

Copy link
Copy Markdown
Contributor

This PR introduces initial version of einsum operator to SystemDS.
Einsum operator follow structure of Numpy einsum https://numpy.org/doc/stable/reference/generated/numpy.einsum.html

For tests, R package einsum https://cran.r-project.org/web/packages/einsum/einsum.pdf is used

The aim is to use codegen to potentially fuse multiple operations together.
Fusion is not implemented yet.

Implemented so far:

  • validation of einsum instruction
  • preprocessing: simplifying inputs by contracting dimensions that can be contracted at the beginning
  • preprocessing: identifying diagonal of matrix
  • plan generation
  • plan execution using individual operands (matrixMultiply, multiply, transpose, sumR, sumC, sumAll)
  • (plan execution using codegen TODO)
  • fallback: Cell template with for-loops for einsums that cannot be solved using further 2D summations (e.g AB,BD->ABD)

(M Thesis at TU Berlin "Efficient Einstein Summation in Apache SystemDS")

@HubertKrawczyk HubertKrawczyk changed the title WIP: Einsum [WIP]: Einsum May 19, 2025
@HubertKrawczyk HubertKrawczyk changed the title [WIP]: Einsum Einsum Jun 26, 2025
@HubertKrawczyk HubertKrawczyk changed the title Einsum Einsum, initial PR Jun 26, 2025
@HubertKrawczyk

Copy link
Copy Markdown
Contributor Author
ERROR: R has ended irregularly
R Standard output :

R Standard Error  :
Error in library("einsum") : there is no package called ‘einsum’
Execution halted

@Baunsgaard Would it be possible to install the R einsum package on the build server?

@Baunsgaard

Copy link
Copy Markdown
Contributor
ERROR: R has ended irregularly
R Standard output :

R Standard Error  :
Error in library("einsum") : there is no package called ‘einsum’
Execution halted

@Baunsgaard Would it be possible to install the R einsum package on the build server?

yes, but preferably no. Is the operation you want to import easy to write in R linear algebra?

@HubertKrawczyk

Copy link
Copy Markdown
Contributor Author
ERROR: R has ended irregularly
R Standard output :

R Standard Error  :
Error in library("einsum") : there is no package called ‘einsum’
Execution halted

@Baunsgaard Would it be possible to install the R einsum package on the build server?

yes, but preferably no. Is the operation you want to import easy to write in R linear algebra?

For some easy operations such as matrix multiplications - yes, for more complex chains it can be hard to write, unreadable and easy to do mistakes. And finally there can be some special ones that cannot be solved using 2D matrix operations e.g. 'fx,fg,fz,xg,zx,zg->g' (test 11) (the first intermediate would be 3 dimensional matrix) so the only option would be 4 for loops:

for (g in 1:G) {
  sum_val <- 0
  for (f in 1:F) {
    for (x in 1:X) {
      for (z in 1:Z) {
        sum_val <- sum_val +
          fx[f, x] *
          fg[f, g] *
          fz[f, z] *
          xg[x, g] *
          zx[z, x] *
          zg[z, g]
      }
    }
  }
  out[g] <- sum_val
}

so if we don't want the package then this can be solution, but I think it would be just more readable with a simple einsum call

@Baunsgaard

Copy link
Copy Markdown
Contributor

Okay, feel free to assume that we installed the einsum package, and we will add it to the image soon.

@mboehm7

mboehm7 commented Aug 20, 2025

Copy link
Copy Markdown
Contributor

Hi @HubertKrawczyk - could you please rebase this PR to main, unfortunately I'm getting lots of merge conflicts, and I would be afraid of corrupting existing or your code. Maybe the easiest would be to take your code and create a new PR without these cross-merge commits. Once the commit is prepared I will merge it in, but remove the einsum tests from our github workflow actions until the docker container is including the respective R package.

@HubertKrawczyk

Copy link
Copy Markdown
Contributor Author

Hi @HubertKrawczyk - could you please rebase this PR to main, unfortunately I'm getting lots of merge conflicts, and I would be afraid of corrupting existing or your code. Maybe the easiest would be to take your code and create a new PR without these cross-merge commits. Once the commit is prepared I will merge it in, but remove the einsum tests from our github workflow actions until the docker container is including the respective R package.

Hi @mboehm7 , sure - here is link to new MR: #2312
I did rebase and removed the workflow tests step

@github-project-automation github-project-automation Bot moved this from In Progress to Done in SystemDS PR Queue Aug 20, 2025
mboehm7 pushed a commit that referenced this pull request Aug 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants