-
Notifications
You must be signed in to change notification settings - Fork 64
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
Python Frontend: Use Numba Type Inference #1253
base: main
Are you sure you want to change the base?
Python Frontend: Use Numba Type Inference #1253
Conversation
704f176
to
e4dbe7e
Compare
Sorry for the lack of clean-up/updates on this one, I was feeling a bit under the weather. The big ToDo, as discussed last week, to move from Numba-style inference to something that supports statically shaped tensors is still open, but I did do some other smaller cleanup
Here's a current example: from heir_py import compile
from heir_py.mlir import *
from heir_py.types import *
@compile() # defaults to scheme="bgv"", backend="openfhe", debug=False
def foo(x : Secret[I16], y : I16):
sum = x + y
mul = x * y
expression = sum * mul
return expression
foo.setup() # runs keygen/etc
enc_x = foo.encrypt_x(7)
result_enc = foo.eval(enc_x, 8)
result = foo.decrypt_result(result_enc)
print(f"Expected result for `foo`: {foo(7,8)}, decrypted result: {result}") |
4cb79a7
to
d22470b
Compare
As mentioned in yesterday's meeting, there's been a bit more progress, in addition to what I mentioned above:
Since this PR is getting a bit large already, I'm leaning towards cleaning this up (once #1302 is merged, allowing for full scheme/backend separation) and then making a new PR for the tensor shape inference stuff (which will probably be an MLIR pass after all). |
11a2d35
to
15628c0
Compare
❤️ !! Feel free to clean/split it up as you see fit. I have no problems reviewing a large PR for this one. |
Part of #1105 |
ec7680b
to
c8ab6e5
Compare
This is essentially ready to review, I just need some help getting the test setup working properly, as the e2e test currenlty fails if run via bazel. Since the last update, major changes include
|
@j2kun : let me now if this is too large, and I'll figure out how to split it into more sensible chunks |
The testing issue is because you put the python package one step further nested under Edit: see next comment |
Ohh! Researching this I found on https://bazel.build/reference/be/python
So with this patch I can get it to run in bazel, although the test fails diff --git a/frontend/BUILD b/frontend/BUILD
index 190aee59..342bf248 100644
--- a/frontend/BUILD
+++ b/frontend/BUILD
@@ -34,6 +34,7 @@ py_library(
),
data = DATA_DEPS,
deps = [
+ "@frontend_pip_deps_colorama//:pkg",
"@frontend_pip_deps_numba//:pkg",
"@frontend_pip_deps_pybind11//:pkg",
"@frontend_pip_deps_pybind11_global//:pkg",
diff --git a/frontend/testing.bzl b/frontend/testing.bzl
index 3d24a318..902f7dd6 100644
--- a/frontend/testing.bzl
+++ b/frontend/testing.bzl
@@ -29,6 +29,7 @@ def frontend_test(name, srcs, deps = [], data = [], tags = []):
":frontend",
"@com_google_absl_py//absl/testing:absltest",
],
+ imports = ["."],
data = data,
tags = tags,
env = { Test failure: https://gist.github.com/j2kun/40fe73429938e814cf3b08beb514dd44 |
Awesome, thanks! I just realized the test failure is likely because my current approach still relies on a nasty local patch to numba to support sizes smaller than |
c8ab6e5
to
b444e4c
Compare
Now the bazel tests work locally but fail on the CI, probably because I messed something up with openfhe_config...
I'll look into it tomorrow! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing work!
The command is using That said, I am trying to wrap your |
I was able to figure out why this is: bazel doesn't set the same environment variables for binary targets vs test targets, so I need to add another env var check for |
Thanks for the detailed review and all the bazel-debugging! I'll try and get this pull-ready later today :) |
explicit imports in e2e_test
0872113
to
da20760
Compare
@j2kun: I think everything I was planning to do (and a lot of semi-related QoL things...feature creep I guess 😓) are in now. :) EDIT: I just found one more annoying thing - numba assumes all literal ints are There is one more "QoL" thing I'd love to tackle, and that's the inability to have multiple instances of the frontend/HEIR (the "PublicKey registerd" error), but I think I might need your assistance to tackle that one as it's less about the frontend and more about the bindings. Next steps would be
|
Very much WIP,
This does a few things:
@mlir
decorator that is a slightly modified version of numba's@intrinsic
, with the main difference being that one can provide a pure python implementation and run it under python. This allows us to define, e.g.,linalg.matmul
and assign itnp.matmul
as its python implementation.Secret[...]
), in preparation for grabbing signature types from type annotations (rathter than from a string passed into the decorator, as is Numba's approach for ahead-of-time compilation)PS: fun fact - in numba/numpy world,
i4
is not a 4-bit integer (as in MLIR), but shorthand for the 4-byte typeint32
.