I'm using TF 2.13.0 and I'm getting an error only when eager execution is enabled. Is there a workaround?
The error is
tensorflow.python.framework.errors_impl.InvalidArgumentError: TensorArray dtype is float64 but Op is trying to write dtype float32
The code is
import tensorflow as tf
# when the next line is uncommented, we get an error
tf.config.run_functions_eagerly(True)
@tf.function(input_signature=[tf.TensorSpec(shape=None,dtype=tf.float64)])
def TrySine(dev):
mytensor = tf.map_fn(fn=lambda t,dev=dev: tf.math.sin(dev*3.14/180.0), elems=tf.ones(shape=(8,),dtype='float64'))
return mytensor
output = TrySine(dev=5.0)
print(output)
Generally speaking,
tensorflowdoesn't like calculations with differentdtypes. It will typically either throw warnings or errors.Unless you have a solid reason for using
float64, I suggest you stick tofloat32, as is the standard in deep learning.But if you really want to use
float64, you can make sure your input constant is in thisdtype: