Running Deep Learning on EVM

I guess techniques such as quantization would become very important in this scenario.

1 Like

Interesting - never used it before. My understanding of the idea is that you cant train in low precision, but once trained, you can quantize to low precision and it will still work …

I mean this is only an issue in usecases like the dUber case, and to be honest the more I think about this, the further I go down the rabbithole, and the less it has to do about the specific issue of doing a forward pass in a neural net.

However, in the case, it’s the drivers and the passengers that create the training data. If you could somehow verify that the network is trained on a set of transactions…

Why not solve it in a simpler way:
To work on a job, you will need to stake some amount of ether
When creating a job, you send a swarm hash for the set of data to be predicted upon.
Along with this hash, the sender also submits a salted verfication set
A number of nodes then perform the prediction and salt their result hash, which is merkle tree encoded (it needs to be a quantized result to avoid differences in floating point implementations)
When enough nodes have submitted their hash, they reveal their hash.
When the hashes have been revealed, the submitter reveals the salt for the verification, this decodes the verification which then loops through the different answers, verifying if they’ve correctly computed the verification answers. Any node that tried to cheat is robbed off their staked eth. The rest split the reward for the computation.

In my opinion, DL might be an overkill for a Uber driver evaluation model on the EVM, especially since the EVM does not support vector operations at the moment (see EIP-616 for an interesting proposal).

To me, it seems like an off-chain solutions like Truebit could be a better way of tackling this problem.

If you create multiple nodes and submit the same answer multiple times, you will get a bigger piece of the pie.
A more sophisticated version of your proposal by @kladkogex was discussed in this thread and seems to encourage centralization.

The problem is that there is currently not a single person in the world that can mathematically prove TrueBit security.

Most good BFT and Blockchain protocols have reasonable mathematical models proofs that prove security either deterministically or at least probabilistically at least under some assumptions (such as 2/3 of nodes, deposits, PoW, you name it …)

I wonder if it would be feasible to take something like keras.js and port it to a solidity library.

Just for clarity. Keras is a Deep Learning framework that uses TensorFlow behind the scenes. It’s basically an abstraction on top of TF to make working with TF more pleasant and higher level.

Now what keras.js enables is, you can take a trained model and run the predictions in the browser. I wonder if the same approach could work for Ethereum. So you take a trained Keras model which essentially is just a huge bag of numbers and then run a couple of matrix multiplications and geometric functions over them to get the prediction. This is basically what keras.js essentially does.

I think there’s nothing really that would want prevent one to apply the same approach in solidity, right? Just the fact that the more complex the model is the more gas would it take to run the predictions.

1 Like

Chris - thank you, I was aware of Keras but not aware of Keras.js. Keras is definitely the leading library now for abstracting out deep learning implementation details.

The question is how whats the MVP implementation to add a Keras.js like prediction opcode to Ethereum Virtual Machine, because Solidity ultimately gets compiled into EVM.

Here is a link to Ethereum Yellow paper that describes the current EVM implementation

Ethereum Yellowpaper

Keras is definitely the leading library now for abstracting out deep learning implementation details

I agree. We’re working on a Machine Learning platform that lets people start playing with Keras and other ML libs from right within the browser (even though we also have a CLI around the corner). Experiments run on our cloud infrastructure though.

For instance, here’s a link to some easy Reinforcement Learning experiment that I did:

https://machinelabs.ai/editor/SyPFkpjEG/1516292262547-ByJnOH0V

Back to the topic:

Well, I think if it doesn’t exist yet then probably an opcode for matrix multiplications would be useful. But even without that it should be possible to just come up with an MVP state solidity library that does the basic math on top of todays EVM.

After all, you can do matrix multiplications by hand:

https://www.mathsisfun.com/algebra/matrix-multiplying.html

So the way I understand it, one could build a keras-solidity library today even though it may be inefficient unless further opcodes are added to improve the speed of some underlying mathematical operations.

The idea to integrate support for neural networks into Ethereum recently started to rotate in my head too, glad to have found this thread - @kladkogex please keep us updated!

I guess Vitalik’s scepticism comes from the assumption that the intention is to run deep learning on-chain. But the point is to use models trained off-chain and only do inference on-chain (which is much cheaper).

My line of thought was not to integrate it into the EVM, but to add it as a kind of additional runtime, similarly to how Parity allows WASM contracts alongside EVM contracts (see doc - at least that’s how I understood it).
Similarly, an Ethereum client could be extended with a runtime for neural networks (I guess Tensorflow/Keras would be best suited). That way it should be possible to run these computations more efficiently (e.g. even using GPU support).
It may be a bit of a challenge to guarantee deterministic results, thus quantization may be a good idea not only for performance.
The EVM would only need a mechanism for making a call to the neural network runtime and handle its result.
This is however just an intuition driven guess about what a reasonable architecture may look like as I don’t yet have much expertise in ML.

Besides hitting buzzword/bullshit bingo, I’m quite sure such a construction would open up a huge new playing ground. Putting an AI in charge of distributing economic rewards (this could be tokens created out of thin air) sounds like a pretty powerful possibility to me…

1 Like

Does any one here know how to run Tensorflow in a reproducible fashion on different NVIDIA cards?

We are adding Tensorflow as a set of pre-compiled smart contracts. For the software version of Tensorflow we can get it to be reproducible by fixing seeds of the pseudo-random generator and then compiling using -sse2 flag of gcc …

Have no idea if it’s possible to do with tensorflow, but might be possible with keras using the theano backend?

“I am not saying EVM is a perfect place to run neural networks, on the other hand making it some kind of an simple extension to EVM/Solifity would draw many developers. Another possibility is to run a totally different thing and then feed the results into Ethereum somehow …”

Is it possible to enhance EVM/Solifity APIs to make external calls to Deep NN and RDBMS ?
The data from one node in blockchain will be transformed by DNN / RDBMS and sent to other nodes.
Is this possible ? How hard will be to implement such a thing ?

2 Likes

Thats what we do on our system. The NN needs to be executed in a decentralized way though - it cant be a centralized server.

You do not need to run the NN on all nodes of the chain though. A subset is enough if all agree, and then if there is a single disagreement you can run it on a larger set of nodes, and then punish the party that made an incorrect calculation.

For instance, in a network where 1/3 of nodes is Byzantine it is enough to run the NN on 48 randomly picked nodes, since the probability of all of them being Byzantine is 10^{-22} which is a very small number

Trusting the prover who must know the weights (in order to generate a proof) is relatively acceptable. What I think is less realistic though is disclosing the inputs to feed the “private” neural network.
I don’t see that happening on a regular basis, except in the quite specific use case you mention.

As discussed in this thread a neural network that is stored in a smart contract could be potentially fooled by a purposefully constructed malicious data ( although supplying purposefully constructed data may not be feasible. For instance if the connection between a camera and the blockchain is secure, the image can not be modified by the attacker)

A question is whether malicious data could be filtered out by applying a set of multiple networks with potentially different parameters.

Another interesting possibility is to generate lots of malicious data samples and then to have a dedicated network that detects malicious data samples

I think what we know that a human brain can not be easily fulled. One can not create a picture of a dog that looks like a cat. There is some “anti-fooling” mechanism in the human brain

[/quote]

2 Likes

[quote=“kladkogex, post:26, topic:899”][/quote]
I think what we know that a human brain can not be easily fulled. One can not create a picture of a dog that looks like a cat. There is some “anti-fooling” mechanism in the human brain

^^

1 Like

I retract ))) :joy::joy::joy: