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

  1. 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
  2. Prefer a safetensors copy of the same model if available; safetensors avoids the pickle path entirely
  3. Inspect the archive with `python -m zipfile -l file.ckpt` to confirm the duplicate data.pkl entries
  4. 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

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


AI-assisted analysis of AUTOMATIC1111/stable-diffusion-webui@82a973c043 (2026-08-14). Data as JSON: /api/errors/c2180536b44d50f0. Report an issue: GitHub.