Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does tensorflow < 2.16 depend on keras or tf-keras? #19069

Closed
chenmoneygithub opened this issue Jan 18, 2024 · 12 comments
Closed

Does tensorflow < 2.16 depend on keras or tf-keras? #19069

chenmoneygithub opened this issue Jan 18, 2024 · 12 comments
Assignees
Labels
stale stat:awaiting response from contributor type:support User is asking for help / asking an implementation question. Stackoverflow would be better suited.

Comments

@chenmoneygithub
Copy link
Contributor

Hi team,

I have a question about Keras dependency of installing Tensorflow < 2.16. Basically if I run pip install tensorflow==2.15.0, it's going to install keras==2.15 as a dependency. Then when I upgrade to keras==3.0.2, it throws an error:

tensorflow-macos 2.15.0 requires keras<2.16,>=2.15.0, but you have keras 3.0.2 which is incompatible.

I was assuming older Tensorflow version will port to tf-keras instead of keras, but after I do pip install tf-keras, then from tensorflow import keras, the keras is still the multi-backend Keras. Could you help clarify the dependency? Will old tensorflow point to tf-keras?

For some context, I am trying to add keras 3 support to MLflow: mlflow/mlflow#10830, and the CI is failing because of incompatibility between Tensorflow version and Keras version. Thanks!

Best,
chenmoney

@sachinprasadhs
Copy link
Collaborator

tensorflow 2.15 depends on tf-keras/keras 2.15, but it is compatible with Keras 3 as well.

You can install tensorflow 2.15 first, which installs keras 2.15, you can update the keras package again to upgrade it to latest version, which is 3.0.2.

From tensorflow 2.16, it will install keras 3 by default.

Here is the commit for updating the requirement for tf-nightly(2.16)

@sachinprasadhs sachinprasadhs added type:support User is asking for help / asking an implementation question. Stackoverflow would be better suited. stat:awaiting response from contributor labels Jan 18, 2024
@chenmoneygithub
Copy link
Contributor Author

@sachinprasadhs Thanks!

tensorflow 2.15 depends on tf-keras/keras 2.15

What does it mean? tf-keras is a different package from keras, though they share the same version number. Now TF 2.15 is pointing to Keras instead of tf-keras. For more context, if I have both tf-keras==2.15 and keras==3.0.2 installed on my conda environment, then tensorflow==2.15.0 is using the keras==3.0.2 now. I am wondering if this is the expected behavior?

@sachinprasadhs
Copy link
Collaborator

tensorflow 2.15 by default installs keras 2.15 here https://github.com/keras-team/keras/tree/v2.15.0 and it will point to keras 2 .

If you install Keras 3 and if you also want the keras 2 behavior, then you can install tf-keras 2.15 and set the env variable with TF_USE_LEGACY_KERAS=1

More details on this can be found here https://keras.io/getting_started/#tensorflow--keras-2-backwards-compatibility

@chenmoneygithub
Copy link
Contributor Author

@sachinprasadhs Thanks!

One more question, on keras.io it says:

Should you want tf.keras to stay on Keras 2 after upgrading to TensorFlow 2.16+, you can configure your TensorFlow installation so that tf.keras points to tf_keras. To achieve this:

Does this TF_USE_LEGACY_KERAS environment variable also work for older TF versions like tf 2.15?

@sachinprasadhs
Copy link
Collaborator

Ideally you don't need to use TF_USE_LEGACY_KERAS in 2.15, if you are using keras 2.15.
But, if you have installed keras 3 with tensorflow 2.15, use can use TF_USE_LEGACY_KERAS by installing tf-keras 2.15

@chenmoneygithub
Copy link
Contributor Author

@sachinprasadhs Thanks! One more question - why should there be an error message tensorflow-macos 2.15.0 requires keras<2.16,>=2.15.0, but you have keras 3.0.2 which is incompatible. while Keras 3 works fine with TF 2.15? Keras 3 was developed and tested against TF 2.13 originally.

@sachinprasadhs
Copy link
Collaborator

I guess it is because of all the dependency in the same requirement.txt file.

If that is the case, try installing keras separately else you may find below error.

ERROR: Cannot install KERAS==3.0.2 and tensorflow==2.15.0 because these package versions have conflicting dependencies.

The conflict is caused by:
    The user requested KERAS==3.0.2
    tensorflow 2.15.0 depends on keras<2.16 and >=2.15.0

To fix this you could try to:
1. loosen the range of package versions you've specified
2. remove package versions to allow pip attempt to solve the dependency conflict

ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/topics/dependency-resolution/#dealing-with-dependency-conflicts

Copy link

github-actions bot commented Feb 2, 2024

This issue is stale because it has been open for 14 days with no activity. It will be closed if no further activity occurs. Thank you.

@github-actions github-actions bot added the stale label Feb 2, 2024
Copy link

This issue was closed because it has been inactive for 28 days. Please reopen if you'd like to work on this further.

Copy link

Are you satisfied with the resolution of your issue?
Yes
No

@ShahriarAlom
Copy link

I have tried to ignore keras when installing Object detection and other Api's for version incompatibility and other issues, and after installation, I have seen that tasks include tensorflow and keras both, it doesn't works If keras wasn't installed properly with version control. And you can change keras version any time, where tf.keras will not help you in that case. So most of the installation and code will not work if Keras isn't installed independently.

@ShahriarAlom
Copy link

ShahriarAlom commented Mar 24, 2024

I will suggest to install keras 2.15.0 when you are installing any api or proto, after installation, install the latest any version you need, like 3.1.1 is latest. then older version will be auto replaced.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale stat:awaiting response from contributor type:support User is asking for help / asking an implementation question. Stackoverflow would be better suited.
Projects
None yet
Development

No branches or pull requests

3 participants