Import error with tf-nightly and tf-keras on CPU

Installed tf-nightly and tf-keras in a new env
python version 3.11.16

import tf_keras
Traceback (most recent call last):
File “”, line 1, in
File “/nfs/site/home/xyzd/tfv2_p311/lib/python3.11/site-packages/tf_keras/init.py”, line 3, in
from tf_keras import internal
File “/nfs/site/home/xyzd/tfv2_p311/lib/python3.11/site-packages/tf_keras/internal/init.py”, line 6, in
from tf_keras.internal import models
File “/nfs/site/home/xyzd/tfv2_p311/lib/python3.11/site-packages/tf_keras/internal/models/init.py”, line 3, in
from tf_keras.src.models.cloning import clone_and_build_model
File “/nfs/site/home/xyzd/tfv2_p311/lib/python3.11/site-packages/tf_keras/src/init.py”, line 21, in
from tf_keras.src import applications
File “/nfs/site/home/xyzd/tfv2_p311/lib/python3.11/site-packages/tf_keras/src/applications/init.py”, line 18, in
from tf_keras.src.applications.convnext import ConvNeXtBase
File “/nfs/site/home/xyzd/tfv2_p311/lib/python3.11/site-packages/tf_keras/src/applications/convnext.py”, line 33, in
from tf_keras.src.engine import sequential
File “/nfs/site/home/xyzd/tfv2_p311/lib/python3.11/site-packages/tf_keras/src/engine/sequential.py”, line 24, in
from tf_keras.src.engine import functional
File “/nfs/site/home/xyzd/tfv2_p311/lib/python3.11/site-packages/tf_keras/src/engine/functional.py”, line 33, in
from tf_keras.src.engine import training as training_lib
File “/nfs/site/home/xyzd/tfv2_p311/lib/python3.11/site-packages/tf_keras/src/engine/training.py”, line 48, in
from tf_keras.src.saving import saving_api
File “/nfs/site/home/xyzd/tfv2_p311/lib/python3.11/site-packages/tf_keras/src/saving/saving_api.py”, line 25, in
from tf_keras.src.saving.legacy import save as legacy_sm_saving_lib
File “/nfs/site/home/xyzd/tfv2_p311/lib/python3.11/site-packages/tf_keras/src/saving/legacy/save.py”, line 27, in
from tf_keras.src.saving.legacy.saved_model import load_context
File “/nfs/site/home/xyzd/tfv2_p311/lib/python3.11/site-packages/tf_keras/src/saving/legacy/saved_model/load_context.py”, line 68, in
tf.internal.register_load_context_function(in_load_context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module ‘tensorflow._api.v2.compat.v2.internal’ has no attribute ‘register_load_context_function’. Did you mean: ‘register_call_context_function’?

Hi @jojivk, Even though you installed tf-keras you can import keras using import keras. If you want to install keras-core you can install it using !pip install keras_core and import it using import keras_core as keras. Thank You.

Hi,

Thanks for reporting the issue.

Since the migration, there were many changes made, the error you are getting is due to one such change here Change only affects internal TF. · keras-team/tf-keras@cff6ac9 · GitHub.

To get rid of the error, you need to install tf-keras-nightly as well as tf-nightly.

Note that, tf-keras-nightly is legacy Keras code, to use the Keras 3 with multi-backend support, use keras-nightly and import Keras directly.