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

Saved Model support: implements Model.saved_model that enables the user to serialize pred_step as a SavedModel #171

Merged
merged 9 commits into from Mar 5, 2021

Conversation

cgarciae
Copy link
Collaborator

@cgarciae cgarciae commented Mar 3, 2021

saved_model gets a sample input and a path, and serializes a pred_step as a SavedModel via jax2tf:

import numpy as np
import elegy
from flax import linen

x = np.random.uniform(size=(32, 6))

model = elegy.Model(module=linen.Dense(4))
model.init(x)

model.saved_model(x, "/saved/model/path", batch_size=[1, 8])

This creates a SavedModel with 2 signatures:

  • input: (1, 6)
  • output: (1, 4)

and

  • input: (8, 6)
  • output: (8, 4)

Due to google/jax#5915 only a finite set of static batch sizes work, if this is resolved in the future one will be able to omit the batch size to que a polymorphic batch dimension:

import numpy as np
import elegy
from flax import linen

x = np.random.uniform(size=(32, 6))

model = elegy.Model(module=linen.Dense(4))
model.init(x)

model.saved_model(x, "/saved/model/path")

This SavedModel would contain the following signature:

  • input: (None, 6)
  • output: (None, 4)

@cgarciae cgarciae changed the title Saved Model support: implements Model.saved_model that enable the user to serialize pred_step as a SavedModel Saved Model support: implements Model.saved_model that enables the user to serialize pred_step as a SavedModel Mar 3, 2021
@codecov-io
Copy link

codecov-io commented Mar 4, 2021

Codecov Report

Merging #171 (fb484cc) into master (7f4a781) will increase coverage by 0.01%.
The diff coverage is 88.88%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #171      +/-   ##
==========================================
+ Coverage   87.21%   87.22%   +0.01%     
==========================================
  Files         135      136       +1     
  Lines        7360     7430      +70     
==========================================
+ Hits         6419     6481      +62     
- Misses        941      949       +8     
Impacted Files Coverage Δ
elegy/model/utils.py 82.14% <82.14%> (ø)
elegy/model/model_core.py 85.46% <86.95%> (+0.23%) ⬆️
elegy/model/model_test.py 100.00% <100.00%> (ø)
elegy/nn/linear.py 97.29% <100.00%> (+0.07%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7f4a781...fb484cc. Read the comment docs.

@cgarciae cgarciae merged commit 2ff78ec into master Mar 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants