Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

studio/mmproj: skip unwanted GGUF values via seek instead of read (#5431)

Daniel Hanbbd0ba0c2593
diff --git a/studio/backend/utils/models/gguf_metadata.py b/studio/backend/utils/models/gguf_metadata.py
index 9aab88329d5..5629bac58b5 100644
--- a/studio/backend/utils/models/gguf_metadata.py
+++ b/studio/backend/utils/models/gguf_metadata.py
@@ -152,7 +152,9 @@ _FIXED_VTYPE_SIZES: Dict[int, int] = {
def _skip_gguf_value(f, vtype: int) -> bool:
- """Advance past one GGUF value. False on truncation or unknown type."""
+ """Advance past one GGUF value. ``f.seek(.., 1)`` past EOF is legal
+ on a regular file so truncation is detected on the next read; we
+ only return False for unknown types or sanity-bound overflow."""
if vtype == 8: # STRING
slen_bytes = f.read(8)
if len(slen_bytes) < 8:
@@ -160,7 +162,8 @@ def _skip_gguf_value(f, vtype: int) -> bool:
slen = struct.unpack("<Q", slen_bytes)[0]
if slen > 1 << 30: # 1 GB sanity bound
return False
- return len(f.read(slen)) == slen
+ f.seek(slen, 1)
+ return True
if vtype == 9: # ARRAY
head = f.read(12)
if len(head) < 12:
@@ -176,18 +179,18 @@ def _skip_gguf_value(f, vtype: int) -> bool:
slen = struct.unpack("<Q", slen_bytes)[0]
if slen > 1 << 30:
return False
- if len(f.read(slen)) != slen:
- return False
+ f.seek(slen, 1)
return True
sz = _FIXED_VTYPE_SIZES.get(atype)
if sz is None:
return False
- total = sz * alen
- return len(f.read(total)) == total
+ f.seek(sz * alen, 1)
+ return True
sz = _FIXED_VTYPE_SIZES.get(vtype)
if sz is None:
return False
- return len(f.read(sz)) == sz
+ f.seek(sz, 1)
+ return True
def is_mmproj_by_metadata(meta: Optional[Dict[str, str]]) -> Optional[bool]: