From 752def584fa1cfabc3f0cecd7d2d8539023ce844 Mon Sep 17 00:00:00 2001 From: xmarre Date: Sun, 12 Apr 2026 05:42:29 +0200 Subject: [PATCH] load torch checkpoints on cpu before cuda remap --- patches.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/patches.py b/patches.py index 5894a85..83e5c32 100644 --- a/patches.py +++ b/patches.py @@ -240,7 +240,8 @@ def _patched_load_torch_file(ckpt, safe_load=False, device=None, return_metadata if getattr(comfy_utils, "MMAP_TORCH_FILES", False): torch_args["mmap"] = True - pl_sd = torch.load(ckpt, map_location=requested_device, weights_only=True, **torch_args) + torch_load_device = torch.device("cpu") if requested_device.type == "cuda" else requested_device + pl_sd = torch.load(ckpt, map_location=torch_load_device, weights_only=True, **torch_args) if "state_dict" in pl_sd: sd = pl_sd["state_dict"] else: