Open WillianFuks opened 8 months ago
Does the error go away if you add:
import tf_keras
and replace tf.optimizers
with tf_keras.optimizers
?
In TF 2.16+, tf.optimizers
refers to the Keras 3 version of the optimizer, which introduced this breaking change. But tf_keras.optimizers
should give you the Keras 2 version of the optimizer (which is what tf.optimizers
did in TF 2.15 and earlier).
I had the same problem and replacing tf.optimizers with tf_keras.optimizers solved the problem. Will there be a fix here?
Does the error go away if you add:
import tf_keras
and replace
tf.optimizers
withtf_keras.optimizers
?In TF 2.16+,
tf.optimizers
refers to the Keras 3 version of the optimizer, which introduced this breaking change. Buttf_keras.optimizers
should give you the Keras 2 version of the optimizer (which is whattf.optimizers
did in TF 2.15 and earlier).
From the TFP 0.24.0 release notes -- https://github.com/tensorflow/probability/releases/tag/v0.24.0 :
NOTE: In TensorFlow 2.16+,
tf.keras
(andtf.initializers
,tf.losses
, andtf.optimizers
) refers to Keras 3. TensorFlow Probability is not compatible with Keras 3 -- instead TFP is continuing to use Keras 2, which is now packaged astf-keras
andtf-keras-nightly
and is imported astf_keras
.
We do not plan to update TensorFlow Probability to be compatible with Keras 3.
When TensorFlow moved from Keras 2 to Keras 3, it looks like it introduced some breaking changes in tf.optimizers
, as well as tf.keras
(and potentially tf.initializers
and tf.losses
). To avoid these changes and stay on Keras 2, users must switch from usingtf.optimizers
to tf_keras.optimizers
(and similarly for tf.initializers
and tf.losses
).
Given this brief code:
Its execution raises:
Apparently the integration with Keras raised conflicts on the naming patterns used in tfp.
Versions used:
tensorflow==2.16.1
tensorflow-probability[tf]==0.24.0
tf-keras==2.16.0