tensorflow / probability

Probabilistic reasoning and statistical analysis in TensorFlow
https://www.tensorflow.org/probability/
Apache License 2.0
4.23k stars 1.09k forks source link

transformedVariable compatibility with tensorFlow 2.4 and tensorflow_probability 0.12 #1307

Open StanleyYoo opened 3 years ago

StanleyYoo commented 3 years ago

Hi,

I have modified version of 'Gaussian Process Regression in TensorFlow Probability' from 'Guide & Tutorials'. This has been working with tensorFlow 2.3 and tensorflow_probability 0.11. Once upgraded to tensorFlow to 2.4 and tensorflow_probability 0.12, there are an issue with transformedVariable used for 'amplitude', 'lengthscale' and 'obsevation_variance' at the site-packages\tensorflow\python\eager\function.py with the function '_convert_numpy_inputs'. Since previously it doesn't force the transformedVariable to be numpy.ndarray but it does now. Hence it raises an error as below:

'_The output of array must be an np.ndarray (got <class 'tensorflow.python.framework.ops.EagerTensor'> from <class 'tensorflow_probability.python.util.deferredtensor.TransformedVariable'>).' How could this be fixed?

davmre commented 3 years ago

I believe this is the same issue as https://github.com/tensorflow/tensorflow/issues/47445. As far as I know, there's not yet a consensus around how to address the underlying issue, but it should be possible to work around in most cases by defining a wrapper tf.function that doesn't take the TransformedVariable as an argument (see the example in the linked issue).