From 5c335827c401665910d2a0044f86e83266f53595 Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 9 Sep 2025 17:31:17 -0700 Subject: [PATCH 1/2] Rename Circuitize to Compile --- README.md | 18 +++++++++--------- docs/arc42.md | 10 +++++----- main.py | 8 +++++--- src/cli/__init__.py | 6 +++--- src/cli/circuitize.py | 29 +++++++++++++++++------------ src/{circuitizer.py => compiler.py} | 2 +- src/prover.py | 2 +- 7 files changed, 41 insertions(+), 34 deletions(-) rename src/{circuitizer.py => compiler.py} (99%) diff --git a/README.md b/README.md index fc60a09..674b2f7 100644 --- a/README.md +++ b/README.md @@ -114,28 +114,28 @@ What happens: - Slices are written to src/models/net/slices/segment_/segment_.onnx - A slices metadata.json is created at src/models/net/slices/metadata.json -2) Circuitize with EZKL -- Circuitize either the whole model.onnx or the sliced segments (recommended for incremental proofs): +2) Compile with a backend (EZKL circuitize the slices) +- Compile either the whole model.onnx or the sliced segments (recommended for incremental proofs): Whole model: ```bash -dsperse circuitize --model-path src/models/net/model.onnx +dsperse compile --slices-path src/models/net/model.onnx ``` Sliced model directory (auto-detects slices metadata): ```bash -dsperse circuitize --model-path src/models/net +dsperse compile --slices-path src/models/net ``` Optional calibration input to improve settings: ```bash -dsperse circuitize --model-path src/models/net --input-file src/models/net/input.json +dsperse compile --slices-path src/models/net --input-file src/models/net/input.json ``` Optional layer selection (sliced models only): ```bash -dsperse circuitize --model-path src/models/net --layers 2,3,4 -dsperse circuitize --model-path src/models/net --layers 0-2 +dsperse compile --slices-path src/models/net --layers 2,3,4 +dsperse compile --slices-path src/models/net --layers 0-2 ``` What happens: @@ -223,7 +223,7 @@ Tips and troubleshooting - Ensure ezkl is on your PATH. If installed via cargo, add $HOME/.cargo/bin to PATH. - SRS files missing/slow downloads: - You can skip downloads during install and fetch later with ezkl get-srs --logrows --commitment kzg -- Circuitize says “slice first”: +- Compile says “slice first”: - Run dsperse slice --model-dir to produce slices and metadata.json - Paths in saved JSON are absolute on your machine; sharing outputs across machines may require path adjustments. @@ -239,7 +239,7 @@ Project structure (updated) - cli/ - base.py: shared CLI helpers - slice.py: slice command - - circuitize.py: circuitize command + - circuitize.py: compile command (deprecated alias: circuitize) - run.py: run command - prove.py: prove command - verify.py: verify command diff --git a/docs/arc42.md b/docs/arc42.md index bb9ff74..973b04f 100644 --- a/docs/arc42.md +++ b/docs/arc42.md @@ -60,7 +60,7 @@ This document outlines the high-level architecture for the "dsperse" project—a ## 4. Solution Strategy - **Overview:** - Dsperse proposes to circuitize the neural network at the level of its vertical layers. In a typical neural network, regardless of whether it is fully connected or uses other structures (such as in modern LLMs like LLAMA), the underlying computations rely on dense weight matrices (with weights and biases). Even though LLMs often use transformers—with feed-forward networks (which are fully connected layers)—the core idea is that each layer (or a group of layers) can be split into smaller circuits. + Dsperse proposes to compile circuits for the neural network at the level of its vertical layers. In a typical neural network, regardless of whether it is fully connected or uses other structures (such as in modern LLMs like LLAMA), the underlying computations rely on dense weight matrices (with weights and biases). Even though LLMs often use transformers—with feed-forward networks (which are fully connected layers)—the core idea is that each layer (or a group of layers) can be split into smaller circuits. - **Neural Net Clarification:** - **Fully Connected Layers in Modern LLMs:** @@ -106,7 +106,7 @@ This document outlines the high-level architecture for the "dsperse" project—a ![Vertical Layers Circuitization](images/vertical_layers.jpg) - *Note: In the diagram above, each colored node represents a vertical layer of the neural network, circuitized + *Note: In the diagram above, each colored node represents a vertical layer of the neural network, compiled independently for distributed proof computation.* --- @@ -123,7 +123,7 @@ This document outlines the high-level architecture for the "dsperse" project—a ![Circuit Design Overview](images/circuit_design_overview.jpg) *The neural network’s input witness is processed, and as the inference flows through each vertical layer, a circuit and - corresponding proof are generated. Each circuitized vertical layer will have its own input witness, allowing + corresponding proof are generated. Each compiled vertical layer will have its own input witness, allowing computations to be performed independently on separate machines with smaller lookup tables. credit: @HudsonGraeme for image* --- @@ -142,7 +142,7 @@ This document outlines the high-level architecture for the "dsperse" project—a - **Shared Design Principles:** - **Modularity:** - Circuitize each vertical layer as an independent unit to allow flexible assignment. + Compile each vertical layer as an independent unit to allow flexible assignment. - **Scalability:** Distribute proofs across multiple nodes to balance load and reduce proof time. - **Resource Optimization:** @@ -162,7 +162,7 @@ This document outlines the high-level architecture for the "dsperse" project—a - **Vertical Circuitization:** _Decision:_ Split neural net circuits vertically instead of as a whole model. _Rationale:_ Reduces compute and RAM constraints, allows distributed proof computation, and provides finer control over resource allocation. - _Alternatives:_ Circuitizing the entire model; however, this is less flexible and resource-intensive. + _Alternatives:_ Compiling the entire model into a single circuit; however, this is less flexible and more resource-intensive. - **Dynamic Grouping of Layers:** _Decision:_ Expose CLI parameters to allow grouping of multiple vertical layers into one circuit. diff --git a/main.py b/main.py index dd43c59..dbaa378 100755 --- a/main.py +++ b/main.py @@ -18,7 +18,7 @@ setup_run_parser, run_inference, setup_prove_parser, run_proof, setup_verify_parser, verify_proof, - setup_circuitize_parser, circuitize_model + setup_compile_parser, compile_model ) def main(): @@ -50,7 +50,7 @@ def main(): setup_run_parser(subparsers) setup_prove_parser(subparsers) setup_verify_parser(subparsers) - setup_circuitize_parser(subparsers) + setup_compile_parser(subparsers) # Parse arguments args = parser.parse_args() @@ -76,8 +76,10 @@ def main(): run_proof(args) elif args.command == 'verify': verify_proof(args) + elif args.command == 'compile': + compile_model(args) elif args.command == 'circuitize': - circuitize_model(args) + compile_model(args) else: # If no command is provided, show help parser.print_help() diff --git a/src/cli/__init__.py b/src/cli/__init__.py index c3cc3d4..c74bd29 100644 --- a/src/cli/__init__.py +++ b/src/cli/__init__.py @@ -8,7 +8,7 @@ from src.cli.run import setup_parser as setup_run_parser, run_inference from src.cli.prove import setup_parser as setup_prove_parser, run_proof from src.cli.verify import setup_parser as setup_verify_parser, verify_proof -from src.cli.circuitize import setup_parser as setup_circuitize_parser, circuitize_model +from src.cli.circuitize import setup_parser as setup_compile_parser, circuitize_model as compile_model __all__ = [ 'DsperseArgumentParser', @@ -24,6 +24,6 @@ 'run_proof', 'setup_verify_parser', 'verify_proof', - 'setup_circuitize_parser', - 'circuitize_model' + 'setup_compile_parser', + 'compile_model' ] diff --git a/src/cli/circuitize.py b/src/cli/circuitize.py index 2952706..d537ecf 100644 --- a/src/cli/circuitize.py +++ b/src/cli/circuitize.py @@ -96,7 +96,7 @@ def _check_layers(slices_path, layers_str): def setup_parser(subparsers): """ - Set up the argument parser for the circuitize command. + Set up the argument parser for the compile command. Args: subparsers: The subparsers object from argparse @@ -104,12 +104,12 @@ def setup_parser(subparsers): Returns: The created parser """ - circuitize_parser = subparsers.add_parser('circuitize', help='Circuitize slices using EZKL') - circuitize_parser.add_argument('--slices-path', help='Path to the slices directory') - circuitize_parser.add_argument('--input-file', help='Path to input file for calibration (optional)') - circuitize_parser.add_argument('--layers', help='Specify which layers to circuitize (e.g., "3, 20-22"). If not provided, all layers will be circuitized.') + compile_parser = subparsers.add_parser('compile', aliases=['circuitize'], help='Compile slices and circuitize them using EZKL') + compile_parser.add_argument('--slices-path', help='Path to the slices directory') + compile_parser.add_argument('--input-file', help='Path to input file for calibration (optional)') + compile_parser.add_argument('--layers', help='Specify which layers to compile (e.g., "3, 20-22"). If not provided, all layers will be compiled.') - return circuitize_parser + return compile_parser def circuitize_model(args): @@ -119,8 +119,13 @@ def circuitize_model(args): Args: args: The parsed command-line arguments """ - print(f"{Fore.CYAN}Circuitizing slices with EZKL...{Style.RESET_ALL}") - logger.info("Starting slices circuitization") + # Show deprecation notice if user invoked via 'circuitize' + if hasattr(args, 'command') and args.command == 'circuitize': + print(f"{Fore.YELLOW}Note: 'circuitize' is deprecated. Use 'compile' instead.{Style.RESET_ALL}") + logger.warning("'circuitize' command is deprecated; use 'compile'") + + print(f"{Fore.CYAN}Compiling slices with EZKL...{Style.RESET_ALL}") + logger.info("Starting slices compilation") # Prompt for slices path if not provided if not hasattr(args, 'slices_path') or not args.slices_path: @@ -140,7 +145,7 @@ def circuitize_model(args): if not os.path.isdir(args.slices_path): msg = ( "Please provide a slices directory, not a model file. " - "If you have a model, slice it first before circuitizing.\n" + "If you have a model, slice it first before compiling.\n" f"Try: dsperse slice --model-dir {args.slices_path}" ) print(f"{Fore.YELLOW}Warning: {msg}{Style.RESET_ALL}") @@ -153,7 +158,7 @@ def circuitize_model(args): if not has_metadata: msg = ( "No slices metadata found at the provided path. " - "Please slice the model first before circuitizing slices.\n" + "Please slice the model first before compiling slices.\n" f"Try: dsperse slice --model-dir {args.slices_path}" ) print(f"{Fore.YELLOW}Warning: {msg}{Style.RESET_ALL}") @@ -186,11 +191,11 @@ def circuitize_model(args): input_file=args.input_file, layers=validated_layers ) - success_msg = f"Slices circuitized successfully! Output saved to {os.path.dirname(output_path)}" + success_msg = f"Slices compiled successfully! Output saved to {os.path.dirname(output_path)}" print(f"{Fore.GREEN}✓ {success_msg}{Style.RESET_ALL}") logger.info(success_msg) except Exception as e: - error_msg = f"Error circuitizing slices: {e}" + error_msg = f"Error compiling slices: {e}" print(f"{Fore.RED}Error: {error_msg}{Style.RESET_ALL}") logger.error(error_msg) logger.debug("Stack trace:", exc_info=True) diff --git a/src/circuitizer.py b/src/compiler.py similarity index 99% rename from src/circuitizer.py rename to src/compiler.py index f2211c6..3d3c261 100644 --- a/src/circuitizer.py +++ b/src/compiler.py @@ -266,4 +266,4 @@ def _circuitize_slices(self, dir_path: str, input_file_path: Optional[str] = Non model_path = os.path.abspath(model_dir) circuitizer = Circuitizer.create(model_path=model_path) result_dir = circuitizer.circuitize(model_path=model_path, input_file=input_file) - print(f"Circuitization finished.") \ No newline at end of file + print(f"Compilation finished.") \ No newline at end of file diff --git a/src/prover.py b/src/prover.py index 9809a95..2d8bfa6 100644 --- a/src/prover.py +++ b/src/prover.py @@ -149,7 +149,7 @@ def prove_run(self, run_results_path, metadata_path): # Pre-check circuits exist if not self._has_circuit_files(run_results, metadata): - raise ValueError("No circuit files found. Please run 'dsperse circuitize' first to generate circuit files before attempting to prove.") + raise ValueError("No circuit files found. Please run 'dsperse compile' first to generate circuit files before attempting to prove.") proved_segments = 0 total_ezkl_segments = 0 From f3496404534c3a59e248cc4ea395533f8ab09432 Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 9 Sep 2025 17:31:17 -0700 Subject: [PATCH 2/2] Rename Circuitize to Compile --- README.md | 18 +++++++++--------- docs/arc42.md | 10 +++++----- main.py | 8 +++++--- src/cli/__init__.py | 6 +++--- src/cli/circuitize.py | 29 +++++++++++++++++------------ src/{circuitizer.py => compiler.py} | 2 +- src/prover.py | 2 +- 7 files changed, 41 insertions(+), 34 deletions(-) rename src/{circuitizer.py => compiler.py} (99%) diff --git a/README.md b/README.md index 201acf7..d17580a 100644 --- a/README.md +++ b/README.md @@ -137,28 +137,28 @@ Dsperse creates different types of metadata files for different purposes: - Both files contain similar top-level information but different levels of detail - **This behavior is intended** but can be confusing due to similar names and purposes -2) Circuitize with EZKL -- Circuitize either the whole model.onnx or the sliced segments (recommended for incremental proofs): +2) Compile with a backend (EZKL circuitize the slices) +- Compile either the whole model.onnx or the sliced segments (recommended for incremental proofs): Whole model: ```bash -dsperse circuitize --slices-path models/net/slices +dsperse compile --slices-path models/net/model.onnx ``` Sliced model directory (auto-detects slices metadata): ```bash -dsperse circuitize --slices-path models/net/slices +dsperse compile --slices-path models/net/slices ``` Optional calibration input to improve settings: ```bash -dsperse circuitize --slices-path models/net/slices --input-file models/net/input.json +dsperse compile --slices-path models/net/slices --input-file models/net/input.json ``` Optional layer selection (sliced models only): ```bash -dsperse circuitize --slices-path models/net/slices --layers 2,3,4 -dsperse circuitize --slices-path models/net/slices --layers 0-2 +dsperse compile --slices-path models/net/slices --layers 2,3,4 +dsperse compile --slices-path models/net/slices --layers 0-2 ``` What happens: @@ -246,7 +246,7 @@ Tips and troubleshooting - Ensure ezkl is on your PATH. If installed via cargo, add $HOME/.cargo/bin to PATH. - SRS files missing/slow downloads: - You can skip downloads during install and fetch later with ezkl get-srs --logrows --commitment kzg -- Circuitize says “slice first”: +- Compile says “slice first”: - Run dsperse slice --model-dir to produce slices and metadata.json - Paths in saved JSON are absolute on your machine; sharing outputs across machines may require path adjustments. @@ -262,7 +262,7 @@ Project structure (updated) - cli/ - base.py: shared CLI helpers - slice.py: slice command - - circuitize.py: circuitize command + - circuitize.py: compile command (deprecated alias: circuitize) - run.py: run command - prove.py: prove command - verify.py: verify command diff --git a/docs/arc42.md b/docs/arc42.md index 864797b..14f5bd7 100644 --- a/docs/arc42.md +++ b/docs/arc42.md @@ -60,7 +60,7 @@ This document outlines the high-level architecture for the "dsperse" project—a ## 4. Solution Strategy - **Overview:** - Dsperse proposes to circuitize the neural network at the level of its vertical layers. In a typical neural network, regardless of whether it is fully connected or uses other structures (such as in modern LLMs like LLAMA), the underlying computations rely on dense weight matrices (with weights and biases). Even though LLMs often use transformers—with feed-forward networks (which are fully connected layers)—the core idea is that each layer (or a group of layers) can be split into smaller circuits. + Dsperse proposes to compile circuits for the neural network at the level of its vertical layers. In a typical neural network, regardless of whether it is fully connected or uses other structures (such as in modern LLMs like LLAMA), the underlying computations rely on dense weight matrices (with weights and biases). Even though LLMs often use transformers—with feed-forward networks (which are fully connected layers)—the core idea is that each layer (or a group of layers) can be split into smaller circuits. - **Neural Net Clarification:** - **Fully Connected Layers in Modern LLMs:** @@ -100,7 +100,7 @@ This document outlines the high-level architecture for the "dsperse" project—a ![Vertical Layers Circuitization](images/vertical_layers.jpg) - *Note: In the diagram above, each colored node represents a vertical layer of the neural network, circuitized + *Note: In the diagram above, each colored node represents a vertical layer of the neural network, compiled independently for distributed proof computation.* --- @@ -117,7 +117,7 @@ This document outlines the high-level architecture for the "dsperse" project—a ![Circuit Design Overview](images/circuit_design_overview.jpg) *The neural network’s input witness is processed, and as the inference flows through each vertical layer, a circuit and - corresponding proof are generated. Each circuitized vertical layer will have its own input witness, allowing + corresponding proof are generated. Each compiled vertical layer will have its own input witness, allowing computations to be performed independently on separate machines with smaller lookup tables. credit: @HudsonGraeme for image* --- @@ -136,7 +136,7 @@ This document outlines the high-level architecture for the "dsperse" project—a - **Shared Design Principles:** - **Modularity:** - Circuitize each vertical layer as an independent unit to allow flexible assignment. + Compile each vertical layer as an independent unit to allow flexible assignment. - **Scalability:** Distribute proofs across multiple nodes to balance load and reduce proof time. - **Resource Optimization:** @@ -156,7 +156,7 @@ This document outlines the high-level architecture for the "dsperse" project—a - **Vertical Circuitization:** _Decision:_ Split neural net circuits vertically instead of as a whole model. _Rationale:_ Reduces compute and RAM constraints, allows distributed proof computation, and provides finer control over resource allocation. - _Alternatives:_ Circuitizing the entire model; however, this is less flexible and resource-intensive. + _Alternatives:_ Compiling the entire model into a single circuit; however, this is less flexible and more resource-intensive. - **Dynamic Grouping of Layers:** _Decision:_ Expose CLI parameters to allow grouping of multiple vertical layers into one circuit. diff --git a/main.py b/main.py index dd43c59..dbaa378 100755 --- a/main.py +++ b/main.py @@ -18,7 +18,7 @@ setup_run_parser, run_inference, setup_prove_parser, run_proof, setup_verify_parser, verify_proof, - setup_circuitize_parser, circuitize_model + setup_compile_parser, compile_model ) def main(): @@ -50,7 +50,7 @@ def main(): setup_run_parser(subparsers) setup_prove_parser(subparsers) setup_verify_parser(subparsers) - setup_circuitize_parser(subparsers) + setup_compile_parser(subparsers) # Parse arguments args = parser.parse_args() @@ -76,8 +76,10 @@ def main(): run_proof(args) elif args.command == 'verify': verify_proof(args) + elif args.command == 'compile': + compile_model(args) elif args.command == 'circuitize': - circuitize_model(args) + compile_model(args) else: # If no command is provided, show help parser.print_help() diff --git a/src/cli/__init__.py b/src/cli/__init__.py index c3cc3d4..c74bd29 100644 --- a/src/cli/__init__.py +++ b/src/cli/__init__.py @@ -8,7 +8,7 @@ from src.cli.run import setup_parser as setup_run_parser, run_inference from src.cli.prove import setup_parser as setup_prove_parser, run_proof from src.cli.verify import setup_parser as setup_verify_parser, verify_proof -from src.cli.circuitize import setup_parser as setup_circuitize_parser, circuitize_model +from src.cli.circuitize import setup_parser as setup_compile_parser, circuitize_model as compile_model __all__ = [ 'DsperseArgumentParser', @@ -24,6 +24,6 @@ 'run_proof', 'setup_verify_parser', 'verify_proof', - 'setup_circuitize_parser', - 'circuitize_model' + 'setup_compile_parser', + 'compile_model' ] diff --git a/src/cli/circuitize.py b/src/cli/circuitize.py index 2952706..d537ecf 100644 --- a/src/cli/circuitize.py +++ b/src/cli/circuitize.py @@ -96,7 +96,7 @@ def _check_layers(slices_path, layers_str): def setup_parser(subparsers): """ - Set up the argument parser for the circuitize command. + Set up the argument parser for the compile command. Args: subparsers: The subparsers object from argparse @@ -104,12 +104,12 @@ def setup_parser(subparsers): Returns: The created parser """ - circuitize_parser = subparsers.add_parser('circuitize', help='Circuitize slices using EZKL') - circuitize_parser.add_argument('--slices-path', help='Path to the slices directory') - circuitize_parser.add_argument('--input-file', help='Path to input file for calibration (optional)') - circuitize_parser.add_argument('--layers', help='Specify which layers to circuitize (e.g., "3, 20-22"). If not provided, all layers will be circuitized.') + compile_parser = subparsers.add_parser('compile', aliases=['circuitize'], help='Compile slices and circuitize them using EZKL') + compile_parser.add_argument('--slices-path', help='Path to the slices directory') + compile_parser.add_argument('--input-file', help='Path to input file for calibration (optional)') + compile_parser.add_argument('--layers', help='Specify which layers to compile (e.g., "3, 20-22"). If not provided, all layers will be compiled.') - return circuitize_parser + return compile_parser def circuitize_model(args): @@ -119,8 +119,13 @@ def circuitize_model(args): Args: args: The parsed command-line arguments """ - print(f"{Fore.CYAN}Circuitizing slices with EZKL...{Style.RESET_ALL}") - logger.info("Starting slices circuitization") + # Show deprecation notice if user invoked via 'circuitize' + if hasattr(args, 'command') and args.command == 'circuitize': + print(f"{Fore.YELLOW}Note: 'circuitize' is deprecated. Use 'compile' instead.{Style.RESET_ALL}") + logger.warning("'circuitize' command is deprecated; use 'compile'") + + print(f"{Fore.CYAN}Compiling slices with EZKL...{Style.RESET_ALL}") + logger.info("Starting slices compilation") # Prompt for slices path if not provided if not hasattr(args, 'slices_path') or not args.slices_path: @@ -140,7 +145,7 @@ def circuitize_model(args): if not os.path.isdir(args.slices_path): msg = ( "Please provide a slices directory, not a model file. " - "If you have a model, slice it first before circuitizing.\n" + "If you have a model, slice it first before compiling.\n" f"Try: dsperse slice --model-dir {args.slices_path}" ) print(f"{Fore.YELLOW}Warning: {msg}{Style.RESET_ALL}") @@ -153,7 +158,7 @@ def circuitize_model(args): if not has_metadata: msg = ( "No slices metadata found at the provided path. " - "Please slice the model first before circuitizing slices.\n" + "Please slice the model first before compiling slices.\n" f"Try: dsperse slice --model-dir {args.slices_path}" ) print(f"{Fore.YELLOW}Warning: {msg}{Style.RESET_ALL}") @@ -186,11 +191,11 @@ def circuitize_model(args): input_file=args.input_file, layers=validated_layers ) - success_msg = f"Slices circuitized successfully! Output saved to {os.path.dirname(output_path)}" + success_msg = f"Slices compiled successfully! Output saved to {os.path.dirname(output_path)}" print(f"{Fore.GREEN}✓ {success_msg}{Style.RESET_ALL}") logger.info(success_msg) except Exception as e: - error_msg = f"Error circuitizing slices: {e}" + error_msg = f"Error compiling slices: {e}" print(f"{Fore.RED}Error: {error_msg}{Style.RESET_ALL}") logger.error(error_msg) logger.debug("Stack trace:", exc_info=True) diff --git a/src/circuitizer.py b/src/compiler.py similarity index 99% rename from src/circuitizer.py rename to src/compiler.py index f2211c6..3d3c261 100644 --- a/src/circuitizer.py +++ b/src/compiler.py @@ -266,4 +266,4 @@ def _circuitize_slices(self, dir_path: str, input_file_path: Optional[str] = Non model_path = os.path.abspath(model_dir) circuitizer = Circuitizer.create(model_path=model_path) result_dir = circuitizer.circuitize(model_path=model_path, input_file=input_file) - print(f"Circuitization finished.") \ No newline at end of file + print(f"Compilation finished.") \ No newline at end of file diff --git a/src/prover.py b/src/prover.py index 9809a95..2d8bfa6 100644 --- a/src/prover.py +++ b/src/prover.py @@ -149,7 +149,7 @@ def prove_run(self, run_results_path, metadata_path): # Pre-check circuits exist if not self._has_circuit_files(run_results, metadata): - raise ValueError("No circuit files found. Please run 'dsperse circuitize' first to generate circuit files before attempting to prove.") + raise ValueError("No circuit files found. Please run 'dsperse compile' first to generate circuit files before attempting to prove.") proved_segments = 0 total_ezkl_segments = 0