Skip to content

Instantly share code, notes, and snippets.

@seominjoon
Created May 4, 2017 16:54
Show Gist options
  • Save seominjoon/0326ebb0d1d85f1d31e784051f689b86 to your computer and use it in GitHub Desktop.
Save seominjoon/0326ebb0d1d85f1d31e784051f689b86 to your computer and use it in GitHub Desktop.
tensorflow CPU speed test
import tensorflow as tf
import numpy as np
import time
from tensorflow.contrib.rnn import BasicLSTMCell
N = 1
L = 500
d = 10
k = 1
V = 1000
inputs = tf.placeholder('int64', [N, L])
emb_mat = tf.get_variable('emb_mat', shape=[V, d])
x = tf.nn.embedding_lookup(emb_mat, inputs)
lstm_cell = BasicLSTMCell(d)
a, (c, h) = tf.nn.dynamic_rnn(lstm_cell, x, dtype='float')
init_op = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init_op)
inputs_val = np.zeros([N, L], dtype='int64')
t0 = time.time()
for _ in range(k):
out = sess.run(h, feed_dict={inputs: inputs_val})
t1 = time.time()
print(t1 - t0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment