tensorflow: tf.matrix_inverse() is slow compared to numpy.linalg.inv

Running this snippet

import numpy as np
import scipy as sp
from datetime import datetime
import tensorflow as tf

s = tf.Session()
dim = 3000
mat = tf.random_uniform((dim,dim))
s.run(tf.initialize_all_variables())
matinv = tf.matrix_inverse(mat)
st = datetime.now()
s.run(matinv)
print "time elapsed tensorflow:", datetime.now() - st

st = datetime.now()
x = np.random.rand(dim,dim)
sp.linalg.inv(x)
print "time elapsed scipy:     ", datetime.now() - st

yields this output

I tensorflow/core/common_runtime/gpu/gpu_device.cc:643] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 750 Ti, pci bus id: 0000:01:00.0)
time elapsed tensorflow: 0:00:18.078232
time elapsed scipy:      0:00:01.613825

1.6 sec (Scipy) vs. ~18 sec (tensorflow), that’s a huge difference.

  • Is this expected behavior?
  • Why is TensorFlow so slow when inverting a matrix? I was hoping it leverages the GPU.
  • Is there a way to improve the TensorFlow runtime duration?

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 22 (6 by maintainers)

Commits related to this issue

Most upvoted comments

Hello! Any news on this regarding GPU implementation?