NVIDIA-Merlin / models

Merlin Models is a collection of deep learning recommender system model reference implementations
https://nvidia-merlin.github.io/models/main/index.html
Apache License 2.0
261 stars 50 forks source link

[FEA] Save input and output schema when `.save` methods are called on models #669

Open oliverholworthy opened 2 years ago

oliverholworthy commented 2 years ago

Relates to: https://github.com/NVIDIA-Merlin/Merlin/issues/545

šŸš€ Feature request

Provide a consistent .save interface for all models.

This .save method should save the model artifact along with the schema to a directory provided.

Motivation

Model artifacts alone are not enough to unambiguously infer the correct input schema for a model. Saving the input schema along with models will enable serving code in systems to figure out the correct inputs required for models from an artifact without requiring the user to provide the schema at serving time.

Part of: https://github.com/NVIDIA-Merlin/Merlin/issues/489

Proposed interface

Create a runtime check-able protocol that specifies the common methods expected on a model object.

This .save method on a model will write out the model artifact(s) along with the input schema to a directory provided.

Files saved in merlin metadata directory.

Saved model directory structure

e.g. a model.save("my_merln_model") on a tensorflow backend should result in the following directory structure:


my_merlin_model
ā”œā”€ā”€ merlin_metadata
ā”‚Ā Ā  ā”œā”€ā”€ input_schema.json
ā”‚Ā Ā  ā”œā”€ā”€ output_schema.json
ā”‚Ā Ā  ā””ā”€ā”€ model.json
ā”œā”€ā”€ assets
ā”œā”€ā”€ keras_metadata.pb
ā”œā”€ā”€ saved_model.pb
ā””ā”€ā”€ variables
    ā”œā”€ā”€ variables.data-00000-of-00001
    ā””ā”€ā”€ variables.index

Sub-Tasks

EvenOldridge commented 2 years ago

@marcromeyn @oliverholworthy what's the status of this? This is blocking the creation of example notebooks for end to end using systems.

rnyak commented 1 year ago

partially addressed by https://github.com/NVIDIA-Merlin/models/pull/680

oliverholworthy commented 1 year ago

This PR (https://github.com/NVIDIA-Merlin/models/pull/680) handles the first two tasks.

There is a bit more to think about beyond this. Adding output schema for tensorflow models. And figuring out how to enforce that a schema is created. Since the Merlin Models API is flexible enough at the moment that we can't always guarantee that we have a schema available. At least not in a way that provides any more information than the saved model signature is able to (since we could infer the schema from the saved model like we do in Merlin Systems currently).