diff --git a/backend/services/llamaswap.py b/backend/services/llamaswap.py index 98f1645..2205bdf 100644 --- a/backend/services/llamaswap.py +++ b/backend/services/llamaswap.py @@ -27,6 +27,24 @@ ROLE_IDS = {"fast", "heavy", "coder", "vision", "scout"} _CTX_RE = re.compile(r"-(?:c|-ctx-size)\s+(\d+)") _PATH_RE = re.compile(r"-(?:m|-model)\s+([^\s]+)") _QUANT_RE = re.compile(r"(Q\d_[A-Z0-9_]+|IQ\d_[A-Z0-9_]+|fp16|bf16)\.gguf", re.IGNORECASE) +_SPLIT_RE = re.compile(r"-(\d+)-of-(\d+)\.gguf$", re.IGNORECASE) + + +def _gguf_total_size(path: str) -> int | None: + """Gesamtgröße eines GGUF inkl. ALLER Split-Teile (…-00001-of-00003.gguf). + Die Größe nur des ersten Teils ist bei Splits irreführend (oft nur ein Header).""" + try: + base = os.path.basename(path) + m = _SPLIT_RE.search(base) + if not m: + return os.path.getsize(path) + prefix, dirn = base[:m.start()], os.path.dirname(path) + total = sum(os.path.getsize(os.path.join(dirn, f)) + for f in os.listdir(dirn) + if f.startswith(prefix) and _SPLIT_RE.search(f)) + return total or os.path.getsize(path) + except OSError: + return None # --- Lesen ------------------------------------------------------------------- @@ -54,7 +72,7 @@ def _parse_model(name: str, spec: dict) -> dict: path = m.group(1).replace("'", "").replace('"', "") filename = os.path.basename(path) if os.path.exists(path): - size_bytes = os.path.getsize(path) + size_bytes = _gguf_total_size(path) if (q := _QUANT_RE.search(path)): quant = q.group(1).upper()