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

refactor(bento): add entry_service to bento info #4417

Merged
merged 2 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions examples/quickstart/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
from bentoml.validators import Shape


@bentoml.service(resources={"cpu": "200m", "memory": "512Mi"})
@bentoml.service(name="preprocessing", resources={"cpu": "200m", "memory": "512Mi"})
class Preprocessing:
@bentoml.api
def preprocess(self, input_series: np.ndarray) -> np.ndarray:
return input_series


@bentoml.service(name="iris_classifier", resources={"cpu": "200m", "memory": "512Mi"})
@bentoml.service(resources={"cpu": "200m", "memory": "512Mi"})
class IrisClassifier:
iris_model = bentoml.models.get("iris_sklearn:latest")
preprocessing = bentoml.depends(Preprocessing)
Expand Down
4 changes: 1 addition & 3 deletions src/_bentoml_sdk/service/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from bentoml._internal.configuration.containers import BentoMLContainer
from bentoml._internal.context import ServiceContext
from bentoml._internal.models import Model
from bentoml._internal.tag import validate_tag_str
from bentoml._internal.utils import dict_filter_none
from bentoml.exceptions import BentoMLException

Expand Down Expand Up @@ -159,8 +158,7 @@ def schema(self) -> dict[str, t.Any]:

@property
def name(self) -> str:
name = self.config.get("name") or self.inner.__name__.lower()
validate_tag_str(name)
name = self.config.get("name") or self.inner.__name__
return name

@property
Expand Down
17 changes: 16 additions & 1 deletion src/bentoml/_internal/bento/bento.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from ..store import Store
from ..store import StoreItem
from ..tag import Tag
from ..tag import to_snake_case
from ..types import PathType
from ..utils import bentoml_cattr
from ..utils import copy_file_to_fs_folder
Expand Down Expand Up @@ -204,7 +205,18 @@ def create(
# Apply default build options
build_config = build_config.with_defaults()

bento_name = build_config.name if build_config.name is not None else svc.name
if isinstance(svc, Service):
# for < 1.2
bento_name = (
build_config.name if build_config.name is not None else svc.name
)
else:
# for >= 1.2
bento_name = (
build_config.name
if build_config.name is not None
else to_snake_case(svc.name)
)
tag = Tag(bento_name, version)
if version is None:
tag = tag.make_new_version()
Expand Down Expand Up @@ -293,6 +305,7 @@ def create(
BentoInfo(
tag=tag,
service=svc, # type: ignore # attrs converters do not typecheck
entry_service=svc.name,
labels=build_config.labels,
models=[
BentoModelInfo.from_bento_model(
Expand Down Expand Up @@ -581,7 +594,9 @@ class BentoInfo:
models: t.List[BentoModelInfo] = attr.field(factory=list)
runners: t.List[BentoRunnerInfo] = attr.field(factory=list)
# for BentoML 1.2+ SDK
entry_service: str = attr.field(factory=str)
services: t.List[BentoServiceInfo] = attr.field(factory=list)

apis: t.List[BentoApiInfo] = attr.field(factory=list)
docker: DockerOptions = attr.field(factory=lambda: DockerOptions().with_defaults())
python: PythonOptions = attr.field(factory=lambda: PythonOptions().with_defaults())
Expand Down
1 change: 1 addition & 0 deletions src/bentoml/_internal/cloud/bentocloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ def push_model(model: Model) -> None:
]
manifest = BentoManifestSchema(
name=info.name,
entry_service=info.entry_service,
service=info.service,
bentoml_version=info.bentoml_version,
apis=apis,
Expand Down
1 change: 1 addition & 0 deletions src/bentoml/_internal/cloud/schemas/modelschemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class BentoRunnerSchema:
@attr.define
class BentoManifestSchema:
service: str
entry_service: str
bentoml_version: str
size_bytes: int
name: t.Optional[str] = attr.field(default=None)
Expand Down
1 change: 1 addition & 0 deletions src/bentoml/_internal/cloud/yatai.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ def push_model(model: Model) -> None:
]
manifest = BentoManifestSchema(
name=info.name,
entry_service=info.entry_service,
service=info.service,
bentoml_version=info.bentoml_version,
apis=apis,
Expand Down
5 changes: 5 additions & 0 deletions src/bentoml/_internal/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
tag_regex = re.compile(f"^{tag_fmt}$")


def to_snake_case(name: str) -> str:
snake_case = re.sub(r"(?<!^)(?=[A-Z])", "_", name).lower()
return snake_case


def validate_tag_str(value: str):
"""
Validate that a tag value (either name or version) is a simple string that:
Expand Down
1 change: 1 addition & 0 deletions tests/unit/_internal/bento/test_bento.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def test_bento_info(tmpdir: Path):
- runner_a_model
resource_config:
cpu: 2
entry_service: ''
services: []
apis:
- name: predict
Expand Down
1 change: 1 addition & 0 deletions tests/unit/_internal/cloud/test_deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def dummy_generate_deployment_schema(
presigned_download_url="",
manifest=BentoManifestSchema(
service="",
entry_service="",
bentoml_version="",
size_bytes=0,
apis={},
Expand Down