This repo contains a demo of how you can run an AI model and commit its result on-chain, using Bonsol.
For this demo we created a small CNN, with two convolution layers and a fully connected output layer, about 2k params in total. We used the MNIST database and during training it achieved an accuracy of 95% approximately, not bad for such a small model.
Later we ported the model to RiscZero and Bonsol and it takes about 500ms to run and 5-10min to generate the proofs using CUDA.
To run it you must first start a Solana Test Validator and deploy the Bonsol program.
solana-test-validator --rpc-pubsub-enable-block-subscription --bpf-program BoNsHRcyLLNdtnoDf8hiCNZpyehMC4FDMxs6NTxFi3ew /PATH-TO-BONSOL/target/sbf-solana-solana/release/bonsol.so --limit-ledger-size 100000Now run the test server, to upload the Bonsol Image. Clone the bonsol repo:
cd bonsol
cargo run -p local-zk-program-serverThen build and deploy the Bonsol program:
cd ai
bonsol build
bonsol deploy url --url http://localhost:8888 --manifest-path manifest.jsonNow you can start the node using the default config from the Bonsol repo:
bonsol-node -f Node.tomlFinally, you can run the tests by doing:
cd ai-onchain
anchor test --skip-local-validator