GizaModel
Welcome to the step-by-step guide for using GizaModel
within the Actions SDK, a key component of AI Actions. GizaModel
is designed to streamline the integration and management of machine learning (ML) models in blockchain workflows using ZKML. This guide will walk you through the process of model building, transpilation and deployment of GizaModel
in your projects.
Running an unverifiable inference involves executing the ONNX model locally, whereas a verifiable inference entails executing the transpiled ZK version on the Giza platform to generate a ZK proof of the inference.
Executing Unverifiable Inference with GizaModel and ONNX
To execute an unverifiable inference, initiate a GizaModel
with the path to your ONNX model file. Use the predict
function, setting the verifiable
parameter to False
. Below is an example in Python:
Executing Verifiable Inference with GizaModel and ONNX
To enable verifiable inference, the model must first be transpiled to Orion Cairo, allowing execution on CairoVM to generate trace and memory files for inference proof.
Transpiling from ONNX to Orion Cairo
To transpile your ONNX model to Orion Cairo, execute the following command in your terminal:
This converts your model to Cairo, providing a model-id
and version-id
for deployment on the Giza platform. The deployment process on our platform sets up services that handle prediction requests via a specific endpoint, utilizing Cairo for provable inferences.
When we transpile a model we have two possibilities: a fully compatible model and a partially compatible one.
A model is fully compatible when all the operators that the model uses are supported by the Transpiler and Orion, if this happens the model is compiled after transpilation and we save the .sierra file on behalf of the user to use later for deployment. This will be shown in the output of the transpile command:
If a model is partially supported, we will create a warning in the output stating that not all the operators are supported right now. If it is partially supported the Cairo code can still be modified for later compilation and deployment.
You can check all operators supported by the transpiler here. We are actively working to support more operators.
If a model is partially supported
As previously mentioned, if a model is only partially supported during transpilation, you can finetune your Cairo project to ensure successful compilation. Once your Cairo project compiles without errors, you can proceed to build it and obtain the Sierra file necessary for deployment. The Sierra file serves as an intermediate representation bridging the high-level Cairo code and compilation targets. To deploy your Cairo model, it is essential to compile your transpiled model using Scarb to generate this file:
Once your transpiled project compiled, Sierra file will be located in the target/dev/inference.sierra
directory.
Deploying the Transpiled Model
For deployment, use the deploy
command as shown below, which prepares your machine learning service to accept predictions at the /cairo_run
endpoint:
If a model is fully compatible the sierra file is not needed and can be deployed without using it in the command:
For a partially compatible model the sierra file must be provided, if not an error will be shown.
Running a Verifiable Prediction
With your Cairo model deployed on the Giza platform, you can execute verifiable predictions. This involves running the Sierra program on CairoVM to generate trace and memory files for proof, returning the output value and initiating a proving job for a Stark proof:
A prediction in verifiable mode, return result and request id. The request id can be used to download the ZK proof.
Downloading the ZK Proof of an Inference
After running your model, CairoVM generates the necessary files to prove your program. You can download the ZK proof generated for your inference as follows:
Last updated