AUTOMATIC1111/stable-diffusion-webui · error · Exception
data.pkl not found in {filename}
Error message
data.pkl not found in {filename} What it means
After passing the zip-filename check, check_pt looks for exactly one member matching '<dir>/data.pkl' — the pickle that describes the stored tensors. Zero matches means the archive is a valid zip but has no PyTorch data.pkl, so it cannot be a new-format torch checkpoint, and the Exception is raised (the subsequent BadZipfile branch for legacy format is not taken because the file opened as a zip fine).
Source
Thrown at modules/safe.py:89
def check_zip_filenames(filename, names):
for name in names:
if allowed_zip_names_re.match(name):
continue
raise Exception(f"bad file inside {filename}: {name}")
def check_pt(filename, extra_handler):
try:
# new pytorch format is a zip file
with zipfile.ZipFile(filename) as z:
check_zip_filenames(filename, z.namelist())
# find filename of data.pkl in zip file: '<directory name>/data.pkl'
data_pkl_filenames = [f for f in z.namelist() if data_pkl_re.match(f)]
if len(data_pkl_filenames) == 0:
raise Exception(f"data.pkl not found in {filename}")
if len(data_pkl_filenames) > 1:
raise Exception(f"Multiple data.pkl found in {filename}")
with z.open(data_pkl_filenames[0]) as file:
unpickler = RestrictedUnpickler(file)
unpickler.extra_handler = extra_handler
unpickler.load()
except zipfile.BadZipfile:
# if it's not a zip file, it's an old pytorch format, with five objects written to pickle
with open(filename, "rb") as file:
unpickler = RestrictedUnpickler(file)
unpickler.extra_handler = extra_handler
for _ in range(5):
unpickler.load()
def load(filename, *args, **kwargs):
View on GitHub (pinned to 82a973c043)
Solutions
- Verify the file is a real PyTorch checkpoint: `python -c "import zipfile;print(zipfile.ZipFile('model.ckpt').namelist())"` should show data.pkl and data/* entries.
- Re-download the model from its official source — a truncated or proxy-replaced download often yields a small invalid zip.
- Remove non-checkpoint archives from the models directories so the scanner doesn't try to load them.
Example fix
# before mv photos.zip model.ckpt # renamed archive -> 'data.pkl not found' # after: use a genuine torch export # torch.save(state_dict, 'model.ckpt') # archive contains data.pkl + data/0...
Defensive patterns
Strategy: validation
Validate before calling
import re, zipfile
def has_data_pkl(path):
pat = re.compile(r'^([^/]+)/data\.pkl$')
try:
with zipfile.ZipFile(path) as z:
return any(pat.match(n) for n in z.namelist())
except zipfile.BadZipFile:
return False # legacy (non-zip) torch format is handled separately
assert has_data_pkl('model.ckpt'), 'not a new-format torch checkpoint; check the file type/download' Type guard
def looks_like_torch_zip_checkpoint(path: str) -> bool:
import re, zipfile
pat = re.compile(r'^([^/]+)/data\.pkl$')
try:
with zipfile.ZipFile(path) as z:
return any(pat.match(n) for n in z.namelist())
except zipfile.BadZipFile:
return False Try / catch
try:
weights = torch.load(path)
except Exception as e:
if 'data.pkl not found' in str(e):
raise RuntimeError(f'{path} is a zip but not a torch checkpoint; verify the download/source')
raise Prevention
- Verify downloads by size/checksum against the official release before loading.
- Keep models directories free of unrelated zip/npz/renamed files.
When it happens
Trigger: Passing a file to torch.load/webui loading that is a valid zip archive but not a torch checkpoint — e.g. a renamed .zip, a .npz, an ONNX file, or a torch .pt' archive whose data.pkl sits at a nonstandard path already rejected earlier.
Common situations: Renaming unrelated archives to .ckpt/.pt; corrupted downloads that are actually HTML/error zips; model files from other frameworks accidentally placed in models/Stable-diffusion.
Related errors
- global '{module}/{name}' is forbidden
- bad file inside {filename}: {name}
- Requests not allowed
- Request to local resource not allowed
- When merging inpainting model with a normal one, A must be t
AI-assisted analysis of AUTOMATIC1111/stable-diffusion-webui@82a973c043 (2026-08-14).
Data as JSON: /api/errors/f455595de182c0fe.
Report an issue: GitHub.