Skip to content

Commit

Permalink
skip unchanged bentos
Browse files Browse the repository at this point in the history
  • Loading branch information
bojiang committed Jul 13, 2024
1 parent ba15cd0 commit 7509a6d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
2 changes: 0 additions & 2 deletions source/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@ BENTOML_HOME := $(PWD)/../bentoml

.PHONY: all
all:
@rm -rf $(BENTOML_HOME)
@mkdir -p $(BENTOML_HOME)
@BENTOML_HOME=$(BENTOML_HOME) python make.py
2 changes: 1 addition & 1 deletion source/llamacpp-chat/bentofile.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
service: "service:LlamaCppChat"
labels:
source: https://github.com/bentoml/openllm-models-feed/tree/main/source/llamacpp-chat
platforms: macos
platforms: macos,linux
include:
- "*.py"
- "ui/*"
Expand Down
32 changes: 31 additions & 1 deletion source/make.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,15 @@ def hash_directory(directory_path):
else:
specified_model = None

built_bentos = set()

for model_name, config in RECIPE.items():
if specified_model and model_name != specified_model:
continue

project = config["project"]
model_repo, model_version = model_name.split(":")

with tempfile.TemporaryDirectory() as tempdir:
tempdir = pathlib.Path(tempdir)
shutil.copytree(project, tempdir, dirs_exist_ok=True)
Expand All @@ -73,8 +77,25 @@ def hash_directory(directory_path):
directory_hash = hash_directory(tempdir)
model_version = f"{model_version}-{directory_hash[:4]}"

bento_path = BENTOML_HOME / "bentos" / model_repo / model_version
built_bentos.add((model_repo, model_version))

if bento_path.exists():
print(
f"Model {model_name} with version {model_version} already exists, skipping"
)
continue

subprocess.run(
[sys.executable, "-m", "bentoml", "build", str(tempdir), "--version", model_version],
[
sys.executable,
"-m",
"bentoml",
"build",
str(tempdir),
"--version",
model_version,
],
check=True,
cwd=tempdir,
env=os.environ,
Expand All @@ -96,3 +117,12 @@ def hash_directory(directory_path):
BENTOML_HOME / "bentos" / model_repo / model_version,
BENTOML_HOME / "bentos" / model_repo / alias,
)

for bento_path in BENTOML_HOME.glob("bentos/*/*"):
if (
bento_path.exists()
and bento_path.is_dir()
and (bento_path.parent.name, bento_path.name) not in built_bentos
):
print(f"Deleting unused bento {bento_path}")
shutil.rmtree(bento_path)

0 comments on commit 7509a6d

Please sign in to comment.