Random: A marriage between crypto and AI

Sergey Surkov
4 min readOct 5, 2017

--

Crytocurrency + AI

Can we make blockchain train neural networks?

I’ve been reading a lot on cryptocurrency lately, and just like every other bystander, I can’t help but wonder how painfully inefficient and wasteful the whole mining process is. Here is what they do to make a ‘block’ in a blockchain. Once they have a block of data, they attach a random number to it. Compute the hash of the whole thing. Count zeros in the hash. If it’s the wrong number zeros, they then increment that random number and compute the hash again. The purpose of this is to prove some CPU power was applied so that it is very expensive for attackers to forge data on the blockchain.

The community then dresses up this process into professional lingo, and after you hear about “mining pools”, “hashing power”, and “proof of work”, it does not sound like a wasteful thing to do. But like I said, I am not the first to ponder this question, as no other than Vitalik Buterin, the famous creator of Ethereum, suggested back in 2012 that if Bitcoin miners could heat their homes with their mining rigs it would be “a very positive change”. Today, Ethereum is looking to get away from mining altogether by switching to a proof of stake consensus algorithm. It would have an effect of making the network more efficient, making the rich even richer, and putting all those mining rigs and their owners out of a job.

Here is something that could also work(even outside of Canadian/Russian climate zones). What if crypto miners were training deep neural networks? I don’t mean Golem style, where people sell their computing power, and use the blockchain to register their transactions. Golem relies on Ethereum for that. No, I mean we retain proof-of-work, but this work is the useful work of training a neural network. So instead of recomputing a hash of essentially the same data over and over again, nodes instead will be training somebody’s neural network, and their progress in this task will serve as a proof of work. Miners stay on the job and get paid with both newly minted currency _and_ with anything extra that the neural network owners decide to throw in to speed things up.

Most modern neural networks get trained using good old gradient descent, with gradient computed using backpropagation. Neural network gurus, including Geoffrey Hinton have been saying lately that backpropagation needs to go, and there may be other alternatives. For instance, Elon Musk’s OpenAI institute managed to make evolution strategies to learn to play Atari just fine. But, let’s assume that backpropagation is here to stay. How can backpropagation be inserted into the heart of the blockchain, and serve as a proof of work?

One way to parallelize training in deep learning is to use data parallelization — a very simple technique in which workers compute gradients for their own mini-batch each. These mini-batches have been traditionally small — usually up to a few hundred examples each — although the need to train with high degree of parallelization within a computer network have been spurring interest in making larger batches work, like Facebook did in their paper on large minibatch SGD. Once all workers are done processing their minibatches and have their gradients ready, the average or worker’s gradient is computed, and used to adjust weights in the neural network. These gradients that each worker computes can serve as a proof work.

Here is how. Each worker computes a gradient on its own minibatch. These gradients need to generally agree; otherwise, the gradient descent would not work. Once all workers finish, they send their gradients to each other. Since workers can’t trust each other, they will need to use a protocol that prevents one worker from stealing somebody else’s results. For instance, they can exchange encrypted gradients, collect each other’s digital signatures, and then reveal their keys so that they all can compute the average gradient and update the network weights thus concluding a single step of network training.

The process repeats until the training is complete. Workers then review all steps, and the worker whose minibatch gradients were closest to the average gets to issue a new block recording a mined reward for each worker on it. Since different neural networks have different difficulty, there should be a limit on the total volume of transactions that can be registered on the block. For a mining network to accept the new block, it will need to verify that steps in the training process indeed minimize the cost function of the neural network. After a block gets buried under a sufficient number of blocks, the neural network required for its verification can be discarded.

What do we do if a worker does not play by the rules and simply generates random numbers instead of properly computed gradients? Such workers could simply idle and collect the reward while others do all the work. The answer is simple: on each step a reward is only issued to workers whose gradient is reasonably close to the average computed across all workers. This may seem a little unfair: after all, it’s a stochastic process and there will always be honest workers who are simply unlucky. But over the course of the entire training process, things will even out and all workers should see a similar average reward.

We end up with a proof of work. Moreover, it’s a proof of useful work.

No, I am not starting an ICO with this idea.

I have https://sourcerer.io to build.

--

--