AUTOMATIC1111/stable-diffusion-webui · error · Exception
Multiple data.pkl found in {filename}
Error message
Multiple data.pkl found in {filename} What it means
Raised by safe.py's check_pt() when scanning a PyTorch zip-format checkpoint (.ckpt/.pt). The new PyTorch serialization format stores the pickle payload in a file named '<dir>/data.pkl'; the security checker expects exactly one match for data_pkl_re in the archive's namelist. More than one match means the archive is malformed or was hand-assembled from multiple checkpoints, so the loader refuses to unpickle it.
Source
Thrown at modules/safe.py:91
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):
return load_with_extra(filename, *args, extra_handler=global_extra_handler, **kwargs)
View on GitHub (pinned to 82a973c043)
Solutions
- Re-export the model: load the state dict in PyTorch (torch.load) and re-save it with torch.save(state_dict, out.pt) so the archive has a single data.pkl
- Prefer a safetensors copy of the same model if available; safetensors avoids the pickle path entirely
- Inspect the archive with `python -m zipfile -l file.ckpt` to confirm the duplicate data.pkl entries
- Re-download the checkpoint from the original source if the file may be corrupted
Example fix
# before: merging two zip checkpoints by concatenating entries (produces two data.pkl)
# after: merge via state dicts and re-save
import torch
a = torch.load('a.ckpt', map_location='cpu')
b = torch.load('b.ckpt', map_location='cpu')
a['state_dict'].update({k: 0.5*(v+b['state_dict'][k]) for k, v in a['state_dict'].items()})
torch.save(a, 'merged.ckpt') # single data.pkl Defensive patterns
Strategy: validation
Validate before calling
import re, zipfile
data_pkl_re = re.compile(r'^[^/]+/data\.pkl$')
def check_archive_has_single_pkl(path):
with zipfile.ZipFile(path) as z:
matches = [f for f in z.namelist() if data_pkl_re.match(f)]
if len(matches) != 1:
raise ValueError(f'{path}: expected 1 data.pkl, found {matches}')
return True Try / catch
try:
modules.safe.check_pt(path, extra_handler)
except Exception as e:
if 'Multiple data.pkl' in str(e):
# re-export the checkpoint via state dicts, then retry
... Prevention
- Only merge checkpoints by loading state dicts and re-saving with torch.save
- Verify downloads with the publisher's checksum before loading
- Prefer safetensors distribution formats when available
When it happens
Trigger: Calling load/embedding-checkpoint paths that run check_pt() on a file whose ZipFile.namelist() contains two or more entries matching the data.pkl regex (e.g. both 'archive/data.pkl' and 'foo/data.pkl'), typically after merging zipped checkpoints or re-zipping a model incorrectly.
Common situations: Merging two v1/v2 checkpoints with a script that concatenates zip entries instead of loading state dicts; manually repacking a .ckpt with 'zip -r'; downloading a corrupted or re-packaged model from a mirror.
Related errors
- Lora layer {self.network_key} matched a layer with unsupport
- bad file inside {filename}: {name}
- No checkpoints found. When searching for checkpoints, looked
- Unknown checkpoint: {x}
- Could not find a module type (out of {', '.join([x.__class__
AI-assisted analysis of AUTOMATIC1111/stable-diffusion-webui@82a973c043 (2026-08-14).
Data as JSON: /api/errors/c2180536b44d50f0.
Report an issue: GitHub.