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

Add Export for TF backend #692

Merged
merged 35 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
88e9b30
Add saved model test
nkovela1 Jul 17, 2023
dfd404f
Merge remote-tracking branch 'refs/remotes/origin/main'
nkovela1 Jul 17, 2023
19b0e39
Add TF tracking attribute
nkovela1 Jul 17, 2023
0be8fcc
Add tests for functional and subclassed
nkovela1 Jul 17, 2023
8908273
Fix saving trackables
nkovela1 Jul 18, 2023
0418c60
Fix test assertions
nkovela1 Jul 18, 2023
82c3af1
Fix formatting
nkovela1 Jul 18, 2023
6c8731d
Add comments for attribute tracking
nkovela1 Jul 18, 2023
ac35c30
Merge branch 'keras-team:main' into main
nkovela1 Jul 18, 2023
d341600
Merge remote-tracking branch 'refs/remotes/origin/main'
nkovela1 Jul 18, 2023
8c1d954
Change saved model test description
nkovela1 Jul 18, 2023
9751d02
Add backend conditional for attribute
nkovela1 Jul 18, 2023
c1391cb
Change package name
nkovela1 Jul 18, 2023
1e7df16
Change epoch nums
nkovela1 Jul 18, 2023
51410fe
Revert epochs
nkovela1 Jul 18, 2023
1f11c1a
Add set verbose logging utility and debug callback tests
nkovela1 Jul 18, 2023
e93a4a6
Fix formatting
nkovela1 Jul 18, 2023
99301e1
Sync with main repo
nkovela1 Jul 26, 2023
a6eda55
Merge remote-tracking branch 'refs/remotes/origin/main'
nkovela1 Aug 7, 2023
2902b72
Merge remote-tracking branch 'refs/remotes/origin/main'
nkovela1 Aug 7, 2023
49b74b8
Merge remote-tracking branch 'refs/remotes/origin/main'
nkovela1 Aug 9, 2023
1f446c0
Initial port of model export
nkovela1 Aug 9, 2023
adbc885
Fix imports
nkovela1 Aug 9, 2023
ede9bd7
Add save spec methods to TF layer
nkovela1 Aug 9, 2023
d4f2b1a
Add export function to Keras Core base model
nkovela1 Aug 9, 2023
766b9f6
Downgrade naming error to warning and debug TF variable collections c…
nkovela1 Aug 9, 2023
b6990f8
Simplify weight reloading
nkovela1 Aug 10, 2023
316fdc7
Fix formatting, add TODOs
nkovela1 Aug 10, 2023
02df6af
Unify tf_utils under backend/tensorflow
nkovela1 Aug 10, 2023
8f3f3c9
Fix docstring and import
nkovela1 Aug 10, 2023
82bf3a3
Fix module utils import
nkovela1 Aug 10, 2023
9fdb0dc
Fix lookup layers export and add test
nkovela1 Aug 10, 2023
796b466
Change naming to TFSMLayer
nkovela1 Aug 10, 2023
db80dc9
Remove parameterized
nkovela1 Aug 11, 2023
4861175
Comment out failing test
nkovela1 Aug 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix docstring and import
  • Loading branch information
nkovela1 committed Aug 10, 2023
commit 8f3f3c94e649a7346ea9bd138cfaf874eda9ad28
1 change: 1 addition & 0 deletions keras_core/backend/tensorflow/tf_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def encode_categorical_inputs(
else:
return tf.multiply(bincounts, idf_weights)


def get_tensor_spec(t, dynamic_batch=False, name=None):
"""Returns a `TensorSpec` given a single `Tensor` or `TensorSpec`."""
if isinstance(t, tf.TypeSpec):
Expand Down
3 changes: 1 addition & 2 deletions keras_core/export/export_lib.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
"""Library for exporting inference-only Keras models/layers."""

import tensorflow as tf

from keras_core import backend
from keras_core.api_export import keras_core_export
from keras_core.layers import Layer
from keras_core.models import Functional
from keras_core.models import Sequential
from keras_core.module_utils import tensorflow as tf
from keras_core.utils import io_utils


Expand Down
2 changes: 1 addition & 1 deletion keras_core/layers/preprocessing/hashing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from keras_core import backend
from keras_core.api_export import keras_core_export
from keras_core.backend.tensorflow import tf_utils
from keras_core.layers.layer import Layer
from keras_core.utils import backend_utils
from keras_core.backend.tensorflow import tf_utils
from keras_core.utils.module_utils import tensorflow as tf


Expand Down
5 changes: 4 additions & 1 deletion keras_core/models/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,10 @@ def to_json(self, **kwargs):
return json.dumps(model_config, **kwargs)

def export(self, filepath, format="tf_saved_model"):
"""Create a SavedModel artifact for inference (e.g. via TF-Serving).
"""[TF backend only]* Create a TF SavedModel artifact for inference
(e.g. via TF-Serving).

*Note: This can currently only be used with the TF backend.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

**Note:**

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed


This method lets you export a model to a lightweight SavedModel artifact
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should first mention that it only works with the TF backend.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, thanks

that contains the model's forward pass only (its `call()` method)
Expand Down