Skip to content

Instantly share code, notes, and snippets.

@iaroslav-ai
Created June 19, 2016 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iaroslav-ai/d6f7e594923073ec26696eabca76bed0 to your computer and use it in GitHub Desktop.
Save iaroslav-ai/d6f7e594923073ec26696eabca76bed0 to your computer and use it in GitHub Desktop.
Estimates the time needed to compute forward pass of neural net of size of human brain (10^15 synapses). Assumes that synapse implements function which can be well approximated by multiplication.
import numpy as np
import theano
from theano import tensor as T
# synapses to compute at once
N = 2 ** 13
M = N
Sym_rep = 16
x = np.random.randn(N).astype('float32')
print "compiling ..."
xt = theano.shared(x)
yt = xt[:N]
for i in range(Sym_rep):
Wt = theano.shared(np.random.rand(M, N).astype('float32'))
yt = T.maximum(0, T.dot(Wt, yt) )
fp = theano.function(inputs=[], outputs=[yt], allow_input_downcast=True)
print "computing ..."
# number of synapses simulated
S = N * M * Sym_rep
# number of synapses in human brain
H = 10 ** 15
from time import time
reps = 10
st = time()
for i in range(reps):
#y = np.maximum( 0, np.dot(W,x) )
y = fp()
d = time() - st
perbatch = d / reps
brain_forward = perbatch * (H / S)
print "time in seconds for forward pass of whole human brain, s: ", brain_forward
print "time in seconds for forward pass of whole human brain, h: ", brain_forward / 3600
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment