{"record":{"id":"b668794c0fe118a8","repo":"Comfy-Org/ComfyUI","slug":"n-nfile-path-n-nthe-safetensors-file-is-cor","errorCode":null,"errorMessage":"{}\\n\\nFile path: {}\\n\\nThe safetensors file is corrupt or invalid. Make sure this is actually a safetensors file and not a ckpt or pt or other filetype.","messagePattern":"(.+?)\\\\n\\\\nFile path: (.+?)\\\\n\\\\nThe safetensors file is corrupt or invalid\\. Make sure this is actually a safetensors file and not a ckpt or pt or other filetype\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy/utils.py","lineNumber":146,"sourceCode":"            if comfy.memory_management.aimdo_enabled:\n                sd, metadata = load_safetensors(ckpt)\n                if not return_metadata:\n                    metadata = None\n            else:\n                with safetensors.safe_open(ckpt, framework=\"pt\", device=device.type) as f:\n                    sd = {}\n                    for k in f.keys():\n                        tensor = f.get_tensor(k)\n                        if DISABLE_MMAP:  # TODO: Not sure if this is the best way to bypass the mmap issues\n                            tensor = tensor.to(device=device, copy=True)\n                        sd[k] = tensor\n                    if return_metadata:\n                        metadata = f.metadata()\n        except Exception as e:\n            if len(e.args) > 0:\n                message = e.args[0]\n                if \"HeaderTooLarge\" in message:\n                    raise ValueError(\"{}\\n\\nFile path: {}\\n\\nThe safetensors file is corrupt or invalid. Make sure this is actually a safetensors file and not a ckpt or pt or other filetype.\".format(message, ckpt))\n                if \"MetadataIncompleteBuffer\" in message:\n                    raise ValueError(\"{}\\n\\nFile path: {}\\n\\nThe safetensors file is corrupt/incomplete. Check the file size and make sure you have copied/downloaded it correctly.\".format(message, ckpt))\n            raise e\n    else:\n        torch_args = {}\n        if MMAP_TORCH_FILES:\n            torch_args[\"mmap\"] = True\n\n        pl_sd = torch.load(ckpt, map_location=device, weights_only=True, **torch_args)\n\n        if \"state_dict\" in pl_sd:\n            sd = pl_sd[\"state_dict\"]\n        else:\n            if len(pl_sd) == 1:\n                key = list(pl_sd.keys())[0]\n                sd = pl_sd[key]\n                if not isinstance(sd, dict):\n                    sd = pl_sd","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy/utils.py#L128-L164","documentation":"comfy.utils.load_torch_file uses safetensors.safe_open when the file ends in .safetensors. safetensors raises HeaderTooLarge when the 8-byte header length prefix is absurdly large — the classic signature of a pickle-based .ckpt/.pt file renamed to .safetensors, or a truncated/corrupt download. ComfyUI re-raises with the file path and an explanation suggesting a wrong file type.","triggerScenarios":"Calling load_torch_file on a .safetensors-suffixed file whose first 8 bytes decode to a huge header size — e.g. a PyTorch pickle file renamed, a ckpt saved with the wrong extension, or a partially downloaded file.","commonSituations":"Renamed ckpt to safetensors to satisfy a loader; download interrupted so only the beginning exists; file is actually a git-lfs pointer or HTML error page saved with the right name.","solutions":["Confirm the true file type (file model.safetensors / xxd first bytes); if pickle/zip, rename to .ckpt/.pt so the torch.load branch is used","Re-download the file and check its size against the source","If it is a git-lfs pointer or HTML page, fetch the real binary with git lfs pull or a proper URL"],"exampleFix":"// before\nsd = utils.load_torch_file('model.safetensors')  # actually a renamed ckpt\n\n# after\n# file model.safetensors -> 'Zip archive' or pickle: rename to model.ckpt\nsd = utils.load_torch_file('model.ckpt')","handlingStrategy":"validation","validationCode":"def looks_like_safetensors(path):\n    with open(path, 'rb') as f:\n        import struct\n        n = struct.unpack('<Q', f.read(8))[0]\n    return 0 < n < 100_000_000  # sane header size\nif path.endswith('.safetensors') and not looks_like_safetensors(path):\n    raise ValueError('file is not a real safetensors file (probably renamed ckpt or truncated)')","typeGuard":null,"tryCatchPattern":"except ValueError as e:\n    if 'corrupt or invalid' in str(e):\n        # point user at file type check / re-download\n        raise","preventionTips":["Never rename .ckpt/.pt to .safetensors","Check the first bytes with `file` before loading unfamiliar checkpoints"],"tags":["safetensors","checkpoint","corrupt-file","model-loading"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}