Skip to main content

Decentralized AI inference

Intermediate
Concept
DeAI

It's possible for canister smart contracts to run inference in a number of ways, depending on the decentralization and performance requirements.

Inference on-chain

Currently, ICP supports on-chain inference of small models using AI libraries such as Sonos Tract that compile to WebAssembly. Check out the image classification example to learn how it works.

Examples

  • GPT2: An example of GPT2 running on-chain using Rust.
  • ELNA AI: A fully on-chain AI agent platform and marketplace. Supports both on-chain and off-chain LLMs. Try it here.
  • Tensorflow on ICP: An Azle example that uses TypeScript and a pre-trained model for making predictions.
  • ICGPT: A React frontend that uses a C/C++ backend running an LLM fully on-chain. Try it here.
  • ArcMind AI: An autonomous agent written in Rust using chain of thoughts for reasoning and actions. Try it here.

On-chain inference frameworks

  • Sonos Tract: An open-source AI inference engine written in Rust that supports ONNX, TensorFlow, and PyTorch models, and compiles to WebAssembly.
  • MotokoLearn: A Motoko package that enables on-chain machine learning. The image classification example explains how to integrate it into a canister to run on ICP.
  • Rust-Connect-Py-AI-to-IC: Open-source tool for deploying and running Python AI models on-chain using Sonos Tract.
  • Burn: An open-source deep learning framework written in Rust that supports ONNX, and PyTorch models, and compiles to WebAssembly. The MNIST example explains how to integrate it into a canister to run on ICP. Try it here.
  • Candle: a minimalist ML framework for Rust that compiles to WebAssembly. An AI chatbot example shows how to run a Qwen 0.5B model in a canister on ICP.

Inference on-device

An alternative to running the model on-chain would be for the user to download the model from a canister smart contract, and the inference then happens on the user's device. If the user trusts their own device, then they can trust that the inference ran correctly. A disadvantage here is that the model needs to be downloaded to the user's device with corresponding drawbacks of less confidentiality of the model and decreased user experience due to increased latency. ICP supports this use case for practically all existing models because a smart contract on ICP can store models up to 400GiB.

Examples

  • DeVinci: An in-browser AI chatbot that uses an open-source LLM model served from ICP. Try it here.

Inference with HTTP calls

Smart contracts running on ICP can make HTTP requests through HTTP outcalls to Web2 services including OpenAI and Claude.

Examples