Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polynomial evaluation IR #1217

Open
j2kun opened this issue Dec 20, 2024 · 5 comments
Open

Polynomial evaluation IR #1217

j2kun opened this issue Dec 20, 2024 · 5 comments
Labels
dialect: polynomial Issues concerning the polynomial dialect

Comments

@j2kun
Copy link
Collaborator

j2kun commented Dec 20, 2024

As part of the broader polynomial approximation system, we would like to materialize polynomial approximations in the IR.

We should create a polynomial.eval op, which takes as input a static polynomial attribute and an SSA value (AnyType), and semantically this represents the evaluation of the polynomial at the input.

Then we would implement possible lowerings of eval to a sequence of add/mul ops in an appropriate dialect (see below). One lowering would be a Horner's method, while another would correspond to Paterson-Stockmeyer. We'd expect the latter to be more efficient for FHE due to the imbalance in add/mul costs.

We should start by implementing this for integer/float types, with the lowering lower to addi/mui/add/mulf. Ideally we could generalize this to an interface, so that the interface would decide what is the "right" add/mul op to use for a given type. Maybe the interface would be in charge of actually constructing the op in question.

@j2kun
Copy link
Collaborator Author

j2kun commented Feb 26, 2025

Note that polynomial.eval is checked in, and a first pass at polynomial patterns to generate polynomial.eval ops is #1449

After that is in, the remaining work required is to:

  • Add more patterns for special neural network activation functions like ReLU ops, or any more complex patterns that coincide with activation functions we might see (like matching on arith.maximumf 0, %x and similar)
  • Implement the lowering of polynomial.eval using Paterson-Stockmeyer.

I recall @eymay was planning to work on the second bullet. Do you have any updates on that front? We are hoping to include this before a paper submission deadline on April 15, so if you're not able to work on it, one of our other collaborators may take it over.

@j2kun
Copy link
Collaborator Author

j2kun commented Feb 26, 2025

Ah, perhaps it was actually @zmbekdemir who was going to work on Paterson-Stockmeyer?

@zmbekdemir
Copy link
Contributor

@j2kun yes, I am working on it.

@j2kun
Copy link
Collaborator Author

j2kun commented Feb 28, 2025

@j2kun yes, I am working on it.

Would you be so kind as to post a draft PR with your partial work? We are happy to look at it and provide advice.

@zmbekdemir
Copy link
Contributor

@j2kun yes, I am working on it.

Would you be so kind as to post a draft PR with your partial work? We are happy to look at it and provide advice.

I will tidy things up and then I can post a draft PR, it shouldn't really take much time, just a couple days at max.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dialect: polynomial Issues concerning the polynomial dialect
Projects
None yet
Development

No branches or pull requests

2 participants