{"record":{"id":"a35a4b0bf2841b41","repo":"Comfy-Org/ComfyUI","slug":"n-nfile-path-n-nthe-safetensors-file-is-cor-a35a4b","errorCode":null,"errorMessage":"{}\\n\\nFile path: {}\\n\\nThe safetensors file is corrupt/incomplete. Check the file size and make sure you have copied/downloaded it correctly.","messagePattern":"(.+?)\\\\n\\\\nFile path: (.+?)\\\\n\\\\nThe safetensors file is corrupt/incomplete\\. Check the file size and make sure you have copied/downloaded it correctly\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy/utils.py","lineNumber":148,"sourceCode":"                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\n            else:\n                sd = pl_sd","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy/utils.py#L130-L166","documentation":"When loading a .safetensors file, safetensors raises MetadataIncompleteBuffer when the declared header size exceeds the bytes actually present in the file — i.e. the file is truncated relative to its own header. ComfyUI catches this in load_torch_file and raises a ValueError pointing at incomplete copy/download.","triggerScenarios":"load_torch_file on a .safetensors file truncated by an interrupted download/transfer, or a file corrupted by disk issues, such that the header region is incomplete.","commonSituations":"Browser download cut off; scp/rsync interrupted; cloud-sync placeholder files; file copied while still being written.","solutions":["Re-download or re-copy the safetensors file and verify its byte size matches the source","Check hash if the source publishes one (sha256/civitai hash)","If it is a cloud-sync placeholder, force the sync app to materialize the file before loading"],"exampleFix":"// before\nsd = utils.load_torch_file('model.safetensors')  # truncated\n\n# after\n# re-download, then verify expected size before loading\nassert os.path.getsize('model.safetensors') == EXPECTED_BYTES\nsd = utils.load_torch_file('model.safetensors')","handlingStrategy":"validation","validationCode":"import os\nexpected = 6425467122  # from source metadata if known\nif path.endswith('.safetensors') and os.path.getsize(path) < 1_000_000:\n    raise ValueError('safetensors suspiciously small; download likely incomplete')","typeGuard":null,"tryCatchPattern":"except ValueError as e:\n    if 'corrupt/incomplete' in str(e):\n        # trigger re-download path\n        raise","preventionTips":["Verify file size/hash against the source after downloading","Avoid loading files while a download or cloud sync is still in progress"],"tags":["safetensors","checkpoint","truncated-download","model-loading"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}