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

fix: correct the bento size to include the size of models #4226

Merged
merged 2 commits into from
Oct 12, 2023
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
23 changes: 17 additions & 6 deletions src/bentoml/_internal/bento/bento.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

from ...exceptions import BentoMLException
from ...exceptions import InvalidArgument
from ...exceptions import NotFound
from ..configuration import BENTOML_VERSION
from ..configuration.containers import BentoMLContainer
from ..models import ModelStore
Expand Down Expand Up @@ -352,12 +353,22 @@ def export(
finally:
self._fs.removetree("models")

@property
def path(self) -> str:
return self.path_of("/")

def path_of(self, item: str) -> str:
return self._fs.getsyspath(item)
@inject
def total_size(
self, model_store: ModelStore = Provide[BentoMLContainer.model_store]
) -> int:
total_size = self.file_size
local_model_store = self._model_store
for model in self.info.models:
if local_model_store is not None:
try:
local_model_store.get(model.tag)
continue
except NotFound:
pass
global_model = model_store.get(model.tag)
total_size += global_model.file_size
return total_size

def flush_info(self):
with self._fs.open(BENTO_YAML_FILENAME, "w") as bento_yaml:
Expand Down
2 changes: 1 addition & 1 deletion src/bentoml/_internal/cloud/bentocloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def push_model(model: Model) -> None:
apis=apis,
models=models,
runners=runners,
size_bytes=calc_dir_size(bento.path),
size_bytes=bento.total_size(),
)
if not remote_bento:
with self.spin(
Expand Down
2 changes: 1 addition & 1 deletion src/bentoml/_internal/cloud/yatai.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def push_model(model: Model) -> None:
apis=apis,
models=models,
runners=runners,
size_bytes=calc_dir_size(bento.path),
size_bytes=bento.total_size(),
)
if not remote_bento:
with self.spin(text=f'Registering Bento "{bento.tag}" with Yatai..'):
Expand Down
7 changes: 0 additions & 7 deletions src/bentoml/_internal/models/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,6 @@ def from_fs(cls: t.Type[Model], item_fs: FS) -> Model:

return res

@property
def path(self) -> str:
return self.path_of("/")

def path_of(self, item: str) -> str:
return self._fs.getsyspath(item)

@classmethod
def enter_cloudpickle_context(
cls,
Expand Down
12 changes: 12 additions & 0 deletions src/bentoml/_internal/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from .exportable import Exportable
from .tag import Tag
from .types import PathType
from .utils import calc_dir_size

T = t.TypeVar("T")

Expand Down Expand Up @@ -43,6 +44,17 @@ def _export_name(self) -> str:
def creation_time(self) -> datetime.datetime:
raise NotImplementedError

@property
def path(self) -> str:
return self.path_of("/")

def path_of(self, item: str) -> str:
return self._fs.getsyspath(item)

@property
def file_size(self) -> int:
return calc_dir_size(self.path)

def __repr__(self):
return f'{self.get_typename()}(tag="{self.tag}")'

Expand Down
27 changes: 15 additions & 12 deletions src/bentoml_cli/bentos.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ def add_bento_management_commands(cli: Group):
from bentoml._internal.bento.build_config import BentoBuildConfig
from bentoml._internal.configuration import get_quiet_mode
from bentoml._internal.configuration.containers import BentoMLContainer
from bentoml._internal.utils import calc_dir_size
from bentoml._internal.utils import human_readable_size
from bentoml._internal.utils import resolve_user_filepath
from bentoml._internal.utils import rich_console as console
Expand Down Expand Up @@ -121,18 +120,20 @@ def list_bentos(bento_name: str, output: str) -> None: # type: ignore (not acce
$ bentoml list FraudDetector
"""
bentos = bento_store.list(bento_name)
res = [
{
"tag": str(bento.tag),
"size": human_readable_size(calc_dir_size(bento.path)),
"creation_time": bento.info.creation_time.astimezone().strftime(
"%Y-%m-%d %H:%M:%S"
),
}
for bento in sorted(
bentos, key=lambda x: x.info.creation_time, reverse=True
res: list[dict[str, str]] = []
for bento in sorted(bentos, key=lambda x: x.info.creation_time, reverse=True):
bento_size = bento.file_size
model_size = bento.total_size() - bento_size
res.append(
{
"tag": str(bento.tag),
"size": human_readable_size(bento_size),
"model_size": human_readable_size(model_size),
"creation_time": bento.info.creation_time.astimezone().strftime(
"%Y-%m-%d %H:%M:%S"
),
}
)
]

if output == "json":
info = json.dumps(res, indent=2)
Expand All @@ -144,11 +145,13 @@ def list_bentos(bento_name: str, output: str) -> None: # type: ignore (not acce
table = Table(box=None)
table.add_column("Tag")
table.add_column("Size")
table.add_column("Model Size")
table.add_column("Creation Time")
for bento in res:
table.add_row(
bento["tag"],
bento["size"],
bento["model_size"],
bento["creation_time"],
)
console.print(table)
Expand Down
Loading