SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2510.05891 · ICCV · 2025

D 3 QE: Learning Discrete Distribution Discrepancy-aware Quantization Error for Autoregressive-Generated Image Detection

Yu Zheng, Jiwen Lu, Jie Zhou, Lei Chen, Wenzhao Zheng, Yueqi Duan, Bingyao Yu, Yanran Zhang

arXiv · PDF · Open in the Atlas

Code that ran

1 of 9 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 1 has no contract verdict; 0 failures of our instrument; 8 no recorded run), measured 2026-11-23; 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/2510.05891.json · badge: /api/ran/2510.05891.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
Zhangyr2022/D3QE community
Papers with Code archive
1 ran · 8 no recorded run
FunctionStatusWhere it lives
D3AT_blocks Ran
ran on a synthesized input
Zhangyr2022/D3QE/networks/D3QE.py
code served (permissive licence) · get_code("8956fb73d9f2b1f0")
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 Tensor, ndim 3, dtype family float, shape (2, 3, 4) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape 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 math

class D3AT_blocks(nn.Module):
    """Transformer block with frequency-aware attention bias."""

    def __init__(self, embed_dim, num_heads, ff_dim, dropout=0.1):
        super().__init__()
        assert embed_dim % num_heads == 0, 'embed_dim must be divisible by num_heads'
        self.num_heads = num_heads
        self.head_dim = embed_dim // num_heads
        self.scale = self.head_dim ** (-0.5)
        self.qkv = nn.Linear(embed_dim, embed_dim * 3)
        self.freq_proj = nn.Sequential(nn.Linear(1, embed_dim), nn.LayerNorm(embed_dim), nn.GELU(), nn.Linear(embed_dim, embed_dim))
        self.out_proj = nn.Linear(embed_dim, embed_dim)
        self.dropout = nn.Dropout(dropout)
        self.attn_dropout = nn.Dropout(dropout)
        self.norm1 = nn.LayerNorm(embed_dim)
        self.norm2 = nn.LayerNorm(embed_dim)
        self.mlp = nn.Sequential(nn.Linear(embed_dim, ff_dim), nn.GELU(), nn.Dropout(dropout), nn.Linear(ff_dim, embed_dim), nn.Dropout(dropout))
        self.freq_scale = nn.Parameter(torch.ones(1) * 0.1)
        self._reset_parameters()
        self.W_q = nn.Linear(self.head_dim, self.head_dim)
        self.W_k = nn.Linear(self.head_dim, self.head_dim)

    def _reset_parameters(self):
        """Specialized initialization for transformer components."""
        nn.init.ones_(self.freq_scale)
        if hasattr(self, 'qkv'):
            nn.init.xavier_uniform_(self.qkv.weight, gain=1 / math.sqrt(2))
            if self.qkv.bias is not None:
                nn.init.zeros_(self.qkv.bias)
        if hasattr(self, 'out_proj'):
            nn.init.xavier_uniform_(self.out_proj.weight)
            if self.out_proj.bias is not None:
                nn.init.zeros_(self.out_proj.bias)
        if hasattr(self, 'mlp'):
            for m in self.mlp.modules():
                if isinstance(m, nn.Linear):
                    nn.init.xavier_uniform_(m.weight)
                    if m.bias is not None:
                        nn.init.zeros_(m.bias)

    def forward(self, x, freq_diff):
        """
        Args:
            x: [B, L, C]
            freq_diff: [B, L]
        """
        shortcut = x
        x = self.norm1(x)
        B, L, C = x.shape
        qkv = self.qkv(x).reshape(B, L, 3, self.num_heads, self.head_dim)
        qkv = qkv.permute(2, 0, 3, 1, 4)
        q, k, v = (qkv[0], qkv[1], qkv[2])
        freq_bias = self.freq_proj(freq_diff.unsqueeze(-1))
        freq_bias = freq_bias.view(B, L, self.num_heads, self.head_dim).permute(0, 2, 1, 3)
        query_bias = self.W_q(freq_bias)
        key_bias = self.W_k(freq_bias)
        freq_attn_bias = query_bias @ key_bias.transpose(-2, -1)
        attn = q @ k.transpose(-2, -1) * self.scale
        attn = attn + self.freq_scale * freq_attn_bias
        attn = torch.nn.functional.softmax(attn, dim=-1)
        attn = self.attn_dropout(attn)
        x = (attn @ v).transpose(1, 2).reshape(B, L, C)
        x = self.out_proj(x)
        x = self.dropout(x)
        x = shortcut + x
        x = x + self.mlp(self.norm2(x))
        return x


INIT_ARGS = {
    'embed_dim': 4,
    'num_heads': 2,
    'ff_dim': 8,
    'dropout': 0.1,
}

ARGS = {
    'x': torch.randn(2, 3, 4),
    'freq_diff': torch.randn(2, 3),
}

if __name__ == '__main__':
    model = D3AT_blocks(**INIT_ARGS)
    output = model(**ARGS)
    print(f"Output shape: {output.shape}")
    print(f"Expected shape: {ARGS['x'].shape}")
    assert output.shape == ARGS['x'].shape, "Output shape mismatch"
    print("Success!")
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 3, dtype family float, shape (2, 3, 4) — shape (2, 3, 4) as a later run recorded it
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)
D3AT Not yet run
unverified (harvested, no recorded run)
Zhangyr2022/D3QE/networks/D3QE.py
code served (permissive licence) · get_code("2574ded8c9d04a2c")
How it ran

no invocation recorded.

D3QE Not yet run
unverified (harvested, no recorded run)
Zhangyr2022/D3QE/networks/D3QE.py
code served (permissive licence) · get_code("bff7ee3e5d66e990")
How it ran

no invocation recorded.

Decoder Not yet run
unverified (harvested, no recorded run)
Zhangyr2022/D3QE/networks/D3QE.py
code served (permissive licence) · get_code("7733d9430848cc42")
How it ran

no invocation recorded.

VQModel Not yet run
unverified (harvested, no recorded run)
Zhangyr2022/D3QE/networks/D3QE.py
code served (permissive licence) · get_code("56bf8875ca993a19")
How it ran

no invocation recorded.

VQ_16 Not yet run
unverified (harvested, no recorded run)
Zhangyr2022/D3QE/networks/D3QE.py
code served (permissive licence) · get_code("5ce4f6c78836aad6")
How it ran

no invocation recorded.

VQ_8 Not yet run
unverified (harvested, no recorded run)
Zhangyr2022/D3QE/networks/D3QE.py
code served (permissive licence) · get_code("21b2fde2a69b2632")
How it ran

no invocation recorded.

VectorQuantizer Not yet run
unverified (harvested, no recorded run)
Zhangyr2022/D3QE/networks/D3QE.py
code served (permissive licence) · get_code("e11ea5361acefa3a")
How it ran

no invocation recorded.

init_weights Not yet run
unverified (harvested, no recorded run)
Zhangyr2022/D3QE/networks/D3QE.py
code served (permissive licence) · get_code("dc5ac4cc6033ca57")
How it ran

no invocation recorded.

Also present in other papers' code

Of 9 samples lifted from this paper's linked repositories, 9 carry a function identity and 0 do not. Of the 9 distinct functions with an identity, 1 are also present in other papers whose code we hold (1 with at least one paper dated earlier, 0 the same month, 0 later) and 8 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.

FunctionAlso present inEarliest-datedOthers named
Decoder
brick of this paper's assembly: helper
2 other papers
2 dated earlier
2505.17022 (2025-05)
GOT-R1: UNLEASHING REASONING CAPABILITY OF AUTOREGRESSIVE VISUAL GENERATION WITH REIN-FORCEMENT LEARNING
2507.02358 (2025-07)
Holistic Tokenizer for Autoregressive Image Generation

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-23.

Repositories linked to this paper

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

Abstract

The emergence of visual autoregressive (AR) models has revolutionized image generation while presenting new challenges for synthetic image detection. Unlike previous GAN or diffusion-based methods, AR models generate images through discrete token prediction, exhibiting both marked improvements in image synthesis quality and unique characteristics in their vector-quantized representations. In this paper, we propose to leverage Discrete Distribution Discrepancy-aware Quantization Error (D 3 QE) for autoregressive-generated image detection that exploits the distinctive patterns and the frequency distribution bias of the codebook existing in real and fake images. We introduce a discrete distribution discrepancyaware transformer that integrates dynamic codebook frequency statistics into its attention mechanism, fusing semantic features and quantization error latent. To evaluate our method, we construct a comprehensive dataset termed ARForensics covering 7 mainstream visual AR models. Experiments demonstrate superior detection accuracy and strong generalization of D 3 QE across different AR models, with robustness to real-world perturbations. Code is available at https://github.com/Zhangyr2022/D3QE.

For agents

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

get_harvested_code_for_paper("2510.05891")
get_code_for_paper("2510.05891")
have("2510.05891")

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

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

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

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

Connect an agent — have() is free.