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

Ns/bench tfhe zk pok #1771

Merged
merged 1 commit into from
Nov 18, 2024
Merged

Ns/bench tfhe zk pok #1771

merged 1 commit into from
Nov 18, 2024

Conversation

nsarlin-zama
Copy link
Contributor

PR content/description

Add benches to the tfhe-zk-pok crates to be able to compare timings between zk v1 and v2

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.

I think something is not right with the k * 64, seeding feels unnecessary as we have randomness in real world performance/rng

We must find a way to avoid the duplication for the pure in house benchmark utils stuff and the zk-sepcific parameters setup this won't be maintainable long term

Comment on lines 1 to 2
# Placeholder workflow file allowing running it without having to merge to main first
name: Placeholder Workflow
# Run benchmarks of the tfhe-zk-pok crate on an instance and return parsed results to Slab CI bot.
name: tfhe-zk-pok benchmarks
Copy link
Member

Choose a reason for hiding this comment

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

to be reverted once you are done testing

(PKEV2_TEST_PARAMS, "PKEV2_TEST_PARAMS"),
] {
let (public_param, public_commit, private_commit, metadata) = init_params_v1(params);
let bits = params.k * 64;
Copy link
Member

Choose a reason for hiding this comment

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

that could be way too big

@@ -0,0 +1,459 @@
#![allow(non_snake_case)]
Copy link
Member

Choose a reason for hiding this comment

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

looks to be mostly a copy paste ?

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 need the types in tfhe/benches/utilities to be able to create the json file with the params but I can't use it directly because I am not in the tfhe crate. This is mostly a copy paste with only the needed bits and tfhe internal types converted to builtin rust types.

I also integrated things from tfhe-zk-pok/proof/mod.rs test module because benches are not run with #[cfg(test)]

Copy link
Member

Choose a reason for hiding this comment

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

the utils can be marked with a cfg = "bench" I believe

I think we have something like that in TFHE-rs

as for the utils some work needs to be done with David to make the copied code into a small util crate, we can't copy things when we "just" need to bench something

Copy link
Contributor

Choose a reason for hiding this comment

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

You think about a crate like tfhe-utils that would contains CryptoParametersRecord and write_to_json() function ?

Copy link
Member

Choose a reason for hiding this comment

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

potentially, we can't duplicate those everywhere

Copy link
Contributor Author

@nsarlin-zama nsarlin-zama Nov 12, 2024

Choose a reason for hiding this comment

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

The problem is that the current bench utilities make heavy use of tfhe types so it cannot be used without it, it would need a rework that's out of the scope of this PR I think. Since tfhe itself depends on tfhe-zk-pok it should be written in a way that prevent circular dependencies.

I don't think there is a cfg(bench) and the code is already only compiled with benches, the problem is that I can't use code from cfg(test) from there.

Copy link
Member

Choose a reason for hiding this comment

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

see tfhe/src/core_crypto/commons/ciphertext_modulus.rs:23 fairly sure there is something for benchmarks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are you sure that this works ? I don't find any doc about it, it does not seem to have any effect on my code and cargo warns about it. Maybe there is some special trick in the tfhe crate to make it work ?

@nsarlin-zama
Copy link
Contributor Author

@@ -0,0 +1,459 @@
#![allow(non_snake_case)]
Copy link
Contributor

Choose a reason for hiding this comment

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

You think about a crate like tfhe-utils that would contains CryptoParametersRecord and write_to_json() function ?

@nsarlin-zama nsarlin-zama force-pushed the ns/bench_tfhe_zk_pok branch 5 times, most recently from ecaa1a3 to fc85bbc Compare November 13, 2024 09:00
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 💪

@nsarlin-zama nsarlin-zama merged commit a45b7b3 into main Nov 18, 2024
87 checks passed
@nsarlin-zama nsarlin-zama deleted the ns/bench_tfhe_zk_pok branch November 18, 2024 12:17
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.

4 participants