Skip to content

Commit

Permalink
fix:correct context path when serving from bento (#5210)
Browse files Browse the repository at this point in the history
* fix: re-export bentoml.bentos

Signed-off-by: Frost Ming <[email protected]>

* fix: add bentoml if not lock_packages

Signed-off-by: Frost Ming <[email protected]>

* fix: chdir

Signed-off-by: Frost Ming <[email protected]>
  • Loading branch information
frostming authored Feb 13, 2025
1 parent 30c70d1 commit e0870e0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
23 changes: 9 additions & 14 deletions src/_bentoml_impl/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,26 +141,21 @@ def import_service(
# a project under current directory
extra_python_path = None

# patch model store if needed
if (
bento_path.with_name(BENTO_YAML_FILENAME).exists()
and bento_path.with_name("models").exists()
):
original_model_store = None
original_path = None
if bento_path.with_name(BENTO_YAML_FILENAME).exists():
from bentoml._internal.models import ModelStore

original_path = os.getcwd()
original_model_store = BentoMLContainer.model_store.get()
# cwd into this for relative path to work
os.chdir(bento_path.absolute())

# check in bento source

BentoMLContainer.model_store.set(
ModelStore((bento_path.with_name("models").absolute()))
)
else:
original_path = None
original_model_store = None
# patch model store if needed
if bento_path.with_name("models").exists():
original_model_store = BentoMLContainer.model_store.get()
BentoMLContainer.model_store.set(
ModelStore((bento_path.with_name("models").absolute()))
)

# load model aliases
bento: Bento | None = None
Expand Down
7 changes: 3 additions & 4 deletions src/_bentoml_sdk/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,7 @@ def run_script(self, script: str) -> t.Self:

def freeze(self, platform_: str | None = None) -> ImageInfo:
"""Freeze the image to an ImageInfo object for build."""
if not self.lock_python_packages:
python_requirements = self.python_requirements
else:
python_requirements = self._freeze_python_requirements(platform_)
python_requirements = self._freeze_python_requirements(platform_)
return ImageInfo(
base_image=self.base_image,
python_version=self.python_version,
Expand Down Expand Up @@ -136,6 +133,8 @@ def _freeze_python_requirements(self, platform_: str | None = None) -> str:
if not has_bentoml_req:
req = get_bentoml_requirement() or get_local_bentoml_dependency()
f.write(f"{req}\n")
if not self.lock_python_packages:
return requirements_in.read_text()
lock_args = [
str(requirements_in),
"--allow-unsafe",
Expand Down
5 changes: 5 additions & 0 deletions src/bentoml/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
from _bentoml_impl.frameworks import sklearn
from _bentoml_impl.frameworks import xgboost

from . import bentos

# BentoML built-in types
from ._internal.bento import Bento
from ._internal.cloud import BentoCloudClient
Expand Down Expand Up @@ -171,6 +173,8 @@

FrameworkImporter.install()

bentos = _LazyLoader("bentoml.bentos", globals(), "bentoml.bentos")

# ML Frameworks
catboost = _LazyLoader(
"bentoml.catboost", globals(), "_bentoml_impl.frameworks.catboost"
Expand Down Expand Up @@ -309,6 +313,7 @@ def __getattr__(name: str) -> Any:
"Context",
"Cookie",
"Service",
"bentos",
"models",
"batch",
"metrics",
Expand Down

0 comments on commit e0870e0

Please sign in to comment.