published fresh until

scikit-learn: reject incompatible saved pipelines

Summary Persist the entire fitted pipeline with its training environment, choose compression or shared read-only arrays, and refuse version mismatches before serving. Promote the warning with warnings.simplefilter("error", InconsistentVersionWarning)

Not for training split leakage; see scikit-learn-train-validate-pipeline-without-preprocessing-leaks.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: compare the artifact's training-environment manifest with serving dependencies before calling joblib.load, then promote InconsistentVersionWarning to an exception.

Short answer

As of November 2026, scikit-learn 1.9.1 is the reference release, not permission to load an older fitted artifact. Persist preprocessing and estimator together. Recreate the same dependency versions or retrain; cross-version loading is unsupported (persistence guide).

Choose / don't choose

  • Trusted, large-array artifact: choose joblib; don't load a pickle-based artifact from an untrusted producer (load warning).
  • Several serving workers: choose an uncompressed artifact and read-only memory mapping; don't compress and expect shared mapped arrays.
  • Reviewable type trust: choose skops.io.load when supported object types can be reviewed explicitly; don't blindly trust every type reported by the file. (skops guide).

Not for: training split leakage; see scikit-learn-train-validate-pipeline-without-preprocessing-leaks.

Settings that matter

Setting or flagValue / defaultApplies toSource
joblib.dump(..., compress=3)Documented size/speed compromise; default 0 means no compression; higher compression costs read/write timeCurrent stable joblib dumpdump
joblib.dump(..., compress=0)Select for mmap sharing; avoid a compression-triggering filename suffixCurrent stable joblib dumpdump
joblib.load(..., mmap_mode="r")Memory mapping for eligible uncompressed arrays; default None; compressed arrays cannot be mappedCurrent stable joblib loadload
ensure_native_byte_orderDefault "auto": true without mapping, false with it; explicit true conflicts with non-null mmap modeCurrent stable joblib loadload
skops.io.load(..., trusted=...)Explicit reviewed list from get_untrusted_types(file=...); never automatically approve the whole listCurrent stable skopsskops

Order of operations

1. Save the fitted pipeline and an immutable environment manifest: Python, scikit-learn, NumPy, SciPy, joblib and every custom transformer/third-party estimator package at training time. Keep training recipe, data reference and validation score alongside it (persistence). 2. Select compress=3 for smaller transport or compress=0 plus mmap_mode="r" for shared arrays. Measure artifact bytes, cold-load latency and worker memory separately; no one choice optimizes all three (dump, load). 3. Before trusted loading, set warnings.simplefilter("error", InconsistentVersionWarning). Catch that warning as an exception, capture original_sklearn_version, refuse readiness and restore the matching environment or retrain. Reject other load exceptions too (persistence, warning API). 4. Compare representative prediction outputs and input feature schema with the saved acceptance baseline before admitting traffic. Successful deserialization alone does not establish semantic compatibility. 5. For skops, inspect unknown types first, approve only intended types, then load. Converting an untrusted pickle with skops convert is unsafe because conversion itself loads the pickle (skops).

Known failures and fixes

Error (short quote)CauseFixSource
InconsistentVersionWarningEstimator's saved version differs from runtimeTreat as startup failure and use matching dependencies or a newly trained artifactwarning API
ValueError: node array from the pickle has an incompatible dtypeVersion 1.3.0 has broken backward compatibility for loading older models with joblibReject artifact; restore training environment or retrain; don't patch private serialized fieldsBenjVig, July 7, 2023

That report supplies an actual incompatible tree-artifact load, rather than a guarantee that all estimators fail in the same way.

Missing

  • No fitted pipeline, dependency manifest, array mutation requirement or latency budget is specified.
  • Compression level 3 is joblib guidance; optimal compression and mmap benefit require measurements for the actual pipeline.

Started from a post by @BenjVig, packaged by the editor. Original post

Subjects

More in local models

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# scikit-learn: reject incompatible saved pipelines
Summary: Persist the entire fitted pipeline with its training environment, choose compression or shared read-only arrays, and refuse version mismatches before serving. Promote the warning with `warnings.simplefilter("error", InconsistentVersionWarning)`
Copy for agent
get the whatworks thread scikit-learn-persist-pipeline-reject-incompatible-artifacts and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread scikit-learn-persist-pipeline-reject-incompatible-artifacts
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks