feat: reserve queue capacity for recent models
This commit is contained in:
@@ -3,6 +3,7 @@ from __future__ import annotations
|
||||
import os
|
||||
import threading
|
||||
import time
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import PurePosixPath
|
||||
from typing import Any
|
||||
from urllib.parse import quote
|
||||
@@ -71,6 +72,8 @@ class HuggingFaceDiscovery:
|
||||
self._repo_tree_lock = threading.Lock()
|
||||
self._model_config_cache: dict[str, tuple[dict[str, Any], str | None]] = {}
|
||||
self._model_config_lock = threading.Lock()
|
||||
self._model_last_modified_cache: dict[str, datetime | None] = {}
|
||||
self._model_last_modified_lock = threading.Lock()
|
||||
self._model_page_cache: dict[tuple[str, int, int], tuple[float, list[dict[str, Any]]]] = {}
|
||||
self._model_page_cache_ttl = max(
|
||||
0.0,
|
||||
@@ -237,6 +240,47 @@ class HuggingFaceDiscovery:
|
||||
self._model_config_cache[repo_id] = result
|
||||
return dict(result[0]), result[1]
|
||||
|
||||
def get_model_last_modified(self, repo_id: str) -> datetime | None:
|
||||
with self._model_last_modified_lock:
|
||||
if repo_id in self._model_last_modified_cache:
|
||||
return self._model_last_modified_cache[repo_id]
|
||||
|
||||
encoded_repo_id = "/".join(quote(part, safe="") for part in repo_id.split("/"))
|
||||
try:
|
||||
payload = self.legacy_http_client.request_json(
|
||||
"GET",
|
||||
f"/api/v1/models/{encoded_repo_id}",
|
||||
)
|
||||
except HttpJsonError as exc:
|
||||
print(f"[modelscope] model_metadata_error repo={repo_id} error={exc}", flush=True)
|
||||
payload = None
|
||||
|
||||
data = payload.get("Data") if isinstance(payload, dict) else None
|
||||
if not isinstance(data, dict) and isinstance(payload, dict):
|
||||
data = payload.get("data")
|
||||
result: datetime | None = None
|
||||
if isinstance(data, dict):
|
||||
raw_value = (
|
||||
data.get("LastUpdatedTime")
|
||||
or data.get("lastUpdatedTime")
|
||||
or data.get("last_modified")
|
||||
or data.get("updated_at")
|
||||
)
|
||||
if isinstance(raw_value, (int, float)):
|
||||
timestamp = float(raw_value)
|
||||
if timestamp > 10_000_000_000:
|
||||
timestamp /= 1000.0
|
||||
try:
|
||||
result = datetime.fromtimestamp(timestamp, tz=timezone.utc)
|
||||
except (OverflowError, OSError, ValueError):
|
||||
result = None
|
||||
else:
|
||||
result = parse_datetime(raw_value)
|
||||
|
||||
with self._model_last_modified_lock:
|
||||
self._model_last_modified_cache[repo_id] = result
|
||||
return result
|
||||
|
||||
def list_repo_tree(self, repo_id: str) -> list[dict[str, Any]]:
|
||||
with self._repo_tree_lock:
|
||||
cached = self._repo_tree_cache.get(repo_id)
|
||||
|
||||
Reference in New Issue
Block a user