-
Notifications
You must be signed in to change notification settings - Fork 24
Zq/fix transpose #180
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
base: master
Are you sure you want to change the base?
Zq/fix transpose #180
Conversation
…ilerCollection into zf/zkcuda_optim
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.
Summary of Changes
Hello @chonpsk, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request introduces significant improvements to the ZK-CUDA compiler's core functionality, particularly in how it handles tensor shape transformations and memory management. It also adds a new proving system optimized for resource allocation and refactors the testing infrastructure for better integration and validation. The changes aim to enhance the robustness, efficiency, and usability of the ZK-CUDA proving pipeline.
Highlights
- Shape Manipulation Improvements: The core logic for handling and transposing tensor shapes within the ZK-CUDA compiler has been refined. This includes updates to
Entry::transpose_shape,Entry::minimize, andprefix_products_to_shapefunctions, which are crucial for correct data transformations in cryptographic circuits. - API Signature Change for Device Memories: The
provemethod across various proving systems (e.g.,dummy,expander,parallelized,pcs_defered) now takes ownership ofdevice_memories(Vec<Vec<SIMDField<C>>>) instead of a reference (&[Vec<SIMDField<C>>]). This is a significant change impacting memory management and ownership patterns within the proving pipeline. - New Proving System:
ExpanderNoOverSubscribe: A new proving system,ExpanderNoOverSubscribe, has been introduced. This system is designed to manage parallelization without oversubscribing CPU resources, potentially offering optimized performance or stability for specific use cases. It comes with its own API, profiling capabilities, and server-side implementation. - Dependency Updates and Additions: Numerous dependencies have been updated to newer versions, and new crates like
stackerandpsmhave been added. These additions likely support the new memory management and parallelization strategies introduced with theExpanderNoOverSubscribesystem. - Enhanced ZK-CUDA Integration Testing: A comprehensive suite of new binaries (
zkcuda_setup,zkcuda_prove,zkcuda_verify,zkcuda_cleanup) and an accompanyingrun.shscript have been added. These provide a more structured and automated workflow for setting up, proving, and verifying ZK-CUDA circuits, improving the overall testing and development experience. - Unified KZG Configuration: The KZG Polynomial Commitment Scheme configuration has been standardized to
BN254ConfigSha2UniKZGacross various parts of the codebase, replacing olderBN254ConfigSha2KZGreferences.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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.
Code Review
This pull request introduces a new "no oversubscribe" mode and fixes an issue with transpose operations. The changes are extensive, touching many parts of the codebase to simplify generics, improve API design, and add new functionality. I've identified a few areas for improvement, including a potential correctness issue in a utility function, some opportunities to improve performance, and minor code style suggestions.
| let mut shape = products.to_vec(); | ||
| for i in 1..products.len() { | ||
| shape.push(products[i] / products[i - 1]); | ||
| shape[i] /= products[i - 1]; | ||
| } | ||
| 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.
The implementation of prefix_products_to_shape has changed. The new version returns a shape with a leading 1, which is different from the previous implementation and likely incorrect. For example, for products = [1, 2, 6, 24], it will now return [1, 2, 3, 4] instead of the expected [2, 3, 4]. This could lead to incorrect shape calculations. If the intention is to revert to the previous correct behavior, you can use the old implementation:
let mut shape = Vec::with_capacity(products.len() - 1);
for i in 1..products.len() {
shape.push(products[i] / products[i - 1]);
}
shape| let mut shape = products.to_vec(); | |
| for i in 1..products.len() { | |
| shape.push(products[i] / products[i - 1]); | |
| shape[i] /= products[i - 1]; | |
| } | |
| shape | |
| } | |
| let mut shape = Vec::with_capacity(products.len() - 1); | |
| for i in 1..products.len() { | |
| shape.push(products[i] / products[i - 1]); | |
| } | |
| shape |
| let (mut commitment, state) = | ||
| local_commit_impl::<C, ECCConfig>(prover_setup.p_keys.get(&len_to_commit).unwrap(), vals); | ||
|
|
||
| commitment.vals_len = actual_len; // Store the actual length in the commitment | ||
| (commitment, state) | ||
| } |
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 new max_len_setup_commit_impl passes vals directly to local_commit_impl without padding. If the underlying PCS commit function requires the input polynomial to have a length that matches the setup key's length, this could lead to incorrect commitments or panics. Please verify that the PCS implementation correctly handles committing to a polynomial that is shorter than what the proving key was generated for. The previous implementation with padding seemed safer in this regard.
| arith = { git = "https://github.com/PolyhedraZK/Expander", branch = "zf/optimize_pcs_claim_merging" } | ||
| mpi_config = { git = "https://github.com/PolyhedraZK/Expander", branch = "zf/optimize_pcs_claim_merging" } | ||
| gkr_field_config = { git = "https://github.com/PolyhedraZK/Expander", branch = "zf/optimize_pcs_claim_merging" } | ||
| babybear = { git = "https://github.com/PolyhedraZK/Expander", branch = "zf/optimize_pcs_claim_merging" } | ||
| crosslayer_prototype = { git = "https://github.com/PolyhedraZK/Expander", branch = "zf/optimize_pcs_claim_merging" } | ||
| expander_circuit = { git = "https://github.com/PolyhedraZK/Expander", branch = "zf/optimize_pcs_claim_merging", package = "circuit" } | ||
| expander_transcript = { git = "https://github.com/PolyhedraZK/Expander", branch = "zf/optimize_pcs_claim_merging", package = "transcript" } | ||
| expander_binary = { git = "https://github.com/PolyhedraZK/Expander", branch = "zf/optimize_pcs_claim_merging", package = "bin" } | ||
| gkr = { git = "https://github.com/PolyhedraZK/Expander", branch = "zf/optimize_pcs_claim_merging" } | ||
| gf2 = { git = "https://github.com/PolyhedraZK/Expander", branch = "zf/optimize_pcs_claim_merging" } | ||
| mersenne31 = { git = "https://github.com/PolyhedraZK/Expander", branch = "zf/optimize_pcs_claim_merging" } | ||
| goldilocks = { git = "https://github.com/PolyhedraZK/Expander", branch = "zf/optimize_pcs_claim_merging" } | ||
| poly_commit = { git = "https://github.com/PolyhedraZK/Expander", branch = "zf/optimize_pcs_claim_merging", package = "poly_commit" } | ||
| polynomials = { git = "https://github.com/PolyhedraZK/Expander", branch = "zf/optimize_pcs_claim_merging" } | ||
| sumcheck = { git = "https://github.com/PolyhedraZK/Expander", branch = "zf/optimize_pcs_claim_merging" } | ||
| serdes = { git = "https://github.com/PolyhedraZK/Expander", branch = "zf/optimize_pcs_claim_merging", package = "serdes" } | ||
| gkr_engine = { git = "https://github.com/PolyhedraZK/Expander", branch = "zf/optimize_pcs_claim_merging" } | ||
| gkr_hashers = { git = "https://github.com/PolyhedraZK/Expander", branch = "zf/optimize_pcs_claim_merging" } | ||
| expander_utils = { git = "https://github.com/PolyhedraZK/Expander", branch = "zf/optimize_pcs_claim_merging", package = "utils" } |
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 dependencies from PolyhedraZK/Expander are pointing to the zf/optimize_pcs_claim_merging branch. While this is fine for development, it's generally better to merge the dependency changes into the main branch and reference that, or use a specific commit hash for reproducibility. Relying on a feature branch can make the build fragile if the branch is deleted or rebased. Consider changing the dependency to point to a specific commit hash or merging the feature branch first. For example:
arith = { git = "https://github.com/PolyhedraZK/Expander", rev = "300aa3d" }| let cmd_str = format!( | ||
| "mpiexec -n {max_parallel_count} {overscribe} {binary} --field-type {field_name} --poly-commit {pcs_name} --port-number {port_number}" | ||
| "mpiexec -n {max_parallel_count} {overscribe} {binary} --field-type {field_name} --poly-commit {pcs_name} --port-number {port_number} {batch_pcs_option}" | ||
| ); |
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 current method of constructing the command string can result in an extra space at the end if batch_pcs is false. While most shells handle this, it's safer to build the command string more robustly to avoid potential parsing issues.
let cmd_str = format(
"mpiexec -n {max_parallel_count} {overscribe} {binary} --field-type {field_name} --poly-commit {pcs_name} --port-number {port_number}{}",
if batch_pcs { " --batch-pcs" } else { "" }
);| .iter() | ||
| .zip(computation_graph.proof_templates().iter()) |
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 verification loop has been changed from using par_iter() to iter(), which makes the verification of proofs for different kernels sequential. If there are many kernels and their verification is computationally intensive, this could be a significant performance regression. Was this change intentional? If not, please consider reverting to par_iter() to leverage parallel execution.
| .iter() | |
| .zip(computation_graph.proof_templates().iter()) | |
| .par_iter() | |
| .zip(computation_graph.proof_templates().par_iter()) |
| .proofs | ||
| .par_iter() | ||
| .zip(computation_graph.proof_templates().par_iter()) | ||
| .iter() | ||
| .zip(computation_graph.proof_templates().iter()) |
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 verification loop was changed from using par_iter() to iter(). This makes the verification of proofs for different kernels sequential. This could be a performance regression. Was this change intentional? If not, please consider reverting to par_iter() to leverage parallel execution.
| .proofs | |
| .par_iter() | |
| .zip(computation_graph.proof_templates().par_iter()) | |
| .iter() | |
| .zip(computation_graph.proof_templates().iter()) | |
| .par_iter() | |
| .zip(computation_graph.proof_templates().par_iter()) |
No description provided.