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

add noise level #651

Merged
merged 2 commits into from
Nov 6, 2023
Merged

add noise level #651

merged 2 commits into from
Nov 6, 2023

Conversation

mayeul-zama
Copy link
Contributor

No description provided.

@cla-bot cla-bot bot added the cla-signed label Oct 23, 2023
@github-actions
Copy link

@slab-ci cpu_fast_test

@github-actions
Copy link

@slab-ci cpu_fast_test

Copy link
Member

@IceTDrinker IceTDrinker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing tests

tfhe/src/shortint/server_key/mod.rs Show resolved Hide resolved
tfhe/src/shortint/parameters/multi_bit.rs Show resolved Hide resolved
tfhe/src/shortint/engine/server_side/mod.rs Outdated Show resolved Hide resolved
tfhe/src/shortint/engine/server_side/mod.rs Outdated Show resolved Hide resolved
@github-actions
Copy link

@slab-ci cpu_fast_test

@@ -83,6 +123,7 @@ impl Degree {
pub struct Ciphertext {
pub ct: LweCiphertextOwned<u64>,
pub degree: Degree,
pub noise_level: NoiseLevel,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So as we know adding this field breaks deserialization

Do we plan to do something to mitigate that ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with the 0.5.0 we will do the semver trick, we will most likely provide a way to load old ciphertext and set the noise to the max for that ciphertext or do a bootstrapping right away I would say

for 0.5.0 I would try to break as many things as possible

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mayeul-zama didn't we say we want the noise level to be private to be able to crash with a given feature if the noise level exceeds a valid noise level ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember that
I don't see how it's needed to have this crash feature

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it might make identifying the faulty operation harder though if you have a chain of adds, so... not sure I like it much

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, and if you too many linear operations without a PBS after, the assert won't be triggered

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah its less precise and uses the fact that in practive you are very limited in the number of leveled operation you can do

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But making it private forces the use of a constructor instead of a normal struct construction which is less ergonomic IMO

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes but that's a very small price to pay, even though it crossed my mind

@github-actions
Copy link

@slab-ci cpu_fast_test

Comment on lines 5 to 6
#[test]
fn test_noise_level_propagation() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one function per operator being tested please, with corner cases (i.e. 0 and other values for scalars)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and when I say per operator, it includes, default, checked, smart and unchecked with assign versions to be sure we cover all of the paths

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there should be a way to re use the CPU test executor from Thomas to reuse a test for all variants

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

except smart versions because of the mutable references potentially but it would automate most of the rest to check all paths

@github-actions
Copy link

@slab-ci cpu_fast_test

Copy link
Member

@IceTDrinker IceTDrinker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor stuff on testing (naming) and some randomized tests

Comment on lines 7 to 8
let test_fn = |f: &dyn Fn(&ServerKey, &Ciphertext) -> Ciphertext,
g: &dyn Fn(NoiseLevel) -> NoiseLevel| {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dyn is required so the closure works for everything ?

also better naming for f and g please

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed op and predicate

tfhe/src/shortint/server_key/tests/noise_level.rs Outdated Show resolved Hide resolved
tfhe/src/shortint/server_key/tests/noise_level.rs Outdated Show resolved Hide resolved
use crate::shortint::parameters::PARAM_MESSAGE_2_CARRY_2_KS_PBS;
use crate::shortint::{Ciphertext, ServerKey};

fn test_1_ct_noise_level_propagation(sk: &ServerKey, ct: &Ciphertext) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test_unary_op_... ? it's a proposal but I think it's the notation we use in the C api IIRC, the end of the name is good 👍 , nitpick

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

tfhe/src/shortint/server_key/tests/noise_level.rs Outdated Show resolved Hide resolved
);
}

fn test_2_ct_assign_noise_level_propagation(sk: &ServerKey, ct1: &Ciphertext, ct2: &Ciphertext) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

binary_op_assign

tfhe/src/shortint/server_key/tests/noise_level.rs Outdated Show resolved Hide resolved
tfhe/src/shortint/server_key/tests/noise_level.rs Outdated Show resolved Hide resolved
@IceTDrinker
Copy link
Member

thanks for the base of the testing infrastructure, some improvements can be made I believe but we are nearly there

@github-actions
Copy link

@slab-ci cpu_fast_test

@github-actions
Copy link

@slab-ci cpu_fast_test

1 similar comment
@github-actions
Copy link

@slab-ci cpu_fast_test

Copy link
Member

@IceTDrinker IceTDrinker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor details, next one should be good to merge

Comment on lines +235 to +237
pub fn set_noise_level(&mut self, noise_level: NoiseLevel) {
self.noise_level = noise_level
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we require a max_noise_level right away ? it would mean needing to put it on the ServerKey, or maybe wait a bit more, we will probably require to re optimize all parameters sets and rework parameter sets to have the norm2 in there

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I plan to add it in a subsequent PR

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok ! follow up issue please :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tfhe/src/shortint/server_key/tests/noise_level.rs Outdated Show resolved Hide resolved
Copy link

@slab-ci cpu_fast_test

@tmontaigu
Copy link
Contributor

Changes looks good to me

Copy link

github-actions bot commented Nov 2, 2023

@slab-ci cpu_fast_test

Copy link

github-actions bot commented Nov 2, 2023

Pull Request has been approved 🎉
Launching full test suite...
@slab-ci cpu_test
@slab-ci cpu_integer_test
@slab-ci cpu_multi_bit_test
@slab-ci cpu_wasm_test
@slab-ci csprng_randomness_testing

Copy link
Member

@IceTDrinker IceTDrinker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good thanks !

@mayeul-zama mayeul-zama merged commit 6497fb9 into main Nov 6, 2023
24 checks passed
@mayeul-zama mayeul-zama deleted the mz/add_noise_level branch November 6, 2023 10:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants