Ethan Cemer
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    ![chart (7)](https://hackmd.io/_uploads/r19W4rBca.png) +++ title = 'ZKML Framework Comparison' date = 2024-01-09T09:27:40+00:00 draft = false +++ ![for_exceptional_bigdoggydog](https://hackmd.io/_uploads/S1fV4EdtT.png) ## Introduction Questions about comparative performance of ZKML approaches are frequent. In this article, we aim to shed light on this topic by benchmarking EZKL against [RISC0](https://www.risczero.com/) and [Orion](https://orion.gizatech.xyz/welcome/readme), two of the most popular alternative ZKML frameworks. We have ommitted comparisons to Modulus Labs' Remainder prover as code for the prover is not public at the time of writing. We've also omitted Aleo, as their system doesn't have sufficient coverage of model architectures to be comparable to other frameworks (it currently only supports decision tree classifiers and small MLP neural nets). We will explore the proving times for four types of models: linear regression, random forests, SVM classification and tree ensemble regressions. > **Note**: You can generate the same benchmarking data on your machine with the [repo](https://github.com/zkonduit/zkml-framework-benchmarks). Although you will need to execute on a machine with atleast 16 gb of ram and it will take a few hours to complete. EZKL outperforms RISC0 and Orion in proving times by a significant margin across all four models. On average EZKL is 65.88 times faster than RISC0 and 2.92 times faster than Orion. Furthermore, EZKL offers a more streamlined development experience with minimal context switching, contrasting sharply with the more segmented workflows of RISC0 and Orion, where the data science and zk aspects operate in different contexts. We'll also look at the setup steps for each framework and the architectural differences that contribute to performance disparities. ## Model Accuracy A critical challenge in benchmarking ZKML frameworks lies in ensuring that the accuracy of the models remains consistent. This is essential because often in ZKML circuits, there's a trade-off between model accuracy and proving costs. For RISC0, model inputs are ingested as raw f64 values, and RISC0 internally manages the quantization of these inputs. The outputs are then fixed as either u32 or i32, depending on the model. This inherent quantization can impact the precision of the computations and thus the final accuracy of the model. In contrast, EZKL offers flexibility in managing the fixed-point scaling factor for converting floating points to fixed-point values for quantization. By fine-tuning this parameter, users can balance the trade-off between accuracy and proving efficiency, which is crucial for applications where precision is as important as computational efficiency. Orion introduces another dimension to this challenge. Users can select the fixed-point tensor type for inputting data into their model. In our benchmarks, we selected a 2^4 (or 16 times) fixed-point scaling factor for Orion's tensor library. To ensure a level playing field, we matched this input scaling by setting the input scale parameter for EZKL to 4, corresponding to 2^4. This careful calibration across frameworks is vital to ensure that the accuracy of the models is comparable and that the benchmarks reflect real-world applicability. However, it's important to note a limitation we encountered with Orion. Due to an issue with how cairo-run displays complex data, we were unable to accurately view the outputs of the Cairo benchmarks. This limitation has been recognized by the Giza team, and they are actively working on a [fix](https://github.com/lambdaclass/cairo-vm/issues/1564). ## Setup We selected smaller machine learning models; ideally these would be supported by all three frameworks. This would require finding models supported by [SmartCore](https://smartcorelib.org/), exportable to the [ONNX](https://onnxruntime.ai/) format used by EZKL and Orion, and using only Ops currently supported by Orion (excluding convolution and random forests for example). SmartCore, a Rust-based library used for RISC0-based proving, also supports a limited array of models. Each model type must be explicitly defined in Rust, with detailed specifications for parameters and data types. ONNX offers broader flexibility, accommodating virtually any model defined using the [PyTorch](https://pytorch.org/) or [Tensorflow](https://www.tensorflow.org) frameworks, and many [scikit-learn](https://scikit-learn.org/) models. This discrepancy necessitated a careful selection of models that are both representable in SmartCore's more rigid structure and exportable to ONNX. After evaluating the supported models, we chose Linear Regression, Decision Tree Classifier, and SVC (support vector machine classification) for our benchmarks. > **Note**: Despite our best efforts to benchmark the performance of a random forest classifier model using Orion, we faced significant challenges. Our testing environment, equipped with a robust 1000GB of RAM and a 64-core CPU, seemed more than capable of handling this task. We followed the procedure outlined in the Orion documentation, using [this](https://colab.research.google.com/drive/1qem56rUKJcNongXsLZ16_869q8395prz#scrollTo=V3qGW_kfXudk) TreeEnsembleClassifier notebook to translate parameters from an ONNX TreeEnsembleClassifier model into Cairo code. However, we consistently encountered out-of-memory errors when attempting to run the code, even for relatively small random forest models. This issue suggests a potential memory leakage within the transpiler-generated Cairo program, though further investigation is needed to confirm and address the underlying cause. ### EZKL Setting up and generating proofs with EZKL is remarkably straightforward, making it accessible even to those with minimal technical background. The process begins by opening one of our [example](https://github.com/zkonduit/ezkl/tree/main/examples/notebooks) Jupyter notebooks, which can be run locally or on Google Colab . Users simply progress through the notebook cells, following the instructions and executing the code. The journey from setup to obtaining proofs culminates in a 'proving cell', which when run, generates the zk proofs based on the predefined models and inputs. For the notebooks used for benchmarking, we simply forked the existing example notebooks making modification to the inputs to match the corresponding example SmartCore notebooks used by RISC0. ### RISC0 Getting started with RISC0 involves a more intricate setup. One must first is set up a new Risc0 zkVM project, which lays the foundation for a user's work. Unlike EZKL, RISC0 requires users to spin up a dedicated Rust-based Jupyter notebook server on their computer. > **Note**: Rust notebooks are not supported by Google Colab Once the environment is ready, the user must define both a [host](https://dev.risczero.com/api/zkvm/developer-guide/host-code-101) and [guest](https://dev.risczero.com/api/zkvm/developer-guide/guest-code-101) program for the zkVM. The host, essentially the machine running the zkVM, is an untrusted agent responsible for setting up the environment and managing inputs/outputs. In contrast, the guest code is what will be executed and proven within the zkVM. This distinction is crucial in understanding how RISC0 secures and verifies computations. For benchmarking, the process diverges further. With EZKL, the 'tests/benchmark_tests.rs' file can directly execute the Jupyter notebooks to gather proving data. However, with RISC0, one must first navigate through the Jupyter notebook to generate the model and input data. Only then can you run the host program, which orchestrates the execution and generation of proofs. ### Orion Transitioning to Orion introduces a different setup complexity. Initially, users must install [scarb](https://docs.swmansion.com/scarb/), the development toolchain for Cairo and Starknet. Similar to EZKL, the process begins in a Python environment within a Jupyter notebook, where the model and data are set up. Subsequently, the data is written to a 'Cairo' file in the form of a 'Tensor,' as defined by the Orion library. The next step involves reimplementing the model, initially built using numpy, into the Cairo language with the assistance of the Orion library. Finally, a 'cairo.inference' file is created for executing a forward pass of the model within the Cairo environment. This step is crucial as it times the execution, thereby determining the proving time. ## Performance Comparison ### Linear regressions | Framework | Memory Usage (avg) | Memory Usage (std) | Proving Time (avg) | Proving Time (std) | |-----------|--------------------|---------------------|--------------------|--------------------| | ezkl | 19.38mb | 102.01mb | 0.000s | 0.009s | | orion | 58.78mb | 98.03mb | 0.001s | 0.010s | | riscZero | 1320.92mb | 695.96mb | 0.010s | 0.093s | ### Random forests | Framework | Memory Usage (avg) | Memory Usage (std) | Proving Time (avg) | Proving Time (std) | |-----------|--------------------|---------------------|--------------------|--------------------| | ezkl | 382.78mb | 1358.36mb | 0.006s | 0.262s | | riscZero | 10189.34mb | 209.00mb | 0.173s | 1.639s | ### Svm classifications | Framework | Memory Usage (avg) | Memory Usage (std) | Proving Time (avg) | Proving Time (std) | |-----------|--------------------|---------------------|--------------------|--------------------| | ezkl | 23.69mb | 118.36mb | 0.000s | 0.027s | | orion | 58.81mb | 84.08mb | 0.001s | 0.011s | | riscZero | 5107.03mb | 830.08mb | 0.037s | 0.332s | ### Te regressions | Framework | Memory Usage (avg) | Memory Usage (std) | Proving Time (avg) | Proving Time (std) | |-----------|--------------------|---------------------|--------------------|--------------------| | ezkl | 23.69mb | 89.45mb | 0.000s | 0.015s | | orion | 67.59mb | 53.70mb | 0.001s | 0.056s | | riscZero | 1320.77mb | 690.86mb | 0.010s | 0.062s | ![chart (5)](https://hackmd.io/_uploads/BJfYxyAta.png) ![chart (6)](https://hackmd.io/_uploads/BycFe10Fp.png) > **Note**: The benchmarks displayed here were conducted on a linux box equipped with 2× AMD Epyc 7302 - 16c/32t - 2.8 GHz/3.35 GHz RAM 1000 GB ECC 2400 MHz. You can view the raw data [here](https://github.com/zkonduit/zkml-framework-benchmarks/actions/runs/7609045070/job/20719442408#:~:text=12-,%7B,%7D,-Post%20Run%20actions) ## Analysis EZKL demonstrates significant speed advantages over its competitors across all model types: > **Note**: All of the data below you can generate for yourself by running this benchmarking analysis [notebook](https://github.com/zkonduit/zkml-framework-benchmarks/blob/main/notebooks/benchmark_analysis.ipynb) in the ZKML framework benchmarks repo ### Linear Regression Model Results - **Proving Time Speedup**: EZKL demonstrates remarkable speed, being approximately 4.65 times faster than Orion and about 85.13 times faster than RISC0. - **Memory Usage Reduction**: EZKL shows efficient memory usage, utilizing roughly 67.04% less memory compared to Orion and about 98.53% less than RISC0. ### Random Forest Model Results - **Proving Time Speedup**: EZKL is about 28.14 times faster than RISC0. - **Memory Usage Reduction**: EZKL's memory efficiency is notable, using about 96.24% less memory than RISC0. ### SVM Classification Model Results - **Proving Time Speedup**: In this category, EZKL is approximately 2.09 times faster than Orion and about 117.59 times faster than RISC0. - **Memory Usage Reduction**: Here again, EZKL leads with roughly 59.72% less memory usage compared to Orion and 99.54% less than RISC0. ### Tree Ensemble Regression Model Results - **Proving Time Speedup**: EZKL is approximately 3.12 times faster than Orion and about 32.65 times faster than RISC0. - **Memory Usage Reduction**: EZKL continues to outperform, using roughly 64.95% less memory compared to Orion and about 98.21% less than RISC0. ### Overall Mean Results - **Proving Time Speedup**: On average, EZKL is approximately 2.92 times faster than Orion and about 65.88 times faster than RISC0. - **Memory Usage Reduction**: EZKL consistently uses less memory, averaging roughly 63.95% less than Orion and about 98.13% less than RISC0. ## Reflections on the Results So what explains EZKL's superior performance? Let's take a closer look at the underlying proof systems between the frameworks to find out why: **Underlying Proof Systems:** - **RISC0:** Implements a zk-STARK proof system using the FRI protocol, DEEP-ALI, and an HMAC-SHA-256 based PRF. - **Orion:** Based on Cairo, which also uses a zk-STARK proof system. - **EZKL:** Uses a proof system based on Halo2 and elliptic curve cryptography. It swaps the default Halo2 lookup for the [logUp lookup argument](https://www.youtube.com/watch?v=qv_5dF2_C4g). The substantial performance efficiency of EZKL over RISC0 and Orion can be largely attributed to the use of lookup table arguments and efficient einsum operations in Halo2. By representing non-linearities as lookup tables in the circuit, EZKL significantly reduces proving costs. These pre-computed input-output pairs for each non-linearity mean that complex computations are bypassed during the proof generation, leading to faster proving times. Additionally, the fact that EZKL is not a virtual machine (VM), unlike Cairo and RISC0, contributes to its efficiency. VM-based systems inherently introduce additional proving overhead because they cannot "see" and optimize higher-level operations. For example, applying 1000 nonlinearities, one after another, requires 1000 computations in a zkVM, whereas in EZKL the cost would be the same as if there was only one nonlinearity. In contrast, EZKL's domain-optimized and high-level approach to handling models and proofs enables it to compile circuits that are as fast as if they were hand-written. ## Conclusion The benchmark results show EZKL's significant performance advantages over RISC0 and Orion, in terms of proving times across various models. The underlying technologies, particularly the use efficient logUP and einsum arguments and the streamlined, non-VM approach, are key contributors to this efficiency. This makes EZKL an attractive option for applications where quick proof generation is paramount. EZKL can also handle a much wider variety of models. Beyond raw performance, EZKL minimizes the need for context switching. Our library enables users to execute the entire data science and zero-knowledge (zk) pipeline within a single Jupyter notebook. This seamless transition from model training to proving to verification is not just a matter of convenience; it represents a significant reduction in the cognitive load and technical barriers typically involved in such processes. Users can focus more on the analysis and less on the mechanics of transitioning between different stages of their workflow. In contrast, frameworks like RISC0 and Orion necessitate a considerable shift from the traditional data science workflow to the zk-specific tasks. This shift is not just conceptual but also practical. While the data science components are handled within a Jupyter notebook, the zk aspects are managed in a distinct Domain-Specific Language (DSL) environment outside the notebook. This bifurcation of workflow creates a disjointed experience, requiring users to mentally and technically switch between different environments and toolsets. For those who prefer to run the entire process within a notebook, RISC0 and Orion require the execution of a subprocess within a cell to initiate the necessary CLI command for proving. Therefore, EZKL's streamlined approach, which integrates the full data science and zk pipeline in a familiar and cohesive environment, stands out not just for its performance but also for significantly enhancing the overall developer experience. This ease of use, combined with superior performance, positions EZKL as the clear choice for developers and researchers building Zero-Knowledge Machine Learning technology.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully