Running Artificial Intelligence on the Blockchain by@mywaymywei

Running Artificial Intelligence on the Blockchain

Read on Terminal Reader
react to story with heart
react to story with light
react to story with boat
react to story with money

This article is the third part of a series on AI on blockchain Ecosystems. In these overviews, I will provide outlines of why we need it, how is it achieved, and what does it offer.

Article Series:

- Part 1: AI on Blockchain — What’s the catch?- Part 2: AI Smart Contracts — The Past, Present, and Future- Part 3: Running Artificial Intelligence on the Blockchain- Part 4: Cortex AI on Blockchain Ecosystem- Part 5: AI on Blockchain Use Cases

Smart contracts, known to be used with the blockchain technology, is a computer program that directly controls the transfer of digital currencies or assets between parties under certain conditions. However, there is one particular characteristic that is lacking which ceases a wider application for smart contracts. In spite of many games and pyramid scheme DApps, this feature is a prominent reason why smart contracts have not been very successful thus far — AI Smart Contracts.

So what is AI?

Artificial Intelligence (AI) is not a new term, it has been around since the 1950s. Artificial Intelligence can be defined as human intelligence exhibited by Machines. Earlier works of AI used methods like A*, fuzzy logic, expert systems, and good old-fashioned AI (GOFAI), the same if-then rules that are used in coding most applications including smart contracts. Deep Blue, the AI created by IBM that defeated the world chess champion Garry Kasparov in 1997, used a method called search algorithms to evaluate millions of moves at every turn.


Deep Blue vs Garry Kasparov

When we speak of AI nowadays, we are actually talking about Machine Learning, an approach to achieve Artificial Intelligence.

Machine Learning works by building models that capture weights and relationships between features from historical data and then use these models for predicting future outcomes.

In 1959, Arthur Samuel, one of the first pioneers of machine learning, developed the first-ever machine learning program that learned how to play checkers better than him. Nowadays, advanced statistics and data are readily available on the internet such as for NBA statistics and Kaggle, heaven for data scientists to discuss their findings and gather datasets. There are open-source courses like and that make deep learning, a technique for implementing machine learning, accessible to everyone. Which sports geek wouldn’t like to create their own system for predicting matches?


A visually stunning presentation of NBA match using data from by panos

In 2016, Alpha Go defeated Go world champion Lee Sedol in board game Go (Go is a Chinese board game which the aim is to surround more territory than the opponent). Alpha Go, developed by Google, used a combination of machine learning and tree search techniques which was trained with a database of around 30 million moves then used reinforcement learning, a subset of machine learning, to play against itself to improve its play.


Alpha GO vs Lee Sedol

How AI on the blockchain makes sense

In a recent interview with MIT Technology Review, Yoshua Bengio, one of the fathers of AI, has expressed his concerns with just a few companies dominating the field of AI. He believes in democracy in AI research as AI research tends to lead to concentrations of power and money. Jeremy Howard, Kaggle master and CEO of, stated that "For its(AI) full potential to be met, the technology needs to be much easier to use, more reliable, and more intuitive than it is today."

AI could leverage blockchain in various ways:

  • Make smart contracts “smart” — To expand and diversify the capability of smart contracts. Cortex aims to integrate AI into smart contracts to allow AI functionalities creating truly intelligent smart contracts and enhanced DApps with more diverse use cases;
  • Lower the market barriers — Model training requires tons of computational powers that cause a fortune of money to do so. DeepBrain is using AI and blockchain technologies to develop a distributed AI computing platform that is low-cost and privacy-protecting for a new way to train AI (Try it out here). Cortex will also provide an off-chain solution with low-cost for AI companies to do AI research;
  • Help AI explaining itself — Currently, AI is more of a black-box solution, while the blockchain tends to be more transparent in all the transactions processed. Cortex allows AI model upload to the blockchain and makes AI inference (aka machine learning execution) on-chain which creates an audit trail to improve the trustworthiness of the results;
  • Democratize AI models — Rather than relying on big companies to get access to machine learning models, it’s important to have models under the user’s control. SingularityNET lets anyone create, share, and monetize AI services at scale;

Pain points of running AI on the blockchain

It is not an easy task to allow machine learning models to run on the blockchain.

  1. Successful deep learning models often require significant amounts of computational resources, power, and money to run, which poses an obstacle to performing well on the blockchain;
  2. As the scale of deep learning networks increases, the computational complexity increases, and the size of the model also increases accordingly;
  3. The actual use of the model requires efficient inference tools that returns the same inference results on different machines;


Let’s take an example, as shown in the image above, the parameters of the original deep learning neural network are float variables that need 32-bits storage space. If the model can be converted into a state with only three values (-1, 0, +1), the storage would only take up 2-bits, which significantly compresses the storage space. Moving from 32-bits to 2-bits, we get (almost) 16x reduction in memory. Lower bit-widths allows more data into the same caches which reduce the frequency to access from RAM. In addition, having floating point arithmetic is not ideal as it is not well-supported on microcontrollers on some low-power embedded devices (like IoT devices).

And the answers suggest we could modify the models that require less storage and computation power but with lower precision — Compression and Quantization.

Compression modifies the large cumbersome models that reduce the memory requirements while retaining as much of its precision as possible. Lighter models mean less storage space and easier to share over smaller bandwidths.

Quantization is the process of reducing the number of bits needed to store an integer value by reducing the precision of the integer. Quantization in deep learning combines high performance with lightweight inference which reduces the computation and memory costs. Quantization allows models to be executed on the blockchain with relatively low cost but also provides consistent inferred results.


TinyPNG uses quantization to convert 24-bit PNG files to much smaller 8-bit indexed colour images

With model compression and quantization in place, Cortex proposed “Synapse”, an integer inference engine to do deterministic AI inference, to make machine learning accessible on the blockchain. One of the core Synapse capabilities is to guarantees exactly the same result of an AI model in heterogenetic computing environments (you can try out the TestNet now). determinacy is crucial in the blockchain, as consensus has to be formed upon smart contract outputs. It is non-trivial for widely-used AI inference engines (TVM, NNVM, etc.) to guarantee the determinacy because modern GPU introduces parallelism into the execution flow. Synapse utilizes both quantizations of AI models and deterministic GPU acceleration to make AI DApps available. With the help of GPU hardware acceleration, AI inference subroutines could behave like a dedicated SHA function in the blockchain’s virtual machine, public verifiable and deterministic.

To Sum Up

  • AI Smart Contracts is a much-needed feature for real-world DApp use case.
  • AI is one of a loose term, which can be applied to anything ranging from rule-based application to human intelligence that hasn’t been invented yet.
  • When we speak of AI nowadays, we are talking about Machine Learning, an approach to achieve AI.
  • Machine learning is software that learns from examples where you provide large sets of relevant data to train the algorithms.
  • The design of machine learning models with quantization and compression in mind requires less storage and computation power.
  • Synapse deterministic AI inference proposed by Cortex guarantees the same inference result in heterogenetic computing environments.

If you are interested in learning deep learning, check out Jeremy Howard's and Andrew Ng's! There are also many GPU cloud services that offer a free trial (like Digital Ocean)and free cloud computational environments (like Google Colab and Kaggle Kernels)to get you started with ease.

react to story with heart
react to story with light
react to story with boat
react to story with money
. . . comments & more!