The piece of code below works fine when I am using the CPU as device, however it fails when using GPU. This is the error I am getting:
InvalidArgumentError (see above for traceback): Cannot assign a device for operation 'Adam/update_Variable/Cast_5': Could not satisfy explicit device specification '/device:GPU:0' because no supported kernel for GPU devices is available.
Based on that, I am assuming there are no GPU gradients for nested map_fn calls, is that the case? If true, is there any way I can implement that same piece of code, so it works on the GPU, while keeping the two nested functions?
Thanks.
import numpy as np
import tensorflow as tf
def loop_inner(x):
return tf.reduce_sum(tf.square(x))
def loop_outer(x):
return tf.map_fn(lambda x: loop_inner(x), x)
np.random.seed(10)
io, d, k, m = 2, 4, 3, 2
A = np.random.random((io, d, k, m))
with tf.device('/cpu:0'):
sess = tf.Session()
A = tf.Variable(A)
B = tf.map_fn(lambda x: loop_outer(x), A)
L = tf.reduce_sum(B)
optim = tf.train.AdamOptimizer(learning_rate=0.1).minimize(L)
sess.run(tf.global_variables_initializer())
for i in range(1000):
sess.run(optim)
print(sess.run(L))