bentoml / BentoML

The easiest way to serve AI apps and models - Build Model Inference APIs, Job queues, LLM apps, Multi-model pipelines, and more!
https://bentoml.com
Apache License 2.0
7.14k stars 791 forks source link

Labels are not saved in YataiService repository #1589

Closed chlee1016 closed 3 years ago

chlee1016 commented 3 years ago

Describe the bug

I found a bug that labels are not saved in YataiService after pushing my bento service.

To Reproduce

from sklearn import svm
from sklearn import datasets

# Load training data
iris = datasets.load_iris()
X, y = iris.data, iris.target

# Model Training
clf = svm.SVC(gamma='scale')
clf.fit(X, y)
%%writefile iris_classifier.py
import pandas as pd

from bentoml import env, artifacts, api, BentoService
from bentoml.adapters import DataframeInput
from bentoml.frameworks.sklearn import SklearnModelArtifact

@env(infer_pip_packages=True)
@artifacts([SklearnModelArtifact('model')])
class IrisClassifier(BentoService):
    """
    A minimum prediction service exposing a Scikit-learn model
    """

    @api(input=DataframeInput(), batch=True)
    def predict(self, df: pd.DataFrame):
        """
        An inference API named `predict` with Dataframe input adapter, which codifies
        how HTTP requests or CSV files are converted to a pandas Dataframe object as the
        inference API function input
        """
        return self.artifacts.model.predict(df)
from iris_classifier import IrisClassifier

iris_classifier_service = IrisClassifier()
iris_classifier_service.pack('model', clf)

# Save my bento service with labels
iris_classifier_service.save(labels = {"model_name":"IrisClassifier"})

yatai_service_endpoint = <YOUR_YATAI_SERVICE_ENDPOINT>
bento_bundle_name = f"{iris_classifier_service.name}:{iris_classifier_service.version}"
# See the labels are exist.
!bentoml list

BENTO_SERVICE                         AGE                    APIS                                   ARTIFACTS                    LABELS
IrisClassifier:20210422163910_617F62  1.49 seconds           predict<DataframeInput:DefaultOutput>  model<SklearnModelArtifact>  model_name:IrisClassifier
!bentoml push --yatai-url $yatai_service_endpoint $bento_bundle_name
# After pushing my bento service to YataiService repo, we can see that the labels are not exist. 
!bentoml list --yatai-url $yatai_service_endpoint

BENTO_SERVICE                         AGE                    APIS                                   ARTIFACTS                    LABELS
IrisClassifier:20210422163910_617F62  5.51 seconds           predict<DataframeInput:DefaultOutput>  model<SklearnModelArtifact>

Expected behavior

I should be able to see the labels in the YataiService repository.

Screenshots/Logs

bentoml_labels_bug

Environment:

Additional context

yubozhao commented 3 years ago

@chlee1016 Thank you for reporting, I will look into it. Can you try with the latest BentoML version, 0.12.1 and see?

chlee1016 commented 3 years ago

@yubozhao Okay, I will give it a try and let you know that. Thank you.

chlee1016 commented 3 years ago

Same test with BentoML version 0.12.1

Save my bento service with labels.

!bentoml list

BENTO_SERVICE                         AGE          APIS                                   ARTIFACTS                    LABELS
IrisClassifier:20210423092848_4A13BB  3.8 seconds  predict<DataframeInput:DefaultOutput>  model<SklearnModelArtifact>  model_name:IrisClassifier
!bentoml push --yatai-url $yatai_service_endpoint $bento_bundle_name

After bentoml push, I got the same result.

!bentoml list --yatai-url $yatai_service_endpoint

BENTO_SERVICE                         AGE                      APIS                                   ARTIFACTS                    LABELS
IrisClassifier:20210423092848_4A13BB  10.41 seconds            predict<DataframeInput:DefaultOutput>  model<SklearnModelArtifact>

Screenshot

bentoml_bug_2
yubozhao commented 3 years ago

@chlee1016 I see.

Right now, the python API expose label option, for the use cases that you might have different labels you want to add. This option is not exposed to the CLI. We will match the behavior for them.

I will also add the current labels as default when no new labels are provided.

yubozhao commented 3 years ago

I will keep you updated, hopefully we can get this resolved before next release

chlee1016 commented 3 years ago

@yubozhao Thank you for considering this issue.

As I understand, the labels option in the CLI will be updated in the future and if there are no new labels in the CLI, current labels set via python API will be used as default. Therefore I will be able to see the labels in remote YataiService repo. Am I right?

yubozhao commented 3 years ago

@chlee1016 I made a PR #1598 to address this issue

After some discussion, we think this would be a good solution going forward, love to hear your feedback.

Push now is default to retrain your labels to remote yatai server. You can turn off this behavior in CLI with flag --without-labels, or in python API yatai_client.repository.push('bento:version', with_labels=False)

We are going to introduce a new API for set labels:

API syntax is not finalized

For python API: yatai_client.repository.set_labels('bento', labels={'foo':'abc'}) For CLI: $bentoml labels set bento:version foo=bar,abc=123

yubozhao commented 3 years ago

@chlee1016 It is merged to master now, and will be part of the 0.13.0 release. Feel free to reopen this issue.