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

# TeaCache Acceleration

> Configure TeaCache for temporal similarity-based diffusion acceleration.

> **Note**: This is one of several caching strategies in SGLang (Cache-DiT, TeaCache, Spectrum, plus exact conditioning reuse).
> For an overview of all caching options, see [caching](./caching-acceleration).

TeaCache (Temporal similarity-based caching) accelerates diffusion inference by detecting when consecutive denoising steps are similar enough to skip computation entirely.

## Overview

TeaCache works by:

1. Tracking the L1 distance between modulated inputs across consecutive timesteps
2. Accumulating the rescaled L1 distance over steps
3. When accumulated distance is below a threshold, reusing the cached residual
4. Using separate positive/negative caches for supported CFG model families

## How It Works

### L1 Distance Tracking

At each denoising step, TeaCache computes the relative L1 distance between the current and previous modulated inputs:

```text theme={null}
rel_l1 = |current - previous|.mean() / |previous|.mean()
```

This distance is then rescaled using polynomial coefficients and accumulated:

```text theme={null}
accumulated += poly(coefficients)(rel_l1)
```

### Cache Decision

* If `accumulated >= threshold`: Force computation, reset accumulator
* If `accumulated < threshold`: Skip computation, use cached residual

### CFG Support

For models that support CFG cache separation, TeaCache maintains separate caches for positive and negative branches:

* `previous_modulated_input` / `previous_residual` for positive branch
* `previous_modulated_input_negative` / `previous_residual_negative` for negative branch

Flux and Qwen do not separate CFG caches and do not implement TeaCache yet (see [Supported Models](#supported-models)).

## Configuration

TeaCache is configured via `TeaCacheParams` in the sampling parameters. Start from the matching model's calibrated parameters; this example changes the threshold for `Wan-AI/Wan2.1-T2V-1.3B-Diffusers` while preserving its coefficients and skip window:

```python Configuration theme={null}
from dataclasses import replace
from sglang.multimodal_gen.configs.sample.wan import WanT2V_1_3B_SamplingParams

params = replace(
    WanT2V_1_3B_SamplingParams().teacache_params,
    teacache_thresh=0.1,
)
sampling_params_kwargs = {"enable_teacache": True, "teacache_params": params}
```

`--enable-teacache` / `enable_teacache` use the model's built-in `TeaCacheParams`. To customize them from Python, pass `sampling_params_kwargs` to `DiffGenerator.generate()`.

### Parameters

<table>
  <colgroup>
    <col />

    <col />

    <col />
  </colgroup>

  <thead>
    <tr>
      <th>Parameter</th>
      <th>Type</th>
      <th>Description</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>`teacache_thresh`</td>
      <td>float</td>
      <td>Threshold for accumulated L1 distance. Higher = more caching, faster but potentially lower quality</td>
    </tr>

    <tr>
      <td>`coefficients`</td>
      <td>list\[float]</td>
      <td>Polynomial coefficients for L1 rescaling, highest power first (`c[0]*x**4 + c[1]*x**3 + c[2]*x**2 + c[3]*x + c[4]`). Model-specific tuning</td>
    </tr>

    <tr>
      <td>`start_skipping`</td>
      <td>int or float</td>
      <td>Steps before this always compute. A float is a fraction of the denoising steps; a negative int counts back from the end. Default `5`</td>
    </tr>

    <tr>
      <td>`end_skipping`</td>
      <td>int or float</td>
      <td>Skipping stops at this step (exclusive); same encoding as `start_skipping`. Default `-1`</td>
    </tr>
  </tbody>
</table>

### Model-Specific Configurations

Different models may have different optimal configurations. The coefficients are typically tuned per-model to balance speed and quality.

## Supported Models

TeaCache support status by model family:

<table>
  <colgroup>
    <col />

    <col />

    <col />
  </colgroup>

  <thead>
    <tr>
      <th>Model Family</th>
      <th>CFG Cache Separation</th>
      <th>Notes</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>Wan2.1</td>
      <td>Yes</td>
      <td>Full support</td>
    </tr>

    <tr>
      <td>Wan2.2</td>
      <td>Yes</td>
      <td>Coefficients are not calibrated yet; enabling TeaCache is accepted but currently no-ops</td>
    </tr>

    <tr>
      <td>Z-Image</td>
      <td>—</td>
      <td>Not wired yet; `--enable-teacache` is accepted but currently no-ops</td>
    </tr>

    <tr>
      <td>HunyuanVideo</td>
      <td>No</td>
      <td>Not supported yet</td>
    </tr>

    <tr>
      <td>Flux</td>
      <td>No</td>
      <td>To be supported</td>
    </tr>

    <tr>
      <td>Qwen</td>
      <td>No</td>
      <td>To be supported</td>
    </tr>
  </tbody>
</table>

## References

* [TeaCache: Accelerating Diffusion Models with Temporal Similarity](https://arxiv.org/abs/2411.14324)


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