Notfounderror On Opkernel When Using Tf.nn.embedding_lookup In Tensorflow Eager Mode
Solution 1:
What is happening here is that you're explicitly asking for the loss computation to execute on GPU (by placing the call to tf.nn. sampled_softmax_loss
in the with tf.device("/gpu:0")
block), but it can't since the underlying operation is not implemented for GPU.
This error isn't specific to eager execution, you'd get the same error with graph execution as well (e.g., using with tf.Session() as sess: print(sess.run(loss))
)
If you structure the code to be less prescriptive about where individual operations should execute, it will give TensorFlow the flexibility to run the operation where it can. For example, move the loss computation outside the with tf.device
block:
with tf.device('/gpu:0'):
embed = tf.nn.embedding_lookup(embeddings, train_dataset) #the ID can be a list of words
loss = tf.reduce_mean(tf.nn.sampled_softmax_loss(weights=softmax_weights, biases=softmax_biases, inputs=embed,
labels=train_labels, num_sampled=num_sampled, num_classes=vocabulary_size))
print(loss)
A side note: In TensorFlow 1.7, eager execution does not use a GPU without an explicit with tf.device("/gpu:0")
. However, with the next version of TensorFlow a GPU will be used if possible even when there is no explicit device specification (more details in tensorflow/tensorflow#14133). So, if you're able, I'd suggest using 1.8.0-rc0 instead of 1.7.0-rc1 and then you can do away with the with tf.device("/gpu:0")
completely.
Hope that helps.
Post a Comment for "Notfounderror On Opkernel When Using Tf.nn.embedding_lookup In Tensorflow Eager Mode"