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

ValueErrors when calling Model.export() for TF SavedModel format on Keras Models with dict inputs #20835

Open
RyanMullins opened this issue Jan 31, 2025 · 1 comment
Assignees
Labels
Gemma Gemma model specific issues keras-team-review-pending Pending review by a Keras team member.

Comments

@RyanMullins
Copy link

Problem

The Model.export() API in Keras 3 supports exporting to a TensorFlow SavedModel artifact for inference. When trying to export Gemma 2 and ShieldGemma to TF SavedModel, I ran into two different ValueErrors:

  • If no input_signature is provided, a ValueError will be thrown related to a structural mismatch between the expected and actual inputs passed to the GemmaCausalLM class; and
  • If an input_signature is provided as a list[keras.InputSpec], a ValueError will be thrown related the the wrong number of values being passed to a TF function.

However, if yo uwrap the dict from model.input in a list, as input_signature=[model.input], the export runs to completion.

This is not restricted to Gemma models, as shown in this minimal reproducible example.

Thanks to @mattdangerw for helping to isolate this minimal example.

@github-actions github-actions bot added the Gemma Gemma model specific issues label Jan 31, 2025
@mattdangerw mattdangerw added the keras-team-review-pending Pending review by a Keras team member. label Jan 31, 2025
@mattdangerw
Copy link
Member

When this is fixed the follow should work (and would make a good unit test on the tf backend).

inputs = {
    "foo": keras.Input(shape=()),
    "bar": keras.Input(shape=()),
}
outputs = keras.layers.Add()([inputs["foo"], inputs["bar"]])
model = keras.Model(inputs, outputs)
model.export("test/", format="tf_saved_model")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Gemma Gemma model specific issues keras-team-review-pending Pending review by a Keras team member.
Projects
None yet
Development

No branches or pull requests

3 participants