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

Many refactors #983

Merged
merged 12 commits into from
Mar 21, 2024
Merged

Many refactors #983

merged 12 commits into from
Mar 21, 2024

Conversation

mayeul-zama
Copy link
Contributor

No description provided.

@cla-bot cla-bot bot added the cla-signed label Mar 13, 2024
@mayeul-zama mayeul-zama force-pushed the mz/ms_compression_shortint branch from d6e4ac3 to af86fd7 Compare March 13, 2024 14:29
@mayeul-zama mayeul-zama changed the title Mz/ms compression shortint Mz/ms compression shortint/integer Mar 13, 2024
@mayeul-zama mayeul-zama force-pushed the mz/ms_compression_shortint branch 2 times, most recently from d687fa6 to 7951e25 Compare March 14, 2024 12:27
@mayeul-zama mayeul-zama requested a review from IceTDrinker March 14, 2024 14:24
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.

Several comments, see with David and Thomas if need be for coverage and function executor patterns for tests

I think the shortint compression would not work as expected as it would worsen the degree of the ciphertexts as it's currently written

I would therefore require a test checking for an identity decompression that the degree is conserved

tfhe/src/shortint/ciphertext/compressed_ciphertext.rs Outdated Show resolved Hide resolved
tfhe/src/shortint/server_key/mod.rs Outdated Show resolved Hide resolved
tfhe/src/integer/ciphertext/compressed_ciphertext.rs Outdated Show resolved Hide resolved
tfhe/src/integer/ciphertext/compressed_ciphertext.rs Outdated Show resolved Hide resolved
tfhe/src/integer/ciphertext/compressed_ciphertext.rs Outdated Show resolved Hide resolved
tfhe/src/shortint/ciphertext/compressed_ciphertext.rs Outdated Show resolved Hide resolved
Comment on lines 80 to 82
fn modulus_switch_compression<P>(param: P)
where
P: Into<PBSParameters>,
Copy link
Member

Choose a reason for hiding this comment

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

does not use the Function executor pattern ?

if need be ask Thomas how to use the executor stuff

tfhe/src/shortint/server_key/mod.rs Outdated Show resolved Hide resolved
tfhe/src/shortint/server_key/mod.rs Outdated Show resolved Hide resolved
tfhe/src/shortint/ciphertext/compressed_ciphertext.rs Outdated Show resolved Hide resolved
@mayeul-zama mayeul-zama force-pushed the mz/ms_compression_shortint branch 2 times, most recently from eee4ddb to 35b2ee0 Compare March 19, 2024 10:34
let ct2 = cks.encrypt_with_message_modulus(clear2, MessageModulus(modulus as usize));

println!("MUL SMALL CARRY:: clear1 = {clear1}, clear2 = {clear2}, mod = {modulus}");
let ct_res = sks.unchecked_mul_lsb_small_carry(&ct1, &ct2);
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this uses the bivariate PBS, I think I would go for an integer like rework, where each op gets its file, so you would export the macro in the shortint module that would get moved to e.g.

tests/mod.rs

and then crate a file for the operation you are currently working on ?

so

tests/modulus_switch_compression.rs

does that make sense ?

tfhe/src/shortint/server_key/mod.rs Outdated Show resolved Hide resolved
tfhe/src/shortint/server_key/mod.rs Outdated Show resolved Hide resolved
tfhe/src/shortint/server_key/mod.rs Outdated Show resolved Hide resolved
tfhe/src/shortint/server_key/mod.rs Outdated Show resolved Hide resolved
tfhe/src/shortint/server_key/mod.rs Show resolved Hide resolved
tfhe/src/shortint/ciphertext/mod.rs Outdated Show resolved Hide resolved
tfhe/src/shortint/ciphertext/mod.rs Outdated Show resolved Hide resolved
tfhe/src/shortint/ciphertext/mod.rs Outdated Show resolved Hide resolved
}
}
}
#[allow(clippy::module_inception)]
Copy link
Member

Choose a reason for hiding this comment

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

unsure for the naming below

also, let's keep the modules public for now, more often than not having private stuff ends being more problems than it's worth at the moment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

By reexporting everything publicly, the interface of this module remains unchanged I believe
I don't see what problem this could cause

Copy link
Member

Choose a reason for hiding this comment

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

we'll see but from experience on TFHE-rs as soon as something is not public, then it gets annoying/someone needs access for fairly good reason

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 believe everything is accessible through the pub use, the only difference being that it appears one module higher (as before this refactor)

Copy link
Member

Choose a reason for hiding this comment

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

as I said, we will see :)

@mayeul-zama mayeul-zama force-pushed the mz/ms_compression_shortint branch from 35b2ee0 to f2abd31 Compare March 19, 2024 15:43
@mayeul-zama mayeul-zama changed the title Mz/ms compression shortint/integer Many refactors Mar 19, 2024
Comment on lines -2 to +3
pub mod shortint;
pub mod parametrized_test;
pub mod parametrized_test_bivariate_pbs_compliant;
Copy link
Member

Choose a reason for hiding this comment

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

the split does not make sense I believe as we discussed ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Even if eventually, we'd like to have many more files, I think, it's better to have two files rather than one

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 the split does not make sense as some tests are not bivar PBS compliant in the corresponding file :/

@@ -37,7 +35,9 @@ macro_rules! __join_implementation {
};
}

#[macro_export]
#[doc(hidden)]
Copy link
Member

Choose a reason for hiding this comment

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

doc(hidden) on the re export ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was already hidden, but I can remove it if you think it makes sense

Copy link
Member

Choose a reason for hiding this comment

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

I mean does a doc hidden make sense on a pub use ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a pub(crate) use

Copy link
Member

Choose a reason for hiding this comment

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

sorry

I mean

doc(hidden) on a use statement does nothing ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

@@ -1,490 +1,11 @@
//! This module implements the ciphertext structures.
mod base;
Copy link
Member

Choose a reason for hiding this comment

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

let's keep things public, as you can see the boolean_value one was public, same thing for shortint 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.

Done

Comment on lines 1 to 5
use super::{CrtCiphertext, RadixCiphertext, SignedRadixCiphertext};
use crate::shortint::Ciphertext;

pub trait IntegerCiphertext: Clone {
fn blocks(&self) -> &[Ciphertext];
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't this be in the mod.rs itself ?

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 think it's clearer to have the mod only containing other modules (and possibly reexports)
Renamed module integer_ciphertext

@@ -27,8 +27,7 @@ use serde::{Deserialize, Serialize};
///
/// let ct = cks.encrypt(msg);
///
/// // Decryption
/// let dec = cks.decrypt(&ct);
/// /// let dec = cks.decrypt(&ct);
Copy link
Member

Choose a reason for hiding this comment

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

this looks wrong

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Comment on lines +1 to +6
use super::super::CheckError;
pub use crate::core_crypto::commons::parameters::PBSOrder;
use crate::shortint::parameters::{CarryModulus, MessageModulus};
use serde::{Deserialize, Serialize};
use std::cmp;
use std::fmt::Debug;
Copy link
Member

Choose a reason for hiding this comment

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

could be in the mod.rs itself ?

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 prefer it this way
I think it's clearer to have the mod only containing other modules (and possibly reexports)

Copy link
Member

Choose a reason for hiding this comment

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

ok

Comment on lines +6 to +9
pub use common::*;
pub use compact_list::*;
pub use compressed::*;
pub use standard::*;
Copy link
Member

Choose a reason for hiding this comment

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

let's not have pub use of everything, it was a bad pattern/practice in core_crypto, Thomas said it was not the best way of making things available where required

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

Comment on lines +1 to +4
mod common;
mod compact_list;
mod compressed;
mod standard;
Copy link
Member

Choose a reason for hiding this comment

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

pub mod

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added

Comment on lines 7 to 11
pub use base::*;
pub use boolean_value::*;
pub use compact_list::*;
pub use compressed::*;
pub use utils::*;
Copy link
Member

Choose a reason for hiding this comment

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

pub use the minimum required/which makes sense to compile

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

tfhe/src/shortint/server_key/mod.rs Show resolved Hide resolved
@mayeul-zama mayeul-zama force-pushed the mz/ms_compression_shortint branch 2 times, most recently from 2fae26a to acba6ca Compare March 20, 2024 14:14
@@ -617,6 +656,9 @@ macro_rules! impl_scalar_binary_assign_fn_on_type {
};
}

#[cfg(feature = "integer")]
Copy link
Member

Choose a reason for hiding this comment

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

feature gate required ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No
Removing

@IceTDrinker
Copy link
Member

cuda test red @mayeul-zama

@mayeul-zama mayeul-zama force-pushed the mz/ms_compression_shortint branch from acba6ca to 0bcfc17 Compare March 20, 2024 14:46
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.

Thanks for the preliminary refactor and most notably for the shortint test fixes !

@mayeul-zama mayeul-zama force-pushed the mz/ms_compression_shortint branch from 0bcfc17 to c2f3c2c Compare March 20, 2024 15:50
@zama-bot zama-bot removed the approved label Mar 20, 2024
@mayeul-zama mayeul-zama force-pushed the mz/ms_compression_shortint branch from c2f3c2c to 53df75b Compare March 21, 2024 09:24
@zama-bot zama-bot removed the approved label Mar 21, 2024
@mayeul-zama mayeul-zama merged commit 31e2949 into main Mar 21, 2024
36 checks passed
@mayeul-zama mayeul-zama deleted the mz/ms_compression_shortint branch March 21, 2024 12:58
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