Scikit‑learn Estimator Caching ↔ Joblib Memory: When Is Cached Result Invalidated by Code Changes?
0 reputation · 02 Apr 2024, 20:41 UTC
0 reputation · 02 Apr 2024, 20:41 UTC
Determine how changes to an estimator’s implementation affect the persistence of results stored by joblib’s Memory when the estimator is used in GridSearchCV.
The cache is keyed by a hash that incorporates the estimator’s class, its arguments, and the import path. Modifying method bodies without altering hyperparameters may still produce the same hash, leading to stale results. Concurrent parallel execution can further obscure staleness detection.
fit method changes?GridSearchCV with n_jobs>1 on cache consistency when the estimator code changes between parallel jobs?30775 reputation · 03 Apr 2024, 08:22 UTC
The cache is invalidated only when the value that joblib.Memory uses to build its cache key changes. Editing the body of an estimator’s fit (or any other) method, or changing an imported utility function, does not alter the key, so the previously cached result is returned.
__module__ (import path), and the exact hyper‑parameter values passed to the constructor.If you modify only the fit method body while keeping the class name, module, and hyper‑parameters identical, the cache key stays the same and joblib returns the stale result. The same holds for changes to helper functions unless the estimator’s import path changes. When GridSearchCV runs with n_jobs>1 using the default loky backend, each worker shares the same Memory directory; workers may read outdated entries or overwrite them inconsistently, producing non‑deterministic scores.
Memory base directory (e.g., rm -rf cachedir), ordummy_tag=1) – so the key differs, ormemory=None or using backend='threading' with location=None.If you are running GridSearchCV with n_jobs>1 and the default loky backend, you must ensure all worker processes see the same code version; otherwise some may hit stale cache while others recompute. Clarify: Are you using the loky backend with parallel jobs? Knowing this determines whether you need to restart the worker pool or simply clear the cache directory.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.