diff --git a/comfy/utils.py b/comfy/utils.py index 61c2a22dd..b159844c9 100644 --- a/comfy/utils.py +++ b/comfy/utils.py @@ -119,6 +119,31 @@ def load_safetensors(ckpt): return sd, header.get("__metadata__", {}), +def load_safetensors_no_mmap(ckpt, device): + # safetensors.safe_open()/get_tensor() reads tensor data through an mmap of + # the file. On Windows that mmap-backed read can crash with an access + # violation for large files in a long-running process. Read the tensors + # with plain file I/O instead so no mmap of the file is ever created. + sd = {} + with open(ckpt, "rb") as f: + header_size = struct.unpack("