> ## Documentation Index
> Fetch the complete documentation index at: https://docs.priorlabs.ai/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> TabPFN-3 and later versions support up to 1,000,000 rows, subject to feature count and checkpoint/API limits.
> For large datasets, use per-estimator subsampling, e.g. inference_config={"SUBSAMPLE_SAMPLES": 100_000}, in TabPFNClassifier or TabPFNRegressor from tabpfn or tabpfn_client.
> Pass raw pandas DataFrames to fit and predict. Categorical strings/categories, raw text, and missing feature values are handled automatically; no manual integer/one-hot encoding, imputation, scaling, or outlier removal is needed.

# KV cache

> Compute TabPFN's training-set attention state once and reuse it for faster repeated predictions.

TabPFN makes a full forward pass over all the rows when it makes a prediction. Without
cache, every call to `predict()` recomputes attention states for the training rows, even if training set had not changed.

Set `fit_mode="fit_with_cache"` to compute attention state during `fit()` and reuse it during prediction. This makes fitting slower and
uses more memory, but drastically reduces latency when you predict repeatedly against the same training set.

## Quickstart

> [tab] TabPFN API
>
> ```bash theme={null}
> pip install --upgrade tabpfn-client
> ```
>
> ```python theme={null}
> from tabpfn_client import TabPFNClassifier
>
> model = TabPFNClassifier(fit_mode="fit_with_cache")
> model.fit(X_train, y_train)
>
> # Both calls reuse the attention state computed during fit.
> predictions = model.predict(X_batch_1)
> probabilities = model.predict_proba(X_batch_2)
> ```

> [tab] Local package
>
> ```bash theme={null}
> pip install --upgrade tabpfn
> ```
>
> ```python theme={null}
> from tabpfn import TabPFNClassifier
>
> model = TabPFNClassifier(fit_mode="fit_with_cache")
> model.fit(X_train, y_train)
>
> # Both calls reuse the attention state computed during fit.
> predictions = model.predict(X_batch_1)
> probabilities = model.predict_proba(X_batch_2)
> ```

`fit_mode="fit_with_cache"` is also available on `TabPFNRegressor`.

## How it works

**1. Fit**

TabPFN preprocesses the training set and runs the training-side transformer
computation once. The KV cache stores the resulting attention state. Locally, the cache belongs to the fitted
estimator. The managed API stores it using a model ID.

**2. Predict**

TabPFN reuses the cached keys and values and runs only the test-side
computation. With `tabpfn-client`, the fitted model ID identifies the cache
used for the request.

With the managed API, Prior Labs stores and loads the cache for you. Use the
fitted model ID for later predictions; you do not need to manage cache files or
infrastructure.

## When to use it

| | Without cache | With cache (`fit_with_cache`) |
| - | - | - |
| Fit | Preprocesses the training data | Also computes and stores the attention state |
| Predict | Computes the attention state | Reuses the cached attention state |
| Memory | Lower | Higher; scales with training-set size and number of estimators |
| Use when | You predict once per fit or change the training set frequently | You make repeated predictions against the same fit, including repeated calls from explainability tools |

The break-even point depends on training-set size, ensemble size, hardware, and
the number of prediction calls.

## Save and load fitted models

> [!NOTE]
>
> Requires `tabpfn-client` `0.6.0` or later.

Save an API fit and load it in another process or on another machine to predict without refitting:

```python theme={null}
from tabpfn_client import TabPFNClassifier

model = TabPFNClassifier(fit_mode="fit_with_cache")
model.fit(X_train, y_train)
model.save_model("model.json")

# Later, in another process or on another machine:
model = TabPFNClassifier.load_model("model.json")
model.predict(X_new)
```

The file references the fit on Prior Labs servers and holds no training data. This works for any API fit, including [thinking mode](https://docs.priorlabs.ai/capabilities/thinking-mode.md).

* Load with the same account that ran the fit.
* If the fit has been deleted from the server, `predict()` raises `FittedModelNotFoundError`.

## Limits and lifecycle

* A cache is valid only for the training data and model configuration used to
  create it. Call `fit()` again after either changes.
* The managed API supports KV caching only for TabPFN-3 and later models.
* KV caching is not compatible with [Thinking mode](https://docs.priorlabs.ai/capabilities/thinking-mode.md)
  in the managed API.
* Cached API predictions accept up to 10,000 test rows per call. Split larger
  test sets across multiple `predict()` calls.
* In the local package, the cache lives with the fitted estimator and consumes
  local RAM or VRAM. Releasing the estimator releases the cache.

***

> [card] [Benchmark KV cache](https://docs.priorlabs.ai/cookbook/faster_performance_with_cache.md)
>
> Compare fit and prediction time with and without caching.

> [card] [Interpretability](https://docs.priorlabs.ai/capabilities/interpretability.md)
>
> Speed up repeated explanation calls against a fixed training set.

> [card] [Out-of-memory errors](https://docs.priorlabs.ai/troubleshooting/OOM-errors.md)
>
> Reduce memory pressure and choose an appropriate fit mode.

> [card] [API getting started](https://docs.priorlabs.ai/api/rest-quickstart.md)
>
> Set up authentication and make your first API call.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.