How do I make tensorflow evaluate tensors in parallel?

随声附和 提交于 2021-01-29 14:15:30

问题


From my understanding tensorflow makes a computational graph and then when I run the session it evaluates this graph and does what it can in parallel. How do I as a user make sure/check that tensorflow is doing stuff in parallel? Suppose I have the following code:

x = tf.placeholder()
y = x**2 + 123
z = 5*x/(x+2)
res = y+z

When I evaluate res, is y and z calculated in parallel? Also, from my testing it appears that building the graph inside a for loop breaks something because when I've tried to run the following code (but with more complex calculations) it does not appear to run in parallel:

x = tf.placeholder()
y_list = []
for i in range(100):
   y_list.append(i*x + i)
res = np.sum(y_list)

I am running tensorflow with a GPU card and the time it takes to run the session depends linearly on the range of the for loop, which tells me that it does not evaluate the elements in y_list in parallel. How do I tell tensorflow to evaluate them in parallel?

来源:https://stackoverflow.com/questions/62169648/how-do-i-make-tensorflow-evaluate-tensors-in-parallel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!