Skip to main content
ByPrior Labs
Build the model’s internal representation once at fit time, reuse it at predict. By default TabPFN recomputes its representation of the training set on every call to predict. The fit_with_cache mode does that work once, during fit, and caches the result, so the first prediction is noticeably faster. This short notebook benchmarks the two modes side by side on the same data.

Setup

Installing TabPFN and scikit-learn.

Imports

The classifier, a dataset, and timing utilities.

Authenticating with a Token

Setting TABPFN_TOKEN so the weights can be downloaded.

Data and Split

A synthetic 5,000-row classification set; a small test slice keeps prediction quick.

The Benchmark Function

Timing fit and predict. benchmark_tabpfn fits, times the first prediction. The first prediction is where the cache pays off.

With and Without the Cache

Comparing default mode against fit_with_cache. The baseline recomputes the training representation at predict time. With fit_with_cache, that work happens during fit, so the first prediction is faster.

The Importance of Cache with Repeated predict Calls