SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2505.20353 · 2025

FastCache: Fast Caching for Diffusion Transformer Through Learnable Linear Approximation

arXiv · PDF · Open in the Atlas

Code that ran

4 of 10 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 4 have no contract verdict; 0 failures of our instrument; 6 no recorded run), measured 2026-11-24; repository links from the Papers with Code archive attributed under CC BY-SA, no affiliation; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2505.20353.json · badge: /api/ran/2505.20353.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
noakliu/fastcache-xdit canonical (classifier label)
classifier basis not recorded on the link
4 ran · 6 no recorded run
FunctionStatusWhere it lives
apply_cache_to_model Ran
ran on a synthesized input
noakliu/fastcache-xdit/benchmark/cache_execute.py
code served (permissive licence) · get_code("3b5cf7a687be6905")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned MinimalModel. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

torch.manual_seed(0)

# Mock the cache_modules_available flag and apply_cache_on_transformer function
# since they're referenced in the function body
import sys
from types import ModuleType

# Create mock cache modules
cache_modules_available = True

def apply_cache_on_transformer(transformer, rel_l1_thresh=0.05, return_hidden_states_first=False, num_steps=20, use_cache=True, motion_threshold=0.1):
    """Mock implementation of apply_cache_on_transformer"""
    pass

# Inject into current module for the function to access
sys.modules[__name__].cache_modules_available = cache_modules_available
sys.modules[__name__].apply_cache_on_transformer = apply_cache_on_transformer

# Build a minimal transformer model
class MinimalTransformer(nn.Module):
    def __init__(self):
        super().__init__()
        self.embedding = nn.Embedding(10, 4)
        self.layer = nn.Linear(4, 4)
    
    def forward(self, x):
        return self.layer(x)

class MinimalModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.transformer = MinimalTransformer()
    
    def forward(self, x):
        return self.transformer(x)

# Create model instance
model = MinimalModel()

# Define all arguments
ARGS = {
    'model': model,
    'cache_method': 'dynamic',
    'rel_l1_thresh': 0.05,
    'num_steps': 20,
    'motion_threshold': 0.1,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type MinimalModel — a MinimalModel output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a MinimalModel output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
get_model_for_method Ran
ran on a synthesized input
noakliu/fastcache-xdit/benchmark/fastcache_benchmark.py
code served (permissive licence) · get_code("e0f2e1a2e1c02fd8")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned tuple, ndim 1, dtype family float; no output shape is stated. The image it ran in was not recorded. The code mentions cuda, and the harness aliases cuda to the CPU for every sample; whether this run needed that is not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn
from unittest.mock import Mock, MagicMock

torch.manual_seed(0)

# Mock the cache module classes since they may not be available
class FBCachedTransformerBlocks(nn.Module):
    def __init__(self, blocks, single_transformer_blocks=None, transformer=None, rel_l1_thresh=0.05, return_hidden_states_first=False, num_steps=20):
        super().__init__()
        self.blocks = blocks
        self.single_blocks = single_transformer_blocks
        self.cnt = torch.tensor(0)
        self.use_cache = torch.tensor([0, 0])
    
    def forward(self, *args, **kwargs):
        return self.blocks(*args, **kwargs)

class TeaCachedTransformerBlocks(nn.Module):
    def __init__(self, blocks, single_transformer_blocks=None, transformer=None, rel_l1_thresh=0.05, return_hidden_states_first=False, num_steps=20):
        super().__init__()
        self.blocks = blocks
        self.single_blocks = single_transformer_blocks
        self.cnt = torch.tensor(0)
        self.use_cache = torch.tensor([0, 0])
    
    def forward(self, *args, **kwargs):
        return self.blocks(*args, **kwargs)

class FastCachedTransformerBlocks(nn.Module):
    def __init__(self, blocks, single_transformer_blocks=None, transformer=None, rel_l1_thresh=0.05, return_hidden_states_first=False, num_steps=20, motion_threshold=0.1):
        super().__init__()
        self.blocks = blocks
        self.single_blocks = single_transformer_blocks
        self.cnt = torch.tensor(0)
        self.use_cache = torch.tensor([0, 0])
    
    def forward(self, *args, **kwargs):
        return self.blocks(*args, **kwargs)

# Build minimal transformer block
class TransformerBlock(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 4)
    
    def forward(self, x):
        return self.linear(x)

# Build minimal transformer
class Transformer(nn.Module):
    def __init__(self):
        super().__init__()
        self.transformer_blocks = nn.ModuleList([TransformerBlock() for _ in range(2)])
        self.single_transformer_blocks = nn.ModuleList([TransformerBlock() for _ in range(2)])
    
    def forward(self, x):
        for block in self.transformer_blocks:
            x = block(x)
        return x

# Build minimal model
class MinimalModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.transformer = Transformer()
    
    def forward(self, x):
        return self.transformer(x)

# Build args object
class Args:
    def __init__(self, model_type='sd3', model='test-model', cache_ratio_threshold=0.05, motion_threshold=0.1, num_inference_steps=20):
        self.model_type = model_type
        self.model = model
        self.cache_ratio_threshold = cache_ratio_threshold
        self.motion_threshold = motion_threshold
        self.num_inference_steps = num_inference_steps

# Setup global flag
import sys
sys.modules['cache_modules'] = MagicMock()
cache_modules_available = True

# Create test instances
original_model = MinimalModel()
args = Args(model_type='sd3', model='test-model', cache_ratio_threshold=0.05, motion_threshold=0.1, num_inference_steps=20)

ARGS = {
    'args': args,
    'method': 'None',
    'original_model': original_model
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple, ndim 1, dtype family float — a tuple output has no array shape of its own; none is stated
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
run_inference Ran
ran on a synthesized input
noakliu/fastcache-xdit/benchmark/cache_execute.py
code served (permissive licence) · get_code("67fb4b8f0da79649")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned tuple. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn


# Create a mock model that accepts the parameters used in run_inference
class MockDiffusionModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 4)
    
    def forward(self, prompt, num_inference_steps, height, width, generator):
        # Mock implementation that returns a tensor
        torch.manual_seed(0)
        batch_size = 1
        channels = 3
        result_tensor = torch.randn(batch_size, channels, height, width)
        return result_tensor


# Create mock args object with required attributes
class MockArgs:
    def __init__(self):
        self.prompt = "a cat"
        self.num_inference_steps = 50
        self.height = 64
        self.width = 64


torch.manual_seed(0)

model = MockDiffusionModel()
args = MockArgs()
generator = torch.Generator()
generator.manual_seed(0)

ARGS = {
    "model": model,
    "args": args,
    "generator": generator
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple — a tuple output has no array shape of its own; none is stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
run_inference Ran
ran on a synthesized input
noakliu/fastcache-xdit/benchmark/video_cache_execute.py
code served (permissive licence) · get_code("f35b0e7e455b0508")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned tuple. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn
import time

torch.manual_seed(0)

class MockVideoModel(nn.Module):
    """Minimal mock video generation model"""
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 4)
    
    def forward(self, prompt, num_inference_steps, height, width, num_frames=None, generator=None):
        """Mock forward pass that returns a video tensor"""
        # Return a mock video tensor of shape (batch, frames, channels, height, width)
        if num_frames is None:
            num_frames = 8
        return torch.randn(1, num_frames, 3, height, width)

class MockArgs:
    """Minimal args object with required attributes"""
    def __init__(self, model_type='stepvideo'):
        self.model_type = model_type
        self.prompt = "A cat walking in the park"
        self.num_inference_steps = 20
        self.height = 480
        self.width = 640
        self.num_frames = 16

# Create instances
model = MockVideoModel()
args = MockArgs(model_type='stepvideo')
generator = torch.Generator()
generator.manual_seed(0)

ARGS = {
    'model': model,
    'args': args,
    'generator': generator
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple — a tuple output has no array shape of its own; none is stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
apply_cache Not yet run
unverified (harvested, no recorded run)
noakliu/fastcache-xdit/benchmark/fastcache_benchmark.py
code served (permissive licence) · get_code("a9a49a40764349d9")
How it ran

no invocation recorded.

apply_cache_to_model Not yet run
unverified (harvested, no recorded run)
noakliu/fastcache-xdit/benchmark/video_cache_execute.py
code served (permissive licence) · get_code("62df200d97c33d60")
How it ran

no invocation recorded.

load_baseline_model Not yet run
unverified (harvested, no recorded run)
noakliu/fastcache-xdit/benchmark/cache_execution_xfuser.py
code served (permissive licence) · get_code("dff9bc3fb36537fc")
How it ran

no invocation recorded.

load_fastcache_model Not yet run
unverified (harvested, no recorded run)
noakliu/fastcache-xdit/benchmark/cache_execution_xfuser.py
code served (permissive licence) · get_code("839fc04bcb78e1d6")
How it ran

no invocation recorded.

load_video_model Not yet run
unverified (harvested, no recorded run)
noakliu/fastcache-xdit/benchmark/video_cache_execute.py
code served (permissive licence) · get_code("d9dec598d26d6bba")
How it ran

no invocation recorded.

load_xfuser_cache_model Not yet run
unverified (harvested, no recorded run)
noakliu/fastcache-xdit/benchmark/cache_execution_xfuser.py
code served (permissive licence) · get_code("2d52c251f9bafe3b")
How it ran

no invocation recorded.

Also present in other papers' code

Of 10 samples lifted from this paper's linked repositories, 10 carry a function identity and 0 do not. Of the 10 distinct functions with an identity, 0 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 0 later) and 10 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-24.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

Diffusion Transformers (DiT) are powerful generative models but remain computationally intensive due to their iterative structure and deep transformer stacks. To alleviate this inefficiency, we propose \textbf{FastCache}, a hidden-state-level caching and compression framework that accelerates DiT inference by exploiting redundancy within the model's internal representations. FastCache introduces a dual strategy: (1) a spatial-aware token selection mechanism that adaptively filters redundant tokens based on hidden-state saliency, and (2) a transformer-level cache that reuses latent activations across timesteps when changes fall below a predefined threshold. These modules work jointly to reduce unnecessary computation while preserving generation fidelity through learnable linear approximation. Theoretical analysis shows that FastCache maintains bounded approximation error under a hypothesis-testing-based decision rule. Empirical evaluations across multiple DiT variants demonstrate substantial reductions in latency and memory usage, achieving the best generation quality among existing cache methods, as measured by FID and t-FID. To further improve the speedup of FastCache, we also introduce a token merging module that merges redundant tokens based on k-NN density. Code is available at \href{https://github.com/NoakLiu/FastCache-xDiT}{https://github.com/NoakLiu/FastCache-xDiT}.

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2505.20353")
get_code_for_paper("2505.20353")
have("2505.20353")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2505.20353.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2505.20353.svg)](https://syntology.ai/paper/2505.20353)

Connect an agent — have() is free.