How does ComfyUI decide whether to load a checkpoint as safetensors or via torch.load, and what does PyTorch's documentation say about weights_only?
Problem. A file named .safetensors vs .ckpt/.pt/.pth/.bin/.pkl is the only gate between data loading and pickle deserialisation. Conditions. ComfyUI v0.42.5 comfy/utils.py load_torch_file; PyTorch 2.14 docs. Method. load_torch_file dispatches on the lower-cased filename suffix: .safetensors or .sft use safetensors (safe_open, or load_safetensors when the aimdo path is enabled); every other extension goes to torch.load(..., weights_only=True). folder_paths.supported_pt_extensions lists .ckpt, .pt, .pt2, .bin, .pth, .safetensors, .pkl and .sft, so those pickle-family files are listed in the model dropdowns. The torch.load documentation warns that it uses an unpickler and says never to load data from an untrusted source; its weights_only=True mode restricts loading to tensors, primitive types, dictionaries and registered safe globals. Failure modes. Dispatch is by extension, not content: the function argument safe_load is accepted but not referenced in the body; custom nodes may call t...
Structured fields
{
"citations": [
{
"url": "https://raw.githubusercontent.com/comfyanonymous/ComfyUI/483dae4326356b81de05d27aca3f433dd323cc25/comfy/utils.py",
"note": "load_torch_file; load_torch_file signature; torch.load warning"
},
{
"url": "https://docs.pytorch.org/docs/2.14/generated/torch.load.html",
"note": "load_torch_file; load_torch_file signature; torch.load warning"
}
]
}Evidence claims
- [sourced_fact] Problem. A file named .safetensors vs .ckpt/.pt/.pth/.bin/.pkl is the only gate between data loading and pickle deserialisation. Conditions. ComfyUI v0.42.5 comfy/utils.py load_torch_file; PyTorch 2.14 docs. Method. load_torch_file dispatches on the lower-cased filename suffix: .safetensors or .sft use safetensors (safe_open, or load_safetensors when the aimdo path is enabled); every other extension goes to torch.load(..., weights_only=True). folder_paths.supported_pt_extensions lists .ckpt, .pt, .pt2, .bin, .pth, .safetensors, .pkl and .sft, so those pickle-family files are listed in the model dropdowns. The torch.load documentation warns that it uses an unpickler and says never to load data from an untrusted source; its weights_only=True mode restricts loading to tensors, primitive types, dictionaries and registered safe globals. Failure modes. Dispatch is by extension, not content: the function argument safe_load is accepted but not referenced in the body; custom nodes may call torch.load directly with weights_only=False; weights_only restricts but the PyTorch page itself still recommends caution. Header-size and truncated safetensors errors are given friendly messages (HeaderTooLarge, MetadataIncompleteBuffer). Limitations. Prior item G17-04 covered formats that run code at the pinned versions of its own; this adds the dispatch rule and the unused safe_load parameter. Not tested with a crafted file (no downloads). Version and date. ComfyUI v0.42.5; PyTorch docs 2.14. · locator: load_torch_file; load_torch_file signature; torch.load warning source
Rights
| component | license | hosting | redistribution | modification | training | Evidence and notes |
|---|---|---|---|---|---|---|
| documentation | unknown | permitted | permitted | unknown | unknown | Applies to this original summary only, not to the cited sources. |