SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2209.05687 · 2022

PSAQ-ViT V2: Towards Accurate and General Data-Free Quantization for Vision Transformers

arXiv · PDF · Open in the Atlas

Code that ran

5 of 8 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; 1 honoured the contract we drafted, 0 violated it and 0 have no contract verdict; 4 failures of our instrument; 3 no recorded run), measured 2026-11-23; 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/2209.05687.json · badge: /api/ran/2209.05687.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
zkkli/psaq-vit canonical (classifier label)
classifier basis: classifier_2025
4 ran · 3 no recorded run
copy not recorded community
not in the paper's declared repositories
1 ran · 0 no recorded run
FunctionStatusWhere it lives
accuracy Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
this paper's copy was not recorded; identical code first harvested from ChristophReich1996/Semantic_Pyramid_for_Image_Generation
pointer only · get_code("18badd533b52adb3")
How it ran

The body of this sample is withheld: this paper's copy of the code was not recorded (its link names no repository or source path), so no licence was read for it. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

attention_forward Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
zkkli/psaq-vit/utils/build_model.py
code served (permissive licence) · get_code("3bf709271b1e8d32")
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 Tensor, ndim 3, dtype family float, shape (2, 4, 8) 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

torch.manual_seed(0)

# Build a minimal Attention module that has all the attributes used in attention_forward
class MinimalAttention(nn.Module):
    def __init__(self, dim, num_heads, attn_drop=0.0, proj_drop=0.0):
        super().__init__()
        self.num_heads = num_heads
        self.dim = dim
        self.scale = (dim // num_heads) ** -0.5
        
        # Linear projection for q, k, v
        self.qkv = nn.Linear(dim, dim * 3)
        
        # Dropout layers
        self.attn_drop = nn.Dropout(attn_drop)
        self.proj_drop = nn.Dropout(proj_drop)
        
        # Output projection
        self.proj = nn.Linear(dim, dim)
        
        # Matrix multiplication operations (identity-like)
        self.matmul1 = torch.matmul
        self.matmul2 = torch.matmul
    
    def forward(self, x):
        B, N, C = x.shape
        qkv = self.qkv(x).reshape(B, N, 3, self.num_heads, C // self.num_heads).permute(2, 0, 3, 1, 4)
        q, k, v = qkv.unbind(0)
        attn = self.matmul1(q, k.transpose(-2, -1)) * self.scale
        attn = attn.softmax(dim=-1)
        attn = self.attn_drop(attn)
        del q, k
        x = self.matmul2(attn, v).transpose(1, 2).reshape(B, N, C)
        del attn, v
        x = self.proj(x)
        x = self.proj_drop(x)
        return x

# Create the attention module
dim = 8
num_heads = 2
attention_module = MinimalAttention(dim=dim, num_heads=num_heads, attn_drop=0.1, proj_drop=0.1)

# Create input tensor: (batch_size=2, num_tokens=4, dim=8)
x = torch.randn(2, 4, 8)

# Build ARGS dictionary
ARGS = {
    'self': attention_module,
    'x': x
}
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 Tensor, ndim 3, dtype family float, shape (2, 4, 8) — shape (2, 4, 8) 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: none by the harness; any seed is in the setup block
str2model Ran
ran; our contract draft was wrong, not the code
zkkli/psaq-vit/test_quant.py
code served (permissive licence) · get_code("3e69f59a60befe42")
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 function. 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 Vision Transformer models - we just need them to be callable
class MockDeiT(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 4)
    
    def forward(self, x):
        return self.linear(x)

class MockSwin(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 4)
    
    def forward(self, x):
        return self.linear(x)

# Create mock model functions with __name__ attributes
def deit_tiny_patch16_224():
    return MockDeiT()

def deit_small_patch16_224():
    return MockDeiT()

def deit_base_patch16_224():
    return MockDeiT()

def swin_tiny_patch4_window7_224():
    return MockSwin()

def swin_small_patch4_window7_224():
    return MockSwin()

# Add __name__ attributes to the functions
deit_tiny_patch16_224.__name__ = 'deit_tiny_patch16_224'
deit_small_patch16_224.__name__ = 'deit_small_patch16_224'
deit_base_patch16_224.__name__ = 'deit_base_patch16_224'
swin_tiny_patch4_window7_224.__name__ = 'swin_tiny_patch4_window7_224'
swin_small_patch4_window7_224.__name__ = 'swin_small_patch4_window7_224'

# Inject these into the function's scope by patching
import sys
module = sys.modules[__name__]
setattr(module, 'deit_tiny_patch16_224', deit_tiny_patch16_224)
setattr(module, 'deit_small_patch16_224', deit_small_patch16_224)
setattr(module, 'deit_base_patch16_224', deit_base_patch16_224)
setattr(module, 'swin_tiny_patch4_window7_224', swin_tiny_patch4_window7_224)
setattr(module, 'swin_small_patch4_window7_224', swin_small_patch4_window7_224)

ARGS = {
    'name': 'deit_tiny'
}
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 function — a function output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a function 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
validate Ran
ran, honoured the contract we drafted
zkkli/psaq-vit/test_quant.py
code served (permissive licence) · get_code("5132539cd8e7f9b0")
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. 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

torch.manual_seed(0)

# Create a minimal args object
class Args:
    def __init__(self):
        self.print_freq = 1

# Create a minimal model that takes input and outputs logits
class MinimalModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 10)
    
    def forward(self, x):
        return self.linear(x)

# Create a minimal val_loader (list of batches with data and target)
val_loader = [
    (torch.randn(2, 4), torch.tensor([0, 3])),
    (torch.randn(2, 4), torch.tensor([5, 7])),
]

# Create model and criterion
model = MinimalModel()
criterion = nn.CrossEntropyLoss()
device = 'cpu'

ARGS = {
    'args': Args(),
    'val_loader': val_loader,
    'model': model,
    'criterion': criterion,
    'device': device,
}
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
window_attention_forward Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
zkkli/psaq-vit/utils/build_model.py
code served (permissive licence) · get_code("0772c5bcc39fc675")
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 Tensor, ndim 3, dtype family float, shape (2, 4, 16) 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

torch.manual_seed(0)

class WindowAttention(nn.Module):
    def __init__(self, dim, window_size, num_heads):
        super().__init__()
        self.num_heads = num_heads
        self.window_size = window_size
        self.scale = (dim // num_heads) ** -0.5
        
        # Linear projections
        self.qkv = nn.Linear(dim, dim * 3)
        self.proj = nn.Linear(dim, dim)
        
        # Dropout layers
        self.attn_drop = nn.Dropout(0.0)
        self.proj_drop = nn.Dropout(0.0)
        
        # Softmax
        self.softmax = nn.Softmax(dim=-1)
        
        # Matrix multiplications (dummy operations)
        self.matmul1 = lambda q, k: torch.matmul(q, k)
        self.matmul2 = lambda attn, v: torch.matmul(attn, v)
        
        # Relative position bias
        window_h, window_w = window_size
        num_pos = (2 * window_h - 1) * (2 * window_w - 1)
        self.relative_position_bias_table = nn.Parameter(
            torch.randn(num_pos, num_heads)
        )
        
        # Relative position index
        coords_h = torch.arange(window_h)
        coords_w = torch.arange(window_w)
        coords = torch.stack(torch.meshgrid(coords_h, coords_w, indexing='ij'))
        coords_flatten = torch.flatten(coords, 1)
        relative_coords = coords_flatten[:, :, None] - coords_flatten[:, None, :]
        relative_coords = relative_coords.permute(1, 2, 0).contiguous()
        relative_coords[:, :, 0] += window_h - 1
        relative_coords[:, :, 1] += window_w - 1
        relative_coords[:, :, 0] *= 2 * window_w - 1
        relative_position_index = relative_coords.sum(-1)
        self.register_buffer('relative_position_index', relative_position_index)

# Create model
dim = 16
num_heads = 4
window_size = (2, 2)
model = WindowAttention(dim, window_size, num_heads)

# Create input tensor
# B_ = batch, N = num_patches (window_size[0] * window_size[1]), C = dim
B_ = 2
N = window_size[0] * window_size[1]  # 4
C = dim  # 16
x = torch.randn(B_, N, C)

# Create optional mask (used when masking is applied in windowed attention)
nW = 1
mask = None  # or torch.zeros(nW, N, N) for with-mask case

ARGS = {
    'self': model,
    'x': x,
    'mask': 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 Tensor, ndim 3, dtype family float, shape (2, 4, 16) — shape (2, 4, 16) 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: none by the harness; any seed is in the setup block
deit_base_patch16_224 Not yet run
unverified (harvested, no recorded run)
zkkli/psaq-vit/models/vit_quant.py
code served (permissive licence) · get_code("6648bb7d83d992ca")
How it ran

no invocation recorded.

deit_small_patch16_224 Not yet run
unverified (harvested, no recorded run)
zkkli/psaq-vit/models/vit_quant.py
code served (permissive licence) · get_code("4ad232e463484c01")
How it ran

no invocation recorded.

deit_tiny_patch16_224 Not yet run
unverified (harvested, no recorded run)
zkkli/psaq-vit/models/vit_quant.py
code served (permissive licence) · get_code("1af7645b46407155")
How it ran

no invocation recorded.

Also present in other papers' code

Of 8 samples lifted from this paper's linked repositories, 8 carry a function identity and 0 do not. Of the 8 distinct functions with an identity, 2 are also present in other papers whose code we hold (1 with at least one paper dated earlier, 0 the same month, 2 later) and 6 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
accuracy 19 other papers
5 dated earlier, 14 later
1805.08318 (2018-05)
Self-Attention Generative Adversarial Networks
2105.14148 (2021-05)
OpenMatch: Open-set Consistency Regularization for Semi-supervised Learning with Outliers
2110.03006 (2021-10)
Unsupervised Selective Labeling for More Effective Semi-Supervised Learning
and 16 more not named here
window_attention_forward 2 other papers
2 later
Li_RepQ-ViT_Scale_Reparameterization_for_Post-Training_Quantization_of_Vision_Transformers_ICCV_2023_paper (2023 (year only))
RepQ-ViT: Scale Reparameterization for Post-Training Quantization of Vision Transformers
2411.13918 (2024-11)
Quantization without Tears

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

Data-free quantization can potentially address data privacy and security concerns in model compression, and thus has been widely investigated. Recently, PSAQ-ViT designs a relative value metric, patch similarity, to generate data from pre-trained vision transformers (ViTs), achieving the first attempt at data-free quantization for ViTs. In this paper, we propose PSAQ-ViT V2, a more accurate and general data-free quantization framework for ViTs, built on top of PSAQ-ViT. More specifically, following the patch similarity metric in PSAQ-ViT, we introduce an adaptive teacher-student strategy, which facilitates the constant cyclic evolution of the generated samples and the quantized model (student) in a competitive and interactive fashion under the supervision of the full-precision model (teacher), thus significantly improving the accuracy of the quantized model. Moreover, without the auxiliary category guidance, we employ the task- and model-independent prior information, making the general-purpose scheme compatible with a broad range of vision tasks and models. Extensive experiments are conducted on various models on image classification, object detection, and semantic segmentation tasks, and PSAQ-ViT V2, with the naive quantization strategy and without access to real-world data, consistently achieves competitive results, showing potential as a powerful baseline on data-free quantization for ViTs. For instance, with Swin-S as the (backbone) model, 8-bit quantization reaches 82.13 top-1 accuracy on ImageNet, 50.9 box AP and 44.1 mask AP on COCO, and 47.2 mIoU on ADE20K. We hope that accurate and general PSAQ-ViT V2 can serve as a potential and practice solution in real-world applications involving sensitive data. Code is released and merged at: https://github.com/zkkli/PSAQ-ViT.

For agents

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

get_harvested_code_for_paper("2209.05687")
get_code_for_paper("2209.05687")
have("2209.05687")

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

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

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

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

Connect an agent — have() is free.