-
Notifications
You must be signed in to change notification settings - Fork 159
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
feat: Add tfhe-rs compatibility for model inputs /outputs #997
base: main
Are you sure you want to change the base?
Conversation
@@ -506,9 +514,33 @@ def _get_module_to_compile(self) -> Union[Compiler, QuantizedModule]: | |||
Union[Compiler, QuantizedModule]: The module instance to compile. | |||
""" | |||
|
|||
def _get_tfhres_module_to_compile(self, inputset): |
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.
typo? tfhres -> tfhers
# For now, use the virtual library when simulating | ||
# circuits that use CRT encoding because the official simulation is too slow | ||
# FIXME: https://github.com/zama-ai/concrete-ml-internal/issues/4391 | ||
if USE_OLD_VL or is_crt_encoding: |
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.
I didn't know USE_OLD_VL what still there
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.
it's disabled but still there
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.
is there a reason to keep it? do you still use it? (I guess it's not tested so certainly, soon, it's no more working, anyway)
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.
Old vl is simply CP graph execution, so it is tested in Concrete. but you're right in the sense that we could easily remove it - we kept it thinking it might be useful at some point, but it's not anymore
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.
it is tested in Concrete
I don't know if they still test it. At some point, they'll certainly remove it as well
tests/sklearn/test_sklearn_models.py
Outdated
model.compile(x) | ||
|
||
# Check correctness with TFHE-rs inputs/outputs | ||
assert numpy.all(y_pred_tfhers == y_pred_disable) |
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.
shouldn't you also test vs purely concrete results?
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.
fhe results (with tfhers inputs) should be equal disable for default p_error. Other tests check that concrete fhe and disable are also equal to disable. using fhe=disable here makes this test faster, it's already quite a slow one
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.
I have not understood your answer.
My question is: do we test that results with results "with Concrete format" and "with TFHE-rs format" are the same? (either in simulate or in FHE). If we have that + existing tests that results in TFHE-rs are equivalent in simulate and fhe, that's fine with me.
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.
we compare tfhe-rs inputs vs disable in this test and we compare concrete inputs vs simulate and disable in other tests.
src/concrete/ml/sklearn/base.py
Outdated
def compile( | ||
self, | ||
X: Data, | ||
ciphertext_format: CiphertextFormat = CiphertextFormat.CONCRETE, |
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.
can you allow simple string like we do for fhe arg? e.g. I would like to call compile with model.compile(X, ciphertext_format="tfhe-rs")
q_y_pred_list = [] | ||
for q_X_i in q_X: | ||
# Expected encrypt_run_decrypt output shape is (1, n_features) while q_X_i | ||
# is of shape (n_features,) | ||
q_X_i = numpy.expand_dims(q_X_i, 0) |
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.
wasn't this necessary?
|
||
# Check that we can first compile to Concrete, then to | ||
# TFHE-rs input/outputs then to concrete again | ||
model.compile(x) |
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.
You could add model.predict with concrete maybe and add this to the comparisons. We expect them to be equal to disable and to execute with tfhe-rs input
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.
ok, as Benoit asks for it too I'll add it
a29f818
to
81cad15
Compare
If you're new to commit signing, there are different ways to set it up: Sign commits with
|
28050f6
to
7f2131f
Compare
Coverage failed ❌Coverage details
|
|
Adds the
ciphertext_format
parameter to compile calls.Needs new fhext & new compiler to run.