Skip to content

Commit 8a482b0

Browse files
committed
Fix: Broken serve cli
1 parent 2422aa0 commit 8a482b0

File tree

6 files changed

+14
-11
lines changed

6 files changed

+14
-11
lines changed

pdm.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "pdm.backend"
44

55
[project]
66
name = "CLIP-API-service"
7-
version = "0.1.2"
7+
version = "0.1.3"
88
authors = [
99
{ name="BentoML Authors", email="contact@bentoml.com" },
1010
]
@@ -35,7 +35,7 @@ dependencies = [
3535
"transformers",
3636
"accelerate",
3737
"optimum",
38-
"pydantic",
38+
"pydantic>=2.0.0",
3939
"Pillow",
4040
"open-clip-torch",
4141
"torch==2.0.0",

src/clip_api_service/__about__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.1.2"
1+
__version__ = "0.1.3"

src/clip_api_service/_service.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
import asyncio
44
import typing
55

6+
import os
7+
8+
69
import bentoml
710
import numpy as np
811
from bentoml.io import JSON
912
from typing import Optional, List
1013

11-
from clip_api_service.models import init_model
14+
from clip_api_service.models import init_model, DEFAULT_MODEL_NAME, MODEL_ENV_VAR_KEY
1215
from clip_api_service.runners import get_clip_runner
1316
from clip_api_service.samples import ENCODING_INPUT_SAMPLE, RANKING_INPUT_SAMPLE
1417
from clip_api_service.utils import (
@@ -43,7 +46,9 @@ class RankOutput(BaseItem):
4346
probabilities: List[List[float]]
4447
cosine_similarities: List[List[float]]
4548

46-
bento_model = init_model("__model_name__")
49+
model_name = os.environ.get(MODEL_ENV_VAR_KEY, "__model_name__")
50+
bento_model = init_model(model_name)
51+
4752
logit_scale = np.exp(bento_model.info.metadata.get("logit_scale", 4.60517))
4853

4954
clip_runner = get_clip_runner(bento_model)

src/clip_api_service/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def serve(model_name: Annotated[str, typer.Option(help="CLIP Model name")] = DEF
1414
env[MODEL_ENV_VAR_KEY] = model_name
1515

1616
try:
17-
subprocess.run(["bentoml", "serve", "clip_api_service.service:svc"], env=env, check=True)
17+
subprocess.run(["bentoml", "serve", "clip_api_service._service:svc"], env=env, check=True)
1818
except subprocess.CalledProcessError as e:
1919
typer.echo(f"Command 'bentoml serve {model_name}' failed with error code {e.returncode}")
2020

src/clip_api_service/models/__init__.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,11 @@ def save_model(
122122
)
123123

124124

125-
def init_model(model_name: str | None = None) -> bentoml.Model:
125+
def init_model(model_name: str = DEFAULT_MODEL_NAME) -> bentoml.Model:
126126
"""
127127
Initialize a CLIP model from BentoML format. The model_name must be specified to
128128
support multiple models in a single BentoML bundle.
129-
"""
130-
if model_name is None:
131-
model_name = os.environ.get(MODEL_ENV_VAR_KEY, DEFAULT_MODEL_NAME)
129+
"""
132130

133131
for clip_module in CLIP_MODULES:
134132
if model_name in clip_module.MODELS:

0 commit comments

Comments
 (0)