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

Tensorflow 2.14 breaks dictionary output from a functional model #18399

Closed
mattdangerw opened this issue Sep 20, 2023 · 8 comments
Closed

Tensorflow 2.14 breaks dictionary output from a functional model #18399

mattdangerw opened this issue Sep 20, 2023 · 8 comments

Comments

@mattdangerw
Copy link
Member

mattdangerw commented Sep 20, 2023

When tf 2.14 releases, we will face a bug with dictionary output from a functional model.

https://colab.research.google.com/gist/mattdangerw/019d1ebcec746d6f7424248911cf16ae/tf-2-14-bug.ipynb

I am not sure this will show up on a colab right away, as it actually depends on the specific version of typing-extensions (this is a pretty obtuse bug). But we will see this in a clean pip environment which picks up the latest typing-extensions.

After the 2.14 release:

  • Clean install keras-core and tensorflow in a pip environment.
  • Attempt to write a functional model with dictionary output.
  • Any compiled functions (e.g. predict, fit), will fail.
@mattdangerw
Copy link
Member Author

Here's a bug about the root cause on the tensorflow side -> tensorflow/tensorflow#60687

Ideally this would just be fixed in tensorflow proper. On our side, we could do two things

@mattdangerw
Copy link
Member Author

Roughly it looks like this is an issue with AutoTrackable tensorflow internals and the wrapt library tf uses for some of the tracking stuff.

@fchollet
Copy link
Member

Thanks for the report. Is this being actively fixed by the TensorFlow team? Seems like a significant issue.

@mattdangerw
Copy link
Member Author

Thanks for the report. Is this being actively fixed by the TensorFlow team? Seems like a significant issue.

No idea, commented on the bug and we can try to follow up more. It actually doesn't pop up with tf.keras, because tf.keras does not attempt to auto track functional tracing in the same way we are currently on keras-core. It only pops up when returning a dict from a tf.function that is a property of tf.Module, so it might not affect that much code.

@fchollet fchollet transferred this issue from keras-team/keras-core Sep 22, 2023
@sachinprasadhs sachinprasadhs self-assigned this Jan 18, 2024
@sachinprasadhs
Copy link
Collaborator

I think we can close this issue since it has no problem with the Keras 3 with the below code.

import keras

batch = keras.ops.ones((2, 1))
inputs = keras.Input(shape=(1,))
outputs = {
    "sum": keras.layers.Add()((inputs, inputs)),
    "diff": keras.layers.Subtract()((inputs, inputs)),
}
model = keras.Model(inputs, outputs)
model.predict(batch)

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants