This commit is contained in:
parent
9e0c85b93a
commit
61962c074b
13
app/main.py
13
app/main.py
|
|
@ -179,16 +179,19 @@ tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH)
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
logger.info("Using SAFE_MIN_FREE_MB = %d MB", SAFE_MIN_FREE_MB)
|
logger.info("Using SAFE_MIN_FREE_MB = %d MB", SAFE_MIN_FREE_MB)
|
||||||
|
|
||||||
# ② -------- FastAPI 启动预热 --------
|
|
||||||
@app.on_event("startup")
|
def _warm_worker(t, q):
|
||||||
def warm_up():
|
|
||||||
def _warm_worker(t, q):
|
|
||||||
try:
|
try:
|
||||||
_ = model.encode(t, return_dense=True, num_processes=1)
|
_ = model.encode(t, return_dense=True, num_processes=1)
|
||||||
q.put("ok")
|
q.put("ok")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
q.put(str(e))
|
q.put(str(e))
|
||||||
|
|
||||||
|
# ② -------- FastAPI 启动预热 --------
|
||||||
|
@app.on_event("startup")
|
||||||
|
def warm_up():
|
||||||
|
logger.info("Warm-up on %s", DEVICE)
|
||||||
|
try:
|
||||||
texts = ["warmup"]
|
texts = ["warmup"]
|
||||||
q = mp.Queue()
|
q = mp.Queue()
|
||||||
p = mp.Process(target=_warm_worker, args=(texts, q))
|
p = mp.Process(target=_warm_worker, args=(texts, q))
|
||||||
|
|
@ -199,6 +202,8 @@ def warm_up():
|
||||||
logger.info("Warm-up complete.")
|
logger.info("Warm-up complete.")
|
||||||
else:
|
else:
|
||||||
logger.warning("Warm-up failed or timed out.")
|
logger.warning("Warm-up failed or timed out.")
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning("Warm-up exception: %s", e)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue