Warm up local LLM before live corrections
This commit is contained in:
@@ -21,6 +21,7 @@
|
|||||||
"post_correct_ollama_url": "http://127.0.0.1:11434/api/generate",
|
"post_correct_ollama_url": "http://127.0.0.1:11434/api/generate",
|
||||||
"post_correct_llm_timeout": 8.0,
|
"post_correct_llm_timeout": 8.0,
|
||||||
"post_correct_keep_alive": "30m",
|
"post_correct_keep_alive": "30m",
|
||||||
|
"post_correct_warmup_timeout": 20.0,
|
||||||
"post_correct_min_overlap": 0.45,
|
"post_correct_min_overlap": 0.45,
|
||||||
"post_correct_debug": false,
|
"post_correct_debug": false,
|
||||||
"llm_paragraph": false,
|
"llm_paragraph": false,
|
||||||
|
|||||||
@@ -43,8 +43,34 @@ def run_llm_processor(in_queue, out_queue, args):
|
|||||||
print(f"[LLM] Ollama health check failed ({exc}). Local LLM features may fall back.")
|
print(f"[LLM] Ollama health check failed ({exc}). Local LLM features may fall back.")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def warmup_ollama_model():
|
||||||
|
try:
|
||||||
|
response = requests.post(
|
||||||
|
getattr(args, "post_correct_ollama_url", "http://127.0.0.1:11434/api/generate"),
|
||||||
|
json={
|
||||||
|
"model": args.post_correct_model,
|
||||||
|
"prompt": "Return exactly: ok",
|
||||||
|
"stream": False,
|
||||||
|
"options": {"temperature": 0.0},
|
||||||
|
"keep_alive": getattr(args, "post_correct_keep_alive", "30m"),
|
||||||
|
},
|
||||||
|
timeout=getattr(args, "post_correct_warmup_timeout", 20.0),
|
||||||
|
)
|
||||||
|
response.raise_for_status()
|
||||||
|
body = response.json()
|
||||||
|
if body.get("response", "").strip():
|
||||||
|
total_s = body.get("total_duration", 0) / 1_000_000_000
|
||||||
|
load_s = body.get("load_duration", 0) / 1_000_000_000
|
||||||
|
print(f"[LLM] Ollama warmup OK for {args.post_correct_model} (load={load_s:.2f}s total={total_s:.2f}s).")
|
||||||
|
return True
|
||||||
|
except Exception as exc:
|
||||||
|
print(f"[LLM] Ollama warmup failed for {args.post_correct_model} ({exc}).")
|
||||||
|
return False
|
||||||
|
|
||||||
if not is_openai:
|
if not is_openai:
|
||||||
check_ollama_health()
|
check_ollama_health()
|
||||||
|
if getattr(args, "post_correct_llm", False) or getattr(args, "llm_paragraph", False):
|
||||||
|
warmup_ollama_model()
|
||||||
|
|
||||||
def normalize_english_caption(text):
|
def normalize_english_caption(text):
|
||||||
normalized = " ".join((text or "").split()).strip()
|
normalized = " ".join((text or "").split()).strip()
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ def main():
|
|||||||
parser.add_argument("--post-correct-ollama-url", type=str, default=defaults.get("post_correct_ollama_url", "http://127.0.0.1:11434/api/generate"))
|
parser.add_argument("--post-correct-ollama-url", type=str, default=defaults.get("post_correct_ollama_url", "http://127.0.0.1:11434/api/generate"))
|
||||||
parser.add_argument("--post-correct-llm-timeout", type=float, default=defaults.get("post_correct_llm_timeout", 8.0))
|
parser.add_argument("--post-correct-llm-timeout", type=float, default=defaults.get("post_correct_llm_timeout", 8.0))
|
||||||
parser.add_argument("--post-correct-keep-alive", type=str, default=defaults.get("post_correct_keep_alive", "30m"))
|
parser.add_argument("--post-correct-keep-alive", type=str, default=defaults.get("post_correct_keep_alive", "30m"))
|
||||||
|
parser.add_argument("--post-correct-warmup-timeout", type=float, default=defaults.get("post_correct_warmup_timeout", 20.0))
|
||||||
parser.add_argument("--post-correct-min-overlap", type=float, default=defaults.get("post_correct_min_overlap", 0.45))
|
parser.add_argument("--post-correct-min-overlap", type=float, default=defaults.get("post_correct_min_overlap", 0.45))
|
||||||
parser.add_argument("--post-correct-debug", action="store_true", default=defaults.get("post_correct_debug", False))
|
parser.add_argument("--post-correct-debug", action="store_true", default=defaults.get("post_correct_debug", False))
|
||||||
parser.add_argument("--llm-paragraph", action="store_true", default=defaults.get("llm_paragraph", False))
|
parser.add_argument("--llm-paragraph", action="store_true", default=defaults.get("llm_paragraph", False))
|
||||||
|
|||||||
Reference in New Issue
Block a user