-
-
Notifications
You must be signed in to change notification settings - Fork 156
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
BFVTensor #285
BFVTensor #285
Conversation
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.
Thank you for the contribution. It is a major step in the right direction!
One significant problem is that we should reuse the encrypted_tensor interface, which should be the root class for BFVTensor.
There is also a bit of code duplication between CKKSTensor and BFVTensor, but we can think in another PR about templating the classes.
Regarding the failing tests, it looks like a linting problem. Make sure that you run
.github/workflows/scripts/lint_cpp.sh
and
.github/workflows/scripts/lint_python.sh
and they are successful before pushing. You might need to install clang-format,
flake8
and black
locally for that.
Other than that, awesome work so far!
@@ -16,7 +16,8 @@ if(${BUILD_TEST}) | |||
${TENSEAL_TESTS_BASEDIR}/tensors/ckksvector_test.cpp | |||
${TENSEAL_TESTS_BASEDIR}/tensors/ckkstensor_test.cpp | |||
${TENSEAL_TESTS_BASEDIR}/tensors/plaintensor_test.cpp | |||
${TENSEAL_TESTS_BASEDIR}/tensors/bfvvector_test.cpp) | |||
${TENSEAL_TESTS_BASEDIR}/tensors/bfvvector_test.cpp |
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.
Why the duplicate cpp file?
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.
No sorry probably I just copy pasted and changed again after having saved, those lines should be appearing:
${TENSEAL_TESTS_BASEDIR}/tensors/bfvvector_test.cpp
${TENSEAL_TESTS_BASEDIR}/tensors/bfvtensor_test.cpp)
tenseal/cpp/tensors/BUILD
Outdated
"ckkstensor.h", | ||
"ckksvector.h", | ||
"encrypted_tensor.h", | ||
"encrypted_tensor_bfv.h", |
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.
encrypted_tensor should be a generic interface for all tensors in TenSEAL? Why do we need encrypted_tensor_bfv too?
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.
Yes you are right of course, sorry.
I just got a little confused with the scale method in encrypted_tensor.h given that it is not supposed to be used in BFV and indeed only now I've discovered that it's declared as not implemented for BFV (for the BFVVector counterpart I mean).
Also the same for polyval_inplace method which was using double so I initially changed the data type to the template plain_data_t but it was messing with BFVVector which was using double as template but the method itself was again declared as not implemented, so I did the same now for BFVTensor.
Sorry for the confusion
@@ -0,0 +1,263 @@ | |||
#ifndef TENSEAL_TENSOR_ENCRYPTED_TENSOR_BFV_H |
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.
Why do we need a separate interface from encrypted_tensor?
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.
No we don't sorry again, the wrong reason was the one mentioned above
tenseal/proto/tensors.proto
Outdated
// The serialized ciphertexts | ||
repeated bytes ciphertexts = 2; | ||
// Optional batch size. Exists only if batching is enabled | ||
uint32 batch_size = 4; |
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.
Why 4? this can be index 3.
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 should stop copy-pasting to be faster and forgetting about it, sorry.
I deleted the scale which was not needed but forgot indeed to change the index to 3.
tests/cpp/tensors/bfvtensor_test.cpp
Outdated
using namespace std; | ||
|
||
template <class Iterable> | ||
bool are_close(const Iterable& l, const std::vector<int64_t>& r) { |
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.
are_close
is relevant only for CKKS. For BFV, you should get the exact result. See the BFVVector C++ tests for reference
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.
Right thank you, I changed it now to assert/expect the exact result indeed
] | ||
|
||
|
||
def _almost_equal_number(v1, v2, m_pow_ten): |
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.
Similarly, _almost_equal_number
is only for CKKS. Here you should test for the exact result. See the test_bfv_vector tests for reference.
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.
Yes right, thank you
Ok thank you for the detailed explanation. So I think it's ok and I'll proceed to push the changes. |
The diff you are seeing contains the actual linting errors that break the build. But my bad, it can be a bit confusing:
|
Ok thank you, I run |
Ok now with the new commit it shows that by running the python tests some of them pass but then it stops at one giving indeed the same error I get locally: |
add polyval to BFVTensor BFVTensor tests bugs: remove scaling factor for BFV, use int64_t instead of int, fix context construction
I pushed some fixes, you can see the summary from the commit.
I haven't checked the python tests, though. |
Thank you! Yes my bad, I indeed removed rescaling and coefficient modulus from various methods but not everywhere, sorry for the confusion. Ok I'll wait for the tests to run here on GitHub and then I'll further check the python tests for problems, if any. |
I pushed fixes to the python tests of BFVTensor, now locally they all work! Should also then work everything here in theory. |
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.
LGTM! Great work! Thank you for your contribution, @comidan!
I've left just one minor observation, after that we can merge the PR.
tenseal/cpp/tensors/bfvtensor.h
Outdated
public: | ||
using EncryptedTensor<int64_t, shared_ptr<BFVTensor>>::decrypt; | ||
/** | ||
* Create a new BFVTensor from an 1D vector. |
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.
The comment here is not correct, the BFVTensor can be created from tensors of any shape
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.
LGTM! Great work! Thank you for your contribution, @comidan!
I've left just one minor observation, after that we can merge the PR.
Thank you for the help!
Sure ok, I've just pushed the new header file with the fixed comment.
* @param[in] input vector. | ||
* @param[in] input vector. | ||
* @param[in] input vector. | ||
*/ |
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.
Sorry, but the comments still don't make sense.
Why the
* @param[in] input vector.
* @param[in] input vector.
* @param[in] input vector.
3 times as a vector ?
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 @bcebere I'll change it accordingly, I just left the same comments which were already present in CKKSTensor.h assuming they were correct.
Should I then change also the ones for CKKSTensor?
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.
Yes, please. Thank you so much for improving this!
Thank you for your contribution, @comidan! |
Thank you for the help in making it! |
* BFVTensor * Fix BFVTensor python tests * Update bfvtensor.h * Update ckkstensor.h Co-authored-by: Bogdan Cebere <bogdan.cebere@gmail.com>
Description
This PR tries to add support for BFVTensor.
Checklist