Hardware-aware install, per-step LLM profiles, tuned llama.cpp for 4 GB VRAM
Benchmarked on RTX 500 Ada 4 GB (~3.2 GB usable on Windows) + Core Ultra 7 155H.
- install.js: log GPU/VRAM/RAM, abort without NVIDIA >= 4 GB VRAM; always
install Qwen3.5-4B Q4_K_S, Qwen3.6-35B-A3B only with >= 48 GB RAM.
- llama.py: model registry with vision (shots) and text (report/ask)
profiles; KV q8, image tokens 1024-1536.
- 35B: vision encoder on GPU, -ngl 30 (shot 142 -> ~50 s); text: -ub 2048.
- 4B: vision encoder on GPU, FFN of layers 19-31 in RAM (shot 36 -> 22 s);
text fully on GPU (~30 tok/s, report 4.5 min).
- Per-step choice in out/llm.txt: default 4B for shots, biggest for report.
- flow.py: restart llama in text profile after shots (no mmproj for report).
- shots.py: prompt v3 (inline template + defined fields, Italian summary
rules) and bounded json_schema; stops 4B loops, title 1/38 -> 36/38.
- server.py: shots/report model selects, POST /cancel + stop button, reaper
thread that honours Prefect "Cancel" and closes runs whose process died.
- diarize.py: cut same-speaker paragraphs every 60 s (one 11-min paragraph
truncated every report at 28:52); 8 threads; CUDA provider with CPU
fallback via sherpa-onnx cuda12.cudnn9 wheel (CUDA path not yet verified).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
4ff3e6fe14
commit
a64d3fb275
+40
-7
@@ -1,13 +1,45 @@
|
||||
import subprocess, time, urllib.request
|
||||
from pathlib import Path
|
||||
|
||||
SERVER = Path(__file__).parent / "bin" / "llama-server.exe"
|
||||
MD = Path(__file__).parent / "models"
|
||||
MODEL, MMPROJ = MD / "Qwen3.6-35B-A3B-UD-Q4_K_XL.gguf", MD / "mmproj-BF16.gguf"
|
||||
HERE = Path(__file__).parent
|
||||
SERVER = HERE / "bin" / "llama-server.exe"
|
||||
MD = HERE / "models"
|
||||
CHOICE = HERE / "out" / "llm.txt" # GUI header: "<shots model> <report model>"
|
||||
# Benchmarked on RTX 500 Ada 4 GB (Windows leaves ~3.2 GB free) + Core Ultra 7 155H, 2026-11-02.
|
||||
_Q = ["-ctk", "q8_0", "-ctv", "q8_0", "-fa", "on", "-np", "1"] # KV q8: no measurable loss; V q4 made the 4B loop
|
||||
_IMG = ["--image-min-tokens", "1024", "--image-max-tokens", "1536"] # 1024 = Qwen-VL grounding min; 1536 cap: same quality as 3.7k, 3x faster
|
||||
# key -> (label, model, mmproj, vision args (shots), text args (report/ask: no mmproj, more VRAM for layers/batch))
|
||||
MODELS = {
|
||||
# MoE experts in RAM (needs ~48+ GB RAM). Vision: encoder on GPU (CPU encoder was ~100 s/shot), so only 30/40 attention
|
||||
# layers fit (-ngl 25 halves gen speed). Text: no encoder -> all layers + -ub 2048 (prompt eval 230 -> 340 tok/s).
|
||||
"qwen35b": ("Qwen3.6 35B-A3B (RAM)", MD / "Qwen3.6-35B-A3B-UD-Q4_K_XL.gguf", MD / "mmproj-BF16.gguf",
|
||||
["--mmproj-offload", *_IMG, "--cpu-moe", "-ngl", "30", "-c", "16384", *_Q],
|
||||
["--cpu-moe", "-ngl", "99", "-c", "16384", "-ub", "2048", *_Q]),
|
||||
# Hybrid attention -> 16k KV is only ~0.3 GB. Q4_K_S: best boxes/entities vs IQ4_XS/Q4_K_M/UD-Q4_K_XL on 8 sample shots.
|
||||
# Vision: encoder on GPU, FFN of the last 13/32 layers in RAM to make room: shot 36 -> 22 s (CPU encoder was ~19 s/image),
|
||||
# gen only 30 -> 25 tok/s; 12 is the limit (10 OOMs), 13 leaves margin. Text: everything on GPU.
|
||||
"qwen4b": ("Qwen3.5 4B (VRAM)", MD / "qwen3.5-4b" / "Qwen3.5-4B-Q4_K_S.gguf", MD / "qwen3.5-4b" / "mmproj-BF16.gguf",
|
||||
["--mmproj-offload", *_IMG, "-ngl", "99", "-ot", r"blk\.(19|2[0-9]|3[01])\.ffn_.*=CPU", "-c", "16384", *_Q],
|
||||
["-ngl", "99", "-c", "16384", "-ub", "1024", *_Q]),
|
||||
}
|
||||
PORT = 18081
|
||||
EMBED, EMBED_PORT = Path(__file__).parent / "models" / "bge-m3-Q8_0.gguf", 18082
|
||||
EMBED, EMBED_PORT = MD / "bge-m3-Q8_0.gguf", 18082
|
||||
_open = urllib.request.build_opener(urllib.request.ProxyHandler({})).open # corp proxy must not see localhost
|
||||
|
||||
def available(): return [k for k, m in MODELS.items() if m[1].exists()]
|
||||
|
||||
def current(vision=True):
|
||||
"""Model for shots (vision) or report/ask (text): GUI choice if on disk, else 4B for shots (VRAM-only, near-35B shots)
|
||||
and the biggest model for reports (4B reports lose structure on long transcripts)."""
|
||||
ks = (CHOICE.read_text().split() if CHOICE.exists() else []) or [""]
|
||||
k = ks[0] if vision else ks[-1] # a single key (old format) applies to both
|
||||
av = available()
|
||||
if k in av: return k
|
||||
if vision and "qwen4b" in av: return "qwen4b"
|
||||
return (av or ["qwen4b"])[0]
|
||||
|
||||
def choose(vision_key, text_key): CHOICE.write_text(f"{vision_key} {text_key}")
|
||||
|
||||
def up(port=PORT):
|
||||
try: _open(f"http://127.0.0.1:{port}/health", timeout=2); return True
|
||||
except Exception: return False
|
||||
@@ -21,9 +53,10 @@ def _spawn(args, port, log):
|
||||
time.sleep(2)
|
||||
raise TimeoutError("llama-server not ready")
|
||||
|
||||
def start(model=MODEL, mmproj=MMPROJ, port=PORT, log="llama.log"):
|
||||
"""Start llama-server (attention on GPU, MoE experts on CPU: fits 4 GB). None if already running."""
|
||||
return _spawn(["-m", str(model), "--mmproj", str(mmproj), "-ngl", "99", "--cpu-moe", "-c", "16384", "--jinja"], port, log)
|
||||
def start(vision=True, port=PORT, log="llama.log"):
|
||||
"""Start llama-server with current() model; vision=False: text profile (no mmproj). None if already running."""
|
||||
_, model, mmproj, vargs, targs = MODELS[current(vision)]
|
||||
return _spawn(["-m", str(model), *(["--mmproj", str(mmproj), *vargs] if vision else targs), "--jinja"], port, log)
|
||||
|
||||
def start_embed(log="embed.log"):
|
||||
"""bge-m3 embeddings on CPU (never competes with the GPU model). None if already running."""
|
||||
|
||||
Reference in New Issue
Block a user