Skip to content

Commit

Permalink
fix(keras): compatibility with Keras 3.4.0 (#4922)
Browse files Browse the repository at this point in the history
* Fix keras.save_model compatibility with Keras 3

Compatibility was lost with Keras 3. This restore the functionality
when using Keras 3.4.0 or newer.

Fix #4921

* ci: auto fixes from pre-commit.ci

For more information, see https://pre-commit.ci

* Adjust framework dependency version for Keras

* Fix minimal version check

* Add compatibility with older keras 2.x version

* ci: auto fixes from pre-commit.ci

For more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
rmarquis and pre-commit-ci[bot] authored Aug 17, 2024
1 parent c323ef4 commit afc8647
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"jaxlib; platform_system!='Windows'",
"chex; platform_system!='Windows'",
],
"keras": ["keras"],
"keras": ["keras>=3.4"],
"lightgbm": ["lightgbm"],
"onnx": ["onnx", "onnxruntime", "skl2onnx"],
"picklable_model": [],
Expand Down
10 changes: 9 additions & 1 deletion src/bentoml/_internal/frameworks/keras.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,15 @@ def KerasSequentialModel() -> keras.models.Model:
metadata=metadata,
signatures=signatures,
) as bento_model:
model.save(bento_model.path, include_optimizer=include_optimizer, **kwargs)
if keras.__version__ >= "3.4.0":
model.save(
bento_model.path,
zipped=False,
include_optimizer=include_optimizer,
**kwargs,
)
else:
model.save(bento_model.path, include_optimizer=include_optimizer, **kwargs)

return bento_model

Expand Down

0 comments on commit afc8647

Please sign in to comment.