Skip to main content

Types of inference

Intermediate
Concept
DeAI

Overview

Inference in the context of decentralized AI refers to using a trained model to draw conclusions about new data. It's possible for canister smart contracts to run inference in a number of ways depending on the decentralization and performance requirements.

Canisters can utilize inference run onchain, on-device, or through HTTPS outcalls.

Inference onchain

Currently, ICP supports onchain 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 onchain using Rust.
  • ELNA AI: A fully onchain AI agent platform and marketplace. Supports both onchain 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 onchain. Try it here.
  • ArcMind AI: An autonomous agent written in Rust using chain of thoughts for reasoning and actions. Try it here.

Onchain 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 onchain 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 onchain 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 onchain would be to download the model from a canister, then run the inference on the local device. If the user trusts their own device, then they can trust that the inference ran correctly.

A disadvantage of this workflow is that the model needs to be downloaded to the user's device, resulting in less confidentiality of the model and decreased user experience due to increased latency.

ICP supports this workflow for most 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