feat: real service test endpoints (proxy 7-route round-trip, core/chat/vlm/markbase/embedding), unified log paths + errorLog, pipeline tools/import/export/folder APIs, face pipeline check, dynamic concurrency tuning
This commit is contained in:
@@ -12,20 +12,28 @@ MODEL = None
|
||||
TOKENIZER = None
|
||||
DEVICE = None
|
||||
|
||||
def load_model(model_path: str = "google/embeddinggemma-300m"):
|
||||
def load_model(model_path: str = ""):
|
||||
global MODEL, TOKENIZER, DEVICE
|
||||
if MODEL is not None:
|
||||
return
|
||||
import os
|
||||
# 一律使用本地模型目錄,絕不上網
|
||||
local = os.path.expanduser("~/momentry/models/embeddinggemma-300m")
|
||||
if not (os.path.isdir(local) and os.path.isfile(os.path.join(local, "config.json"))):
|
||||
raise RuntimeError(
|
||||
f"[EmbeddingGemma] Local model not found at {local}. "
|
||||
"Please copy the model files (config.json, model.safetensors, tokenizer*) to this directory."
|
||||
)
|
||||
DEVICE = "mps" if torch.backends.mps.is_available() else "cpu"
|
||||
dtype = torch.float32
|
||||
print(f"[EmbeddingGemma] Loading model on {DEVICE} (dtype={dtype})...")
|
||||
print(f"[EmbeddingGemma] Loading model from local: {local} on {DEVICE} (dtype={dtype})...")
|
||||
t0 = time.time()
|
||||
MODEL = AutoModel.from_pretrained(
|
||||
model_path,
|
||||
local,
|
||||
torch_dtype=dtype,
|
||||
trust_remote_code=True,
|
||||
).eval().to(DEVICE)
|
||||
TOKENIZER = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
|
||||
TOKENIZER = AutoTokenizer.from_pretrained(local, trust_remote_code=True)
|
||||
print(f"[EmbeddingGemma] Loaded in {time.time()-t0:.1f}s on {DEVICE}")
|
||||
|
||||
def embed(texts: list[str]) -> list[list[float]]:
|
||||
@@ -79,7 +87,6 @@ def health():
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--port", type=int, default=11436)
|
||||
parser.add_argument("--model", type=str, default="google/embeddinggemma-300m")
|
||||
args = parser.parse_args()
|
||||
load_model(args.model)
|
||||
load_model() # 一律使用 ~/momentry/models/embeddinggemma-300m,絕不上網
|
||||
app.run(host="0.0.0.0", port=args.port, threaded=True)
|
||||
|
||||
Reference in New Issue
Block a user