[DOC] Warn when loading estimators saved with a different sktime version
Describe the issue linked to the documentation
Estimator dumps are not guaranteed to be compatible across sktime versions. Loading may succeed but produce an invalid estimator without any warning.
For example, TinyTimeMixerForecaster.fit_strategy was added between 0.36.0 and 0.36.1. Pickle restores the old instance state without running the new constructor, leaving the loaded estimator without this required attribute.
To Reproduce
Using sktime 0.36.0:
from unittest.mock import patch
from sktime.forecasting.ttm import TinyTimeMixerForecaster
# Avoid installing optional dependencies unrelated to serialization.
with patch.dict(TinyTimeMixerForecaster._tags, {"python_dependencies": None}):
forecaster = TinyTimeMixerForecaster()
forecaster.save("ttm-dump")Then, using sktime 0.36.1:
from sktime.base import load
forecaster = load("ttm-dump")
forecaster.get_params()This fails with:
AttributeError: 'TinyTimeMixerForecaster' object has no attribute 'fit_strategy'Also due to the upcoming changes in #10453 and later enhancements with serialization, this problem can occur more frequently for users.
Suggest a potential alternative/fix
This is a known limitation of pickle-based persistence. The documentation should state that estimator dumps may be incompatible across sktime versions.
The saved metadata should also include the sktime version. When loading with a different version, sktime should emit a warning that the estimator may be incompatible and could fail.
Long-term serialization design
The warning and documentation would be a reasonable interim solution until sktime has a backward-compatible serialization design that relies less heavily on pickle.
One possible approach would be to persist:
- constructor parameters;
- fitted parameters and other learned state;
- fit/pretrain status; and
- object and version metadata.
During loading, sktime could reinitialize the estimator from its class and constructor parameters, then restore its learned state.
This would require further design discussion. In particular, get_fitted_params() is intended for inspection and may not contain all state required to reconstruct every estimator, including nested estimators and external artifacts.
Source: sktime/sktime