invoke-ai/InvokeAI · error · Exception

Error scanning model at {checkpoint} for malware. Aborting l

Error message

Error scanning model at {checkpoint} for malware. Aborting load.

What it means

torch_load_file aborts loading when the picklescan tool itself errors while scanning the checkpoint (scan_result.scan_err true), e.g. the scanner cannot parse the pickle stream. If unsafe_disable_picklescan is false this becomes a hard Exception rather than a warning.

Source

Thrown at invokeai/app/services/model_load/model_load_default.py:135

        def torch_load_file(checkpoint: Path) -> AnyModel:
            scan_result = scan_file_path(checkpoint)
            if scan_result.infected_files != 0:
                if self._app_config.unsafe_disable_picklescan:
                    self._logger.warning(
                        f"Model at {checkpoint} is potentially infected by malware, but picklescan is disabled. "
                        "Proceeding with caution."
                    )
                else:
                    raise Exception(f"The model at {checkpoint} is potentially infected by malware. Aborting load.")
            if scan_result.scan_err:
                if self._app_config.unsafe_disable_picklescan:
                    self._logger.warning(
                        f"Error scanning model at {checkpoint} for malware, but picklescan is disabled. "
                        "Proceeding with caution."
                    )
                else:
                    raise Exception(f"Error scanning model at {checkpoint} for malware. Aborting load.")

            result = torch_load(checkpoint, map_location="cpu")
            return result

        def diffusers_load_directory(directory: Path) -> AnyModel:
            load_class = GenericDiffusersLoader(
                app_config=self._app_config,
                logger=self._logger,
                ram_cache=ram_cache,
                convert_cache=self.convert_cache,
            ).get_hf_load_class(directory)
            return load_class.from_pretrained(model_path, torch_dtype=TorchDevice.choose_torch_dtype())

        loader = loader or (
            diffusers_load_directory
            if model_path.is_dir()
            else torch_load_file
            if model_path.suffix.endswith((".ckpt", ".pt", ".pth", ".bin"))

View on GitHub (pinned to 0b6a024f2f)

Solutions

  1. Re-download the model file and verify checksum/size.
  2. Open/convert the checkpoint in PyTorch directly (torch.load) in a sandbox, then re-save as safetensors.
  3. Update picklescan (pip install -U picklescan) and InvokeAI.
  4. As a last resort for trusted files, set unsafe_disable_picklescan=true.

Example fix

// before
# corrupt partial download triggers scan error
load({ path: 'partial_download.ckpt' });
// after
# verify integrity first, then load
// sha256sum model.ckpt  # compare to published hash
load({ path: 'model.ckpt' });
Defensive patterns

Strategy: try-catch

Validate before calling

def is_loadable_checkpoint(path) -> bool:
    if not path.is_file() or path.stat().st_size == 0:
        return False
    try:
        from picklescan import scan_file_path
        return scan_file_path(path).scan_err is False
    except Exception:
        return False

Try / catch

try:
    model = loader.load_model(path)
except Exception as e:
    if 'Error scanning model' in str(e):
        log.error('picklescan failed on %s; re-download or convert to safetensors', path)
        raise
    raise

Prevention

When it happens

Trigger: Passing a malformed, truncated, encrypted, or non-standard pickle/zip archive (corrupt .pt/.ckpt, partially downloaded file) to torch_load_file, or a file using pickle features picklescan cannot parse.

Common situations: Interrupted downloads yielding partial files; exotic checkpoint formats saved by non-PyTorch tools; picklescan version incompatibilities with new pickle opcodes; archived/zipped checkpoints with unusual structures.

Related errors


AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29). Data as JSON: /api/errors/5aebeb80f5f0d24e. Report an issue: GitHub.