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

[BUG] SavedModel serving signature contains all input features even when they aren't used #898

Closed
karlhigley opened this issue Nov 21, 2022 · 1 comment
Assignees
Labels
bug Something isn't working P0 S2
Milestone

Comments

@karlhigley
Copy link
Contributor

Bug description

When I train a model and save it, the resulting saved model file's serving signature contains every feature from the training dataset that was loaded by the dataloader, even when the model doesn't actually use those features.

Steps/Code to reproduce bug

Run the following code:

import tensorflow
import merlin.models.tf as mm
from merlin.datasets.synthetic import generate_data
from merlin.io import Dataset
from merlin.schema import Tags


train = generate_data("sequence-testing", num_rows=100)

seq_schema = train.schema.select_by_tag(Tags.SEQUENCE).select_by_tag(Tags.CATEGORICAL)
target = train.schema.select_by_tag(Tags.ITEM_ID).column_names[0]

predict_last = mm.SequencePredictLast(schema=seq_schema, target=target)

input_schema = seq_schema
output_schema = seq_schema.select_by_name(target)

loader = mm.Loader(train, batch_size=16, shuffle=False)

d_model = 48
query_encoder = mm.Encoder(
    mm.InputBlockV2(
        input_schema,
        embeddings=mm.Embeddings(
            input_schema.select_by_tag(Tags.CATEGORICAL), sequence_combiner=None
        ),
    ),
    mm.MLPBlock([d_model]),
    mm.GPT2Block(d_model=d_model, n_head=2, n_layer=2),
    tf.keras.layers.Lambda(lambda x: tf.reduce_mean(x, axis=1)),
)

model = mm.RetrievalModelV2(
    query=query_encoder,
    output=mm.ContrastiveOutput(output_schema, negative_samplers="in-batch"),
)

model.compile(metrics={})
model.fit(loader, epochs=1, pre=predict_last)

query_encoder.save(
    f"/tmp/query_encoder"
)

Examine the serving signature with:

saved_model_cli show --tag_set serve --signature_def serving_default --dir /tmp/query_encoder

Expected behavior

The serving signature should only contain the features that the model actually uses. (Otherwise, when we try to serve the model, we have to provide a bunch of features that don't do anything.)

Environment details

  • Merlin versions:
    • merlin-core 0.8.0+12.g8612b749e3
    • merlin-dataloader 0.0.2
    • merlin-models 0.9.0+42.g04597b9277
    • merlin-systems 0.7.0+19.g032be4d9
  • Platform: Docker (merlin_ci_runner image)
  • Python version: 3.8.10
  • Tensorflow version (GPU?): tensorflow-gpu 2.9.2

Additional context

This is one of several issues that are currently making it difficult to serve Tensorflow session-based models for NVIDIA-Merlin/Merlin#433.

@rnyak
Copy link
Contributor

rnyak commented Dec 14, 2022

this PR #904 is potentially solving this issue.

@rnyak rnyak closed this as completed Feb 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working P0 S2
Projects
None yet
Development

No branches or pull requests

5 participants