SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2509.23094 · ICLR · 2025

d2Cache: Accelerating Diffusion-Based LLMs via Dual Adaptive Caching

Jiarui Wang, Xu Yang, Chonghan Liu, Yuchu Jiang, Yue Cai, Xiangzhong Luo, Jiale Fu

arXiv · PDF · Open in the Atlas

Code that ran

5 of 12 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (3 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 5 have no contract verdict; 0 failures of our instrument; 7 no recorded run), measured 2026-11-24; 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/2509.23094.json · badge: /api/ran/2509.23094.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
Kamichanw/d2Cache community
Papers with Code archive
5 ran · 7 no recorded run
FunctionStatusWhere it lives
AttentionContext Ran
ran on a synthesized input · constructed an object; no result was computed
Kamichanw/d2Cache/src/cache/d2cache.py
code served (permissive licence) · get_code("49671aa8f15515e6")
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 an instance of its own class, AttentionContext: the run constructed the object and did not call it, so no result was computed. 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
from dataclasses import dataclass

torch.manual_seed(0)

# Build tiny tensors for attention components
batch_size = 2
query_length = 3
key_value_length = 4
embed_dim = 5

q = torch.randn(batch_size, query_length, embed_dim)
k = torch.randn(batch_size, key_value_length, embed_dim)
v = torch.randn(batch_size, key_value_length, embed_dim)
o = torch.randn(batch_size, query_length, embed_dim)

# Create attention weights (B, num_heads, Q, K)
attn_weights = torch.randn(batch_size, 1, query_length, key_value_length)

# Create boolean attention mask (B, K) - True means keep, False means mask out
attention_mask = torch.tensor([
    [True, True, True, False],
    [True, True, False, False]
])

ARGS = {
    "q": q,
    "k": k,
    "v": v,
    "o": o,
    "attn_weights": attn_weights,
    "attention_mask": attention_mask,
}
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 AttentionContext — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a AttentionContext 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
FFNContext Ran
ran on a synthesized input · constructed an object; no result was computed
Kamichanw/d2Cache/src/cache/d2cache.py
code served (permissive licence) · get_code("22adcb99c43049e1")
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 an instance of its own class, FFNContext: the run constructed the object and did not call it, so no result was computed. 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
from dataclasses import dataclass

torch.manual_seed(0)

@dataclass
class FFNContext:
    hidden_states: torch.Tensor
    ffn_out: torch.Tensor | None = None

# Create tiny tensors with distinct dimensions
hidden_states = torch.randn(2, 4)  # batch_size=2, hidden_dim=4
ffn_out = torch.randn(2, 3)  # batch_size=2, output_dim=3

ARGS = {
    "hidden_states": hidden_states,
    "ffn_out": ffn_out,
}
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 FFNContext — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a FFNContext 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
ModelForwardContext Ran
ran on a synthesized input · constructed an object; no result was computed
Kamichanw/d2Cache/src/cache/d2cache.py
code served (permissive licence) · get_code("575b6522a18ff3da")
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 an instance of its own class, ModelForwardContext: the run constructed the object and did not call it, so no result was computed. 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
from dataclasses import dataclass

torch.manual_seed(0)

@dataclass
class ModelForwardContext:
    input_embeds: torch.Tensor
    position_ids: torch.Tensor | None = None
    attention_mask: torch.Tensor | None = None
    logits: torch.Tensor | None = None

ARGS = {
    "input_embeds": torch.randn(2, 5, 4),
    "position_ids": torch.arange(5).unsqueeze(0).expand(2, -1),
    "attention_mask": torch.ones(2, 5),
    "logits": torch.randn(2, 5, 8),
}
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 ModelForwardContext — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a ModelForwardContext 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
NoCacheLayer Ran
ran on a synthesized input
Kamichanw/d2Cache/src/cache/d2cache.py
code served (permissive licence) · get_code("b80e919026d191eb")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) and returned tuple, ndim 4, dtype family float; no output shape is stated. The image it ran in was 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
from transformers.cache_utils import Cache, CacheLayerMixin, StaticLayer
from typing import Any

class NoCacheLayer(CacheLayerMixin):
    """
    A dummy cache layer that does not cache anything, used for class dCache.
    """

    def lazy_initialization(self, key_states: torch.Tensor):
        ...

    def get_mask_sizes(self, cache_position: torch.Tensor) -> tuple[int, int]:
        return (0, 0)

    def get_seq_length(self) -> int:
        return 0

    def get_max_cache_shape(self) -> int:
        return -1

    def update(self, key_states: torch.Tensor, value_states: torch.Tensor, cache_kwargs: dict[str, Any] | None=None) -> tuple[torch.Tensor, torch.Tensor]:
        return (key_states, value_states)


INIT_ARGS = {}

ARGS = {
    "key_states": torch.randn(2, 4, 8),
    "value_states": torch.randn(2, 4, 8),
    "cache_kwargs": None,
}

METHOD = "update"

if __name__ == "__main__":
    instance = NoCacheLayer(**INIT_ARGS)
    result = getattr(instance, METHOD)(**ARGS)
    print("Result:", result)
    print("Key states shape:", result[0].shape)
    print("Value states shape:", result[1].shape)
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
Imports
torch, transformers — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple, ndim 4, 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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
StaticdCacheLayer Ran
ran on a synthesized input
Kamichanw/d2Cache/src/cache/d2cache.py
code served (permissive licence) · get_code("a064fc2c1b259625")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) and returned tuple, ndim 5, dtype family float; no output shape is stated. The image it ran in was 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
from transformers.cache_utils import StaticLayer
from typing import Any

class StaticdCacheLayer(StaticLayer):

    def __init__(self):
        super().__init__(max_cache_len=-1)

    def update(self, key_states: torch.Tensor, value_states: torch.Tensor, cache_kwargs: dict[str, Any] | None=None) -> tuple[torch.Tensor, torch.Tensor]:
        """
        Update the key and value caches in-place, and return the necessary keys and value states.

        Args:
            key_states (`torch.Tensor`): The new key states to cache.
            value_states (`torch.Tensor`): The new value states to cache.
            cache_kwargs (`dict[str, Any]`, *optional*): Additional arguments for the cache.

        Returns:
            tuple[`torch.Tensor`, `torch.Tensor`]: The key and value states.
        """
        if not self.is_initialized:
            self.max_cache_len = key_states.size(2)
            self.lazy_initialization(key_states)
        active_rows = cache_kwargs.get('active_rows') if cache_kwargs is not None else None
        cache_position = cache_kwargs.get('cache_position') if cache_kwargs is not None else None
        if active_rows is None:
            active_rows = torch.arange(key_states.size(0), device=key_states.device)
        if cache_position is None:
            cache_position = torch.arange(key_states.size(-2), device=key_states.device).unsqueeze(0).repeat(active_rows.size(0), 1)
        assert self.keys is not None and self.values is not None
        row_indices = active_rows[:, None]
        self.keys[row_indices, :, cache_position, :] = key_states.transpose(1, 2)
        self.values[row_indices, :, cache_position, :] = value_states.transpose(1, 2)
        return (self.keys[active_rows], self.values[active_rows])


INIT_ARGS = {}

ARGS = {
    'key_states': torch.randn(2, 3, 4, 8),
    'value_states': torch.randn(2, 3, 4, 8),
    'cache_kwargs': {
        'active_rows': torch.tensor([0, 1]),
        'cache_position': torch.tensor([[0, 1, 2, 3], [0, 1, 2, 3]])
    }
}

METHOD = 'update'

if __name__ == '__main__':
    layer = StaticdCacheLayer(**INIT_ARGS)
    result = getattr(layer, METHOD)(**ARGS)
    print("Output shapes:")
    print(f"  keys: {result[0].shape}")
    print(f"  values: {result[1].shape}")
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
Imports
torch, transformers — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple, ndim 5, 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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
Base Not yet run
unverified (harvested, no recorded run)
Kamichanw/d2Cache/src/cache/d2cache.py
code served (permissive licence) · get_code("ff931134add5074b")
How it ran

no invocation recorded.

CacheState Not yet run
unverified (harvested, no recorded run)
Kamichanw/d2Cache/src/cache/d2cache.py
code served (permissive licence) · get_code("f4cd211e229df8af")
How it ran

no invocation recorded.

Frame Not yet run
unverified (harvested, no recorded run)
Kamichanw/d2Cache/src/cache/d2cache.py
code served (permissive licence) · get_code("3b0c8e7f730f57c6")
How it ran

no invocation recorded.

FrameDelta Not yet run
unverified (harvested, no recorded run)
Kamichanw/d2Cache/src/cache/d2cache.py
code served (permissive licence) · get_code("ecd24e4f5ae609e6")
How it ran

no invocation recorded.

Intermediate Not yet run
unverified (harvested, no recorded run)
Kamichanw/d2Cache/src/cache/d2cache.py
code served (permissive licence) · get_code("caa5fd4c0ce0ae89")
How it ran

no invocation recorded.

d2Cache Not yet run
unverified (harvested, no recorded run)
Kamichanw/d2Cache/src/cache/d2cache.py
code served (permissive licence) · get_code("f96213b13720aeb4")
How it ran

no invocation recorded.

dCache Not yet run
unverified (harvested, no recorded run)
Kamichanw/d2Cache/src/cache/d2cache.py
code served (permissive licence) · get_code("2e6d49b5482f94e1")
How it ran

no invocation recorded.

Also present in other papers' code

Of 12 samples lifted from this paper's linked repositories, 12 carry a function identity and 0 do not. Of the 12 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 12 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-based large language models (dLLMs), despite their promising performance, still suffer from inferior inference efficiency. This is because dLLMs rely on bidirectional attention and cannot directly benefit from the standard key-value (KV) cache as autoregressive models (ARMs) do. To tackle this issue, we introduce Dual aDaptive Cache (d 2 Cache), which is a training-free approximate KV cache framework for accelerating dLLM inference. d 2 Cache features a twostage fine-grained selection strategy to identify tokens and adaptively update their KV states at each decoding step, while caching the KV states of the remaining tokens for reuse. Furthermore, d 2 Cache naturally offers a more reliable decoding alternative, which can enable quasi left-to-right generation and mitigate premature overconfidence in tokens at the end of the sequence. Extensive experimental results on two representative dLLMs (i.e., LLaDA and Dream) demonstrate that d 2 Cache not only achieves substantial inference speedups, but also yields consistent improvements in generation quality. The code is available at https://github.com/Kamichanw/d2Cache.

For agents

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

get_harvested_code_for_paper("2509.23094")
get_code_for_paper("2509.23094")
have("2509.23094")

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

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

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

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

Connect an agent — have() is free.