Auto-scale hardware: CUDA 13 only on cc>=7.5, pin ctranslate2 4.8 (cu12), fp16-less GPUs, CPU threads, llama --fit on >=7 GiB GPUs, CPU-only embeddings

This commit is contained in:
Stefano Zini
2026-11-04 14:14:26 +01:00
parent 03ba83fba8
commit a741859140
5 changed files with 48 additions and 19 deletions
+22 -2
View File
@@ -9,6 +9,7 @@ CHOICE = HERE / "out" / "_global" / "llm.txt" # GUI header: "<shots model> <rep
_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))
# Values below are the 4 GB profile; _fit() strips -ngl/-ot/--cpu-moe on >= 7 GiB GPUs.
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).
@@ -24,6 +25,25 @@ MODELS = {
}
PORT = 18081
EMBED, EMBED_PORT = MD / "bge-m3-Q8_0.gguf", 18082
@functools.cache
def vram_mib():
"""Largest NVIDIA GPU's total VRAM in MiB; 0 without NVIDIA driver."""
try: return max(int(x) for x in subprocess.run(["nvidia-smi", "--query-gpu=memory.total", "--format=csv,noheader,nounits"],
capture_output=True, text=True, timeout=10).stdout.split())
except (OSError, ValueError, subprocess.SubprocessError): return 0
_TUNED = {"-ngl": 1, "-ot": 1, "--cpu-moe": 0} # 4 GB placement flags -> number of values they take
def _fit(args, vision):
"""GPUs >= 7 GiB: drop the 4 GB hand-tuned layer/expert placement so llama.cpp --fit (default on) fills VRAM.
Vision keeps 3 GiB margin: --fit sizes only the LLM, the mmproj encoder loads after it."""
if vram_mib() < 7168: return args
out, it = [], iter(args)
for a in it:
if a in _TUNED:
for _ in range(_TUNED[a]): next(it)
else: out.append(a)
return out + (["-fitt", "3072"] if vision else [])
_open = urllib.request.build_opener(urllib.request.ProxyHandler({})).open # corp proxy must not see localhost
PROXY = "http://zproxy.idg.audi.vwg:9400" # corp proxy for internet calls (docs.py twg, cloud LLMs)
@@ -164,12 +184,12 @@ 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."""
if current(vision) in REMOTE: return None
_, model, mmproj, vargs, targs = MODELS[current(vision)]
return _spawn(["-m", str(model), *(["--mmproj", str(mmproj), *vargs] if vision else targs), "--jinja"], port, log)
return _spawn(["-m", str(model), *(["--mmproj", str(mmproj), *_fit(vargs, True)] if vision else _fit(targs, False)), "--jinja"], port, log)
def start_embed(log="embed.log"):
"""bge-m3 embeddings on CPU (never competes with the GPU model). None if already running."""
if not EMBED.exists(): raise FileNotFoundError(f"{EMBED} missing: hf download gpustack/bge-m3-GGUF bge-m3-Q8_0.gguf --local-dir models")
return _spawn(["-m", str(EMBED), "--embeddings", "--pooling", "cls", "-ngl", "0", "-c", "8192", "-b", "2048", "-ub", "2048"], EMBED_PORT, log)
return _spawn(["-m", str(EMBED), "--embeddings", "--pooling", "cls", "-ngl", "0", "-dev", "none", "-c", "8192", "-b", "2048", "-ub", "2048"], EMBED_PORT, log)
OMP_BUILD = "https://build.stencil.so/api/products/omp/latest/windows-x86_64?channel=stable"
MODELS_YML = """providers: