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

BUG: Fix cache status for embedding, rerank and image models on the web UI #1135

Merged
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
20 changes: 13 additions & 7 deletions xinference/model/image/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
from itertools import chain

from .core import (
BUILTIN_IMAGE_MODELS,
IMAGE_MODEL_DESCRIPTIONS,
MODELSCOPE_IMAGE_MODELS,
ImageModelFamilyV1,
generate_image_description,
get_cache_status,
Expand All @@ -29,14 +31,18 @@
_model_spec_modelscope_json = os.path.join(
os.path.dirname(__file__), "model_spec_modelscope.json"
)
BUILTIN_IMAGE_MODELS = dict(
(spec["model_name"], ImageModelFamilyV1(**spec))
for spec in json.load(codecs.open(_model_spec_json, "r", encoding="utf-8"))
BUILTIN_IMAGE_MODELS.update(
dict(
(spec["model_name"], ImageModelFamilyV1(**spec))
for spec in json.load(codecs.open(_model_spec_json, "r", encoding="utf-8"))
)
)
MODELSCOPE_IMAGE_MODELS = dict(
(spec["model_name"], ImageModelFamilyV1(**spec))
for spec in json.load(
codecs.open(_model_spec_modelscope_json, "r", encoding="utf-8")
MODELSCOPE_IMAGE_MODELS.update(
dict(
(spec["model_name"], ImageModelFamilyV1(**spec))
for spec in json.load(
codecs.open(_model_spec_modelscope_json, "r", encoding="utf-8")
)
)
)

Expand Down
18 changes: 17 additions & 1 deletion xinference/model/image/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
logger = logging.getLogger(__name__)

IMAGE_MODEL_DESCRIPTIONS: Dict[str, List[Dict]] = defaultdict(list)
BUILTIN_IMAGE_MODELS: Dict[str, "ImageModelFamilyV1"] = {}
MODELSCOPE_IMAGE_MODELS: Dict[str, "ImageModelFamilyV1"] = {}


def get_image_model_descriptions():
Expand Down Expand Up @@ -151,7 +153,21 @@ def get_cache_status(
) -> bool:
cache_dir = get_cache_dir(model_spec)
meta_path = os.path.join(cache_dir, "__valid_download")
return valid_model_revision(meta_path, model_spec.model_revision)

model_name = model_spec.model_name
if model_name in BUILTIN_IMAGE_MODELS and model_name in MODELSCOPE_IMAGE_MODELS:
hf_spec = BUILTIN_IMAGE_MODELS[model_name]
ms_spec = MODELSCOPE_IMAGE_MODELS[model_name]

return any(
[
valid_model_revision(meta_path, hf_spec.model_revision),
valid_model_revision(meta_path, ms_spec.model_revision),
]
)
else: # Usually for UT
logger.warning(f"Cannot find builtin image model spec: {model_name}")
return valid_model_revision(meta_path, model_spec.model_revision)


def create_image_model_instance(
Expand Down
2 changes: 1 addition & 1 deletion xinference/web/ui/src/scenes/launch_model/embeddingCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ const EmbeddingCard = ({
})
})()}
{(() => {
if (modelData.is_cached) {
if (modelData.cache_status) {
return <Chip label="Cached" variant="outlined" size="small" />
}
})()}
Expand Down
2 changes: 1 addition & 1 deletion xinference/web/ui/src/scenes/launch_model/imageCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ const ImageCard = ({
)
})()}
{(() => {
if (modelData.is_cached) {
if (modelData.cache_status) {
return <Chip label="Cached" variant="outlined" size="small" />
}
})()}
Expand Down
2 changes: 1 addition & 1 deletion xinference/web/ui/src/scenes/launch_model/rerankCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ const RerankCard = ({
})
})()}
{(() => {
if (modelData.is_cached) {
if (modelData.cache_status) {
return <Chip label="Cached" variant="outlined" size="small" />
}
})()}
Expand Down
Loading