scikit-learn "InconsistentVersionWarning" unpickling a model in CI
scikit-learn detected that a pickled estimator was created with a different library version than the one loading it. It emits InconsistentVersionWarning, and the internal layout may not be compatible, leading to wrong results or later errors.
What this error means
Loading a saved model in CI prints "InconsistentVersionWarning: Trying to unpickle estimator LogisticRegression from version 1.3.2 when using version 1.5.2." Tests that depend on the model then behave oddly or fail.
InconsistentVersionWarning: Trying to unpickle estimator LogisticRegression from
version 1.3.2 when using version 1.5.2. This might lead to breaking code or invalid
results. Use at your own risk.Common causes
The model artifact and CI scikit-learn differ
The pickle was produced under an older (or newer) scikit-learn than the version installed in CI, and the pickled attribute layout changed between them.
scikit-learn was upgraded without re-saving models
A dependency bump moved scikit-learn forward while committed/serialized models still reflect the old version.
How to fix it
Match the scikit-learn version that saved the model
- Read the "from version X" the warning reports.
- Pin scikit-learn in CI to that version, or regenerate the model under the current one.
- Re-run so loader and saver versions match.
pip install "scikit-learn==1.3.2"Retrain or re-export under the CI version
Regenerate the serialized model with the scikit-learn version CI uses so the formats agree, then commit/upload the fresh artifact.
import joblib
clf.fit(X_train, y_train)
joblib.dump(clf, "artifacts/model.joblib")How to prevent it
- Pin scikit-learn and store the version alongside the model artifact.
- Regenerate serialized models when bumping scikit-learn.
- Treat the warning as an error in CI to catch drift early.