From cd3ff69a1421fe6bb3ad5cd13f9bede9f4ffc1d7 Mon Sep 17 00:00:00 2001 From: ussoewwin <136552381+ussoewwin@users.noreply.github.com> Date: Wed, 26 Aug 2026 11:40:30 +0900 Subject: [PATCH] fix(cache): read precompiled cache as bytes, not mmap (Windows page error) load_file() is mmap-based; a cache file with a readable header but damaged data region crashes the whole process with a Windows fatal 'page error' (uncatchable). Read the file as plain bytes and parse with safetensors.torch.load so the same damage surfaces as OSError -> existing except returns {} -> caller falls back to re-fuse. Verified: broken cache returns empty dict (no crash), good cache still loads fully. --- nunchaku_code/lora_cache.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/nunchaku_code/lora_cache.py b/nunchaku_code/lora_cache.py index 90ebc0f..7477332 100644 --- a/nunchaku_code/lora_cache.py +++ b/nunchaku_code/lora_cache.py @@ -263,13 +263,21 @@ def load_precompiled( a full re-fuse gracefully. """ try: - from safetensors.torch import load_file as st_load_file + from safetensors.torch import load as st_load_bytes except ImportError as exc: logger.error(f"[CACHE] Cannot load precompiled cache: safetensors not available. {exc}") return {} try: - flat: Dict[str, torch.Tensor] = st_load_file(str(cache_path), device="cpu") + # Read as plain bytes instead of ``load_file`` (mmap). A damaged cache + # file can still expose a readable header but fail during the mmap'd + # tensor read, which crashes the whole process with a Windows fatal + # "page error" that Python cannot catch. A plain read surfaces the same + # damage as an ordinary OSError, so the existing except below falls + # back to a full re-fuse gracefully. + with open(cache_path, "rb") as fh: + data = fh.read() + flat: Dict[str, torch.Tensor] = st_load_bytes(data) except Exception as exc: logger.error(f"[CACHE] Failed to load {cache_path}: {exc}") return {}