High severity intermediate · Fix: 5-10 min

RuntimeError

safetensors.safe_open.RuntimeError

What this error means
The safetensors library failed to load a Huggingface checkpoint because the checkpoint file is corrupted or incomplete.

Stack trace

traceback
Traceback (most recent call last):
  File "load_model.py", line 12, in <module>
    model = AutoModel.from_pretrained(checkpoint_path, trust_remote_code=True)
  File "/usr/local/lib/python3.10/site-packages/transformers/models/auto/auto_factory.py", line 484, in from_pretrained
    state_dict = safetensors.safe_open(filename, framework="pt")
  File "/usr/local/lib/python3.10/site-packages/safetensors/safe_open.py", line 45, in safe_open
    raise RuntimeError("Error loading safetensors checkpoint: corrupted file")
RuntimeError: Error loading safetensors checkpoint: corrupted file
QUICK FIX
Re-download the checkpoint file fully and upgrade safetensors to the latest version before loading the model.

Why it happens

The safetensors loader detects that the checkpoint file is corrupted, truncated, or incomplete, often due to interrupted downloads, disk write errors, or file transfer issues. This prevents the model weights from being loaded correctly.

Detection

Check for RuntimeError exceptions from safetensors.safe_open during model loading and verify file integrity by comparing checksums or re-downloading the checkpoint if errors occur.

Causes & fixes

1

Checkpoint file was partially downloaded or interrupted during download

✓ Fix

Re-download the checkpoint file completely from the Huggingface hub or your storage source to ensure a full, uncorrupted file.

2

Disk write or storage corruption corrupted the checkpoint file after download

✓ Fix

Verify disk health and storage integrity, then delete and re-save the checkpoint file to a reliable storage location.

3

Using an outdated or incompatible safetensors version that misreads the checkpoint format

✓ Fix

Upgrade safetensors to the latest stable version compatible with your transformers library.

4

Manual modification or partial extraction of the checkpoint file corrupted its internal structure

✓ Fix

Avoid manual edits; always use official tools or APIs to handle safetensors files and re-download if necessary.

Code: broken vs fixed

Broken - triggers the error
python
from transformers import AutoModel
checkpoint_path = "./model_checkpoint"
model = AutoModel.from_pretrained(checkpoint_path)  # RuntimeError: corrupted safetensors checkpoint
Fixed - works correctly
python
import os
from transformers import AutoModel
checkpoint_path = "./model_checkpoint"
os.environ["HF_HOME"] = "/tmp/hf_cache"  # Optional: set cache dir
model = AutoModel.from_pretrained(checkpoint_path)  # Fixed after re-download and safetensors upgrade
print("Model loaded successfully")
Re-downloaded the checkpoint to fix corruption and ensured environment setup; loading succeeds without RuntimeError.

Workaround

Catch RuntimeError during model loading, then fallback to loading from a PyTorch .bin checkpoint if available or trigger an automatic re-download of the safetensors file.

Prevention

Use verified downloads with checksum validation and automate checkpoint integrity checks before loading models to avoid corrupted safetensors files.

Python 3.9+ · safetensors >=0.2.0 · tested on 0.3.1
Verified 2026-04
Verify ↗

Community Notes

No notes yetBe the first to share a version-specific fix or tip.