Roman Walch
    • 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
    > ## Text from Telegram 1. Detailed spec of 1.1 ONNX standard-compliant circuits (as listed in here https://github.com/onnx/onnx-mlir/blob/main/docs/SupportedONNXOps-cpu.md) formal description. Just like we did once in here: https://github.com/NilFoundation/solana-state-proof/blob/master/docs/design/main.pdf. Some of those from ONNX standard are already present on our side - let's coordinate about this. 1.2 Analysis about if there is sense to reduce from MLIR to LLVM IR. 1.3 If it makes sense, then how to lower MLIR to LLVM IR efficiently enough and which extensions LLVM IR has to have. 1.4 More efficient circuits definition done for a particular example use case. (Example should be big and ambitious one for this to worth it to you guys, so let's make it some trivial LLM-alike one? We have some circuit estimations about such one) 1.5 Analysis about necessary proof system efficiency improvements. ## Questions * Cost metrics for their proof system, how does adding rows/columns affect size/time? [R] * List of Operations in MLIR (e.g, arith.cmpf, affine.for, affine.max) [R] * Is pattern matching even feasible at the MLIR level? * Can the ONNX to MLIR compiler be modified easily? * MLIR has the concept of hardware accellerators, can we somehow "hook" in there? * Existing literature for zkML in plonkish arithmetization systems [R] * https://arxiv.org/pdf/2210.08674.pdf * https://drive.google.com/file/d/1tylpowpaqcOhKQtYolPlqvx6R2Gv4IzE/view * https://hackmd.io/Y7Y79_MtSoKdHNAEfZRXUg * Approximation of exp, etc (see Wiki) [R] * Approximation in training -> Cannot use existing models as easily. * Look into quantization more * Fixed-point planning [R] * Select fixed point scale factor * Algorithms for Add, Mul, BitExtract, Rescale * Floating-point investigation [R] * https://www.plonk.cafe/t/draft-plonk-intermediate-opcode-representation/45 * Other methods for floating points in (sign, mantissa, exponent) format * https://eprint.iacr.org/2021/1063.pdf (Cairo, sec 8.3, p45) * Specialized Functions [R] * ReLU (Max, signextract, etc) * Approximated ReLu with Poly already in training <https://arxiv.org/pdf/2011.05530.pdf> * Math (exp, sin, cos, tanh, ...) * Approximate via rational methods <https://xn--2-umb.com/22/approximation/> * <https://xn--2-umb.com/22/exp-ln/> * Model constants * Where to put them in the trace? * Generic stuff, like how big is a trace with just the model constants in there? is this already a problem, re Cost Metrics above. * GPT-2 as a case study: * <http://jalammar.github.io/illustrated-gpt2/> * Token embedding is 50207x768 = Already 38M... * Is needed for each input token + at the end of each of the 12 layers * Matrix needs to be repeated in the trace probably... * Also this is only for 1 token...gpt2 can do up to 1000 * Alternative LLMs: <https://huggingface.co/> * BERT? * Mini-Bert: https://huggingface.co/prajjwal1/bert-mini/tree/main * MiniLM <https://huggingface.co/microsoft/MiniLM-L12-H384-uncased>, <https://huggingface.co/nreimers/MiniLM-L6-H384-uncased> * Recursion, Folding, etc... * Investigate Methods used in RiscZero * <https://geometry.xyz/notebook/sangria-a-folding-scheme-for-plonk> * Cannot do lookup arguments atm * ONNX layer * Existing libraries to parse this (in C++?) * Selection of important blocks from <https://github.com/onnx/onnx-mlir/blob/main/docs/SupportedONNXOps-cpu.md> * Existing libraries to work with ONNX (the python lib can do size inference for example, which is pretty much required for us to work with the model later on, but this can be "baked into" the ONNX model) * Assigner Formats * Reverse Engineer their format, ask for documentation * Enables us to write assigner in other language * Need to keep in sync with C++ version * Basic Matrix Multiplication * Investigate layouting matrix in trace * Advanced * Existing zkML Code stuff * <https://github.com/0xZKML/zk-mnist> MNIST in Circom * <https://github.com/socathie/circomlib-ml> Basic ML building blocks in Circom * https://github.com/worldcoin/proto-neural-zkp * <https://github.com/ddkang/zkml> Probably pretty advanced? 8s for MNIST proving, blog post below is even targeting gpt... * https://medium.com/@danieldkang/verified-execution-of-gpt-bert-clip-and-more-6acb693fd55f * https://arxiv.org/pdf/2210.08674.pdf * https://github.com/lyronctk/zator # Spec: # Introduction The goal of this zkML project is to extend the [zkLLVM project](https://github.com/NilFoundation/zkllvm) with capabilities to prove machine learning inference. # Milestones 1. Detailed Spec. Report (2 months, 3 developers) 2. ONNX-frontend implementation (TODO) 3. Example use case implementation (TODO) ## Milestone 1: Detailed Spec. Report In the first phase of the project we will investigate the following questions: - The base will be ONNX models: - We will investigate the efficient arithmetization of the most important/used operations of the [ONNX standard](https://github.com/onnx/onnx-mlir/blob/main/docs/SupportedONNXOps-cpu.md) - We will base our selection of supported operations on an investigation of the operations used in the most-used ONNX models on huggingface.co - We will investigate which custom gates we would need to efficiently arithmetize these standard operations - e.g., dot-product components that can be re-used for matrix multiplication and convolutions - These components are built with respect the the floating/fixpoint arithmetization findings below - We will provide detailed trace layouts and constraints for the components to quantify their concrete costs - Floating/Fixpoint Arithmetization: - Most state-of-the-art literature suggests using fixed-point representations of the involved floating point values. We will investigate how to efficiently represent them in the context of ML models and how to arithmetize rescaling operations. - We will investigate ways to combine the fixed-point representation with the custom gates above, e.g., rescaling could happen after the dot-product component instead of directly rescaling each multiplication result. - We will investigate quantization processes for existing models or potential support for already quantized models. - Compilation chain: - We will investigate the best place to make our customiztions: - ONNX graph -> ONNX-MLIR dialect: - ONNX MLIR is a representation of the ONNX graph in MLIR, with several optimizations already applied by the ONNX-MLIR backend. This is a high-level (op-level) view of the ONNX graph that would allow us to build more efficient components. - Allows for the highest degree of freedom in arithmetizing the blocks - ONNX graph -> ONNX-MLIR -> Affine MLIR dialect - The affine MLIR dialect is a breakdown of the ONNX MLIR into krnl-dialect which is then mapped to affine-dialect - Affine dialect works with low-level loops and floating point math operations, which is harder to map to specific, more efficient custom gates - ONNX-MLIR hardware accelerators: - ONNX-MLIR has the concept of hardware accelerators for specific functions. - This could also be a an alternative point to hook into the existing ecosystem - We will conduct experiments to justify our findings in the report - Showcase on ML model: - We will showcase our findings by applying them to a specific ML model. - Could be GPT-2, MINI-BERT, or similar - These models already have millions of parameters which need to be efficienlty included in the execution trace - We will investigate the tradeoffs in efficient circuit layouts (i.e., optimizing the prover cost metric) - We will investigate useful extensions of the proof system that would enable more efficient implementation of specific ONNX operations - We will investigate the feasibility of using smaller field sizes in the proof system for increased efficiency - We will investigate if recursion can be applied to improve efficiency ## Milestones 2: Finishing ONNX Frontend with supported ONNX operations Phase 2 will start with a retrospective meeting on the findings of the report in phase 1 and how they influence and change the plans layed out below for phase 2 and 3. After feedback on the findings of the report and integration of potential changes into the work packages below, we will work on implementing our findings into an ONNX frontend. The frontend will consist of the following parts: - A CLI application that can accept ONNX models and inputs to these models and 1. Compiles them to ONNX-MLIR dialect identified in the report. 2. Evaluates the model on the input in the chosen (e.g., fix-point) representation 3. Performs the trace layouting for the model circuit 4. Generates the assignment for the trace 5. Hands the trace and assignment off to the low-level prover to create the proof 6. Can verify produced proofs locally To facilicate the above frontend we will provide: - Implementation of a parser for the ONNX-MLIR dialect identified in the report - This parser will essentially be a counterpart to the assigner, focusing on layouting and assigning the circuit components for the ONNX operations - The parser and components will follow findings of the report with respect to the fixed-point representation - Implementation of the custom components identified in the report in the low-level blueprint library - The individual components will follow the findings of the report - These components will allow the proving of all ONNX operations currently supported in ONNX-MLIR, taking into account limitations of the ONNX-MLIR layer and any limitations identified in the report - https://github.com/onnx/onnx-mlir/blob/5924af533182902d568d4765bc26be1f758bb1d5/docs/SupportedONNXOps-cpu.md - Unit Test for the individual ONNX operations - For each implemented ONNX operator at the MLIR level, we will provide one or more unit test ensuring the functionality of the individual operations - Benchmarks and concrete component sizes for different operators - Examples - We will provide a few end-to-end examples showcasing the functionality of the system for a few chosen well-known models. ## Milestone 3: Example use case implementation This milestone focuses on the implementation of the use case considering findings in the report from Milestone 1, using the functionality implemented in Phase 2. - Implementation of a concrete use-case to showcase the functionality of the ONNX frontend - The concrete use case is planned to follow the analysis of the large model from the report in Phase 1 (GPT-2, MINI-BERT, etc.) - However, potential changes due to the findings of the report might lead to a different choice of use-case - The implementation will consist of a demonstrator using the functionality implemented in Phase 2 to prove inference of a large machine learning model. - This demonstrator will consist of a prover and verifier and documentation on how to use them (and what kind of resource requirements exist) - Deployment via a Docker image will be supported - We also aim to provide an already computed proof so more resource-limited clients can just execute the verifier

    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