Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 <N> --commitment kzg
- Circuitize says “slice first”:
- Compile says “slice first”:
- Run dsperse slice --model-dir <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.

Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions docs/arc42.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:**
Expand Down Expand Up @@ -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.*
---

Expand All @@ -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*

---
Expand All @@ -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:**
Expand All @@ -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.
Expand Down
8 changes: 5 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions src/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -24,6 +24,6 @@
'run_proof',
'setup_verify_parser',
'verify_proof',
'setup_circuitize_parser',
'circuitize_model'
'setup_compile_parser',
'compile_model'
]
29 changes: 17 additions & 12 deletions src/cli/circuitize.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,20 @@ 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

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):
Expand All @@ -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:
Expand All @@ -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}")
Expand 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}")
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/circuitizer.py → src/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
print(f"Compilation finished.")
2 changes: 1 addition & 1 deletion src/prover.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down