Skip to content

add caching to .skb.apply - #2017

Merged
jeromedockes merged 45 commits into
skrub-data:mainfrom
jeromedockes:dataops-caching
Sep 22, 2026
Merged

jeromedockes merged 45 commits into
skrub-data:mainfrom
jeromedockes:dataops-caching

Conversation

@jeromedockes

@jeromedockes jeromedockes commented Apr 2, 2026 •

Copy link
Copy Markdown
Member

adds caching to estimators added with .skb.apply() and function calls added with deferred() or .skb.apply_func(). Caching is off by default and can be enabled with set_config(cache=True) or set_config(cache='/path/to/cache_dir'). For a given estimator or call, caching can be forbidden entirely in the pipeline definition e.g. X.skb.apply_func(f, no_cache=True) in which case the call is never cached regardless of configuration.

@jeromedockes jeromedockes added the data_ops Something related to the skrub DataOps label Apr 2, 2026
@jeromedockes

jeromedockes commented Apr 2, 2026 •

Copy link
Copy Markdown
Member Author
example script
import time

import skrub
from sklearn.datasets import make_classification
from sklearn.ensemble import HistGradientBoostingClassifier

skrub.set_config(cache=True)

X_a, y_a = make_classification(n_samples=50_000, n_features=50)
pred = skrub.X(X_a).skb.apply(HistGradientBoostingClassifier(), y=skrub.y(y_a))
split = pred.skb.train_test_split()
learner = pred.skb.make_learner()

tic = time.perf_counter()
learner.fit(split["train"])
toc = time.perf_counter()
print("first fit", toc - tic)

tic = time.perf_counter()
learner.fit(split["train"])
toc = time.perf_counter()
print("second fit", toc - tic)

tic = time.perf_counter()
result = learner.predict_proba(split["test"])
toc = time.perf_counter()
print("first predict", toc - tic)

tic = time.perf_counter()
result = learner.predict_proba(split["test"])
toc = time.perf_counter()
print("second predict", toc - tic)
first fit 0.28028534399345517
second fit 0.022888949999469332
first predict 0.014127899004961364
second predict 0.005811317008920014

@adrinjalali adrinjalali added this to Labs Apr 13, 2026
@adrinjalali adrinjalali moved this to In progress in Labs Apr 13, 2026
@jeromedockes jeromedockes moved this from In progress to Todo in Labs May 4, 2026
@jeremiedbb jeremiedbb moved this from Todo to Stalled in Labs Jun 29, 2026
@jeromedockes jeromedockes changed the title WIP add caching to .skb.apply add caching to .skb.apply Sep 11, 2026
@rcap107 rcap107 added this to the Release 0.11 milestone Sep 11, 2026
@jeromedockes

Copy link
Copy Markdown
Member Author

I tried a bit the caching on a realistic pipeline which I took from here:

https://github.com/probabl-ai/skore-example-electricity-load

running the cross-validation with a warm cache we see 10x speedup on the HGB pipeline and 42x on the TabICL one (that is re-running the exact same pipeline though). disclaimer: I didn't check the code that ran the experiments. on that pipeline only the final estimator is costly so caching doesn't help much for hyperparam search for example. with caching disabled the runtime was the same as on main, and on a cold cache the biggest overhead due to writing results was +13% (for the fastest pipeline, HGB + no quantile regression). the outputs were the same as those obtained from the main branch. the cache size did grow quickly, up to 2G, so providing guidance on how to handle that, and later tooling, will be important.

it would be interesting to do some similar experiments on a pipeline that does have expensive intermediate steps, e.g. a tablevectorizer with text

@jeromedockes
jeromedockes marked this pull request as draft September 14, 2026 11:22
@jeromedockes

Copy link
Copy Markdown
Member Author

irl we decided we need limiting of the cache size in this PR. I added one possible option but reverting to draft until we have settled on the api and I add the tests

@rcap107

rcap107 commented Sep 15, 2026

Copy link
Copy Markdown
Member

Do you think this PR will make it in the next release? 🤔

@jeromedockes

Copy link
Copy Markdown
Member Author

Do you think this PR will make it in the next release? 🤔

i think so 👍

@jeromedockes
jeromedockes marked this pull request as ready for review September 15, 2026 08:35
@jeromedockes
jeromedockes marked this pull request as draft September 15, 2026 08:46
@jeromedockes
jeromedockes marked this pull request as ready for review September 15, 2026 14:48
@rcap107
rcap107 dismissed their stale review September 17, 2026 08:01

new changes need new review

@rcap107 rcap107 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, the cache pruning change looks like a fairly light addition overall

@jeromedockes

Copy link
Copy Markdown
Member Author

cool, thanks for reviewing!

@jeromedockes
jeromedockes merged commit 2926a34 into skrub-data:main Sep 22, 2026
29 checks passed
@github-project-automation github-project-automation Bot moved this from PR Stalled to Done in Labs Sep 22, 2026
@GaelVaroquaux

GaelVaroquaux commented Sep 22, 2026 via email

Copy link
Copy Markdown
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

data_ops Something related to the skrub DataOps enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants