Skips transformer blocks on the sampling steps that barely change the image, for DiT checkpoints
(Flux, Chroma, and anything else built the same way) in
Forge Classic, branch neo.
This is the "First Block Cache" idea, the same family as TeaCache but without per-model polynomial coefficients: the first of the transformer blocks always runs, and when the relative change of its residual against the previous step falls below a threshold, the remaining blocks are skipped and the cached total residual is reused. Deciding costs one block out of 57 on Flux, about 2%.
Extensions tab, "Install from URL", paste the URL of this repository. Restart the webui.
Open the "Block Cache" accordion in txt2img or img2img and enable it.
| Setting | Meaning |
|---|---|
| Threshold | higher skips more: faster, less detail. 0 disables |
| Uncached starting steps | always compute this many steps first |
| Max consecutive cached steps | stop the cache from running away, 0 = no limit |
| Never cache the last step | keeps the final refinement |
The settings are written into the infotext.
GTX 1070, 512x768, 20 steps, Euler/Beta, same seed.
| Checkpoint | Off | Threshold 0.06 | 0.08 | 0.12 |
|---|---|---|---|---|
| Flux.1-dev NF4 | 3:57 | 3:03 | 2:19 | |
| Flux.1-dev Q4_0 | 3:38 | 2:53 | 2:14 | |
| Chroma1-HD Q4_0 | 9:31 | 7:00 | 4:04 |
On Flux, 0.08 is nearly indistinguishable from no caching and 0.12 keeps the composition, the face and the hands while losing fine texture. Chroma tolerates much less: 0.06 is safe, 0.12 already softens the image and merges fingers. Above roughly 0.2 the picture becomes a different one, so that is not a speed setting.
Nothing is skipped below about ten steps, the steps are simply too different, so distilled models such as Z-Image-Turbo gain nothing.
No backend file is patched and no model forward is copied. The extension uses the block-replacement hook that Forge Classic already exposes for ControlNet, plus one forward-pre-hook on the final layer. With no step skipped the image is bit-identical to stock, which is checked by generating with the threshold set so low that nothing can be cached.
Note for anyone reading the code: the blocks update the hidden state in place (img += ...), so the
block input and output are copied before anything downstream writes into that storage. Without those
copies the indicator is identically zero and every step gets skipped.
DenOfEquity/sd-forge-blockcache implements First Block Cache and TeaCache for upstream Forge, covering SD1.5, SDXL, SD3, Flux and Chroma. It is the more complete extension; this one is a small single-purpose alternative for Forge Classic.