SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2204.00993 · ECCV · 2022

Improving Vision Transformers by Revisiting High-frequency Components

Shu-Tao Xia, Jiawang Bai, Wei Liu, Zhifeng Li, Li Yuan, Shuicheng Yan

arXiv · PDF · Open in the Atlas

Code that ran

11 of 14 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 9 have no contract verdict; 2 failures of our instrument; 3 no recorded run), measured 2026-11-22; 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/2204.00993.json · badge: /api/ran/2204.00993.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
jiawangbai/HAT marked official in Papers with Code
Papers with Code archive
11 ran · 3 no recorded run
FunctionStatusWhere it lives
Attention Ran
ran on a synthesized input
jiawangbai/HAT/models/volo.py
code served (permissive licence) · get_code("758bd44a54df5709")
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 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
import torch.nn as nn

INIT_ARGS = {
    'dim': 4,
    'num_heads': 2,
    'qkv_bias': False,
    'qk_scale': None,
    'attn_drop': 0.0,
    'proj_drop': 0.0,
}

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

if __name__ == '__main__':
    attention = nn.Module()
    attention.__class__ = type('Attention', (nn.Module,), {
        '__init__': lambda self, dim, num_heads=8, qkv_bias=False, qk_scale=None, attn_drop=0.0, proj_drop=0.0: (
            nn.Module.__init__(self),
            setattr(self, 'num_heads', num_heads),
            setattr(self, 'scale', qk_scale or (dim // num_heads) ** (-0.5)),
            setattr(self, 'qkv', nn.Linear(dim, dim * 3, bias=qkv_bias)),
            setattr(self, 'attn_drop', nn.Dropout(attn_drop)),
            setattr(self, 'proj', nn.Linear(dim, dim)),
            setattr(self, 'proj_drop', nn.Dropout(proj_drop)),
        ),
        'forward': lambda self, x: (
            lambda B, H, W, C: (
                lambda qkv: (
                    lambda q, k, v: (
                        lambda attn: (
                            lambda attn: (
                                lambda x: self.proj_drop(self.proj(x))
                            )(self.attn_drop(attn) @ v).transpose(1, 2).reshape(B, H, W, C)
                        )(attn.softmax(dim=-1))
                    )(q @ k.transpose(-2, -1) * self.scale)
                )(qkv[0], qkv[1], qkv[2])
            )(self.qkv(x).reshape(B, H * W, 3, self.num_heads, C // self.num_heads).permute(2, 0, 3, 1, 4))
        )(*x.shape)
    })
    
    attn_module = attention.__class__(**INIT_ARGS)
    output = attn_module(**ARGS)
    print(f"Output shape: {output.shape}")
    print(f"Expected shape: {ARGS['x'].shape}")
    assert output.shape == ARGS['x'].shape, f"Shape mismatch: {output.shape} vs {ARGS['x'].shape}"
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 4, dtype family float — no output shape is stated: observe_signature.py observed this class with its constructor sizes canonicalised where it could, which the node does not record, so its shape is not stated as this setup block's
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)
ClassAttention Ran
ran on a synthesized input
jiawangbai/HAT/models/volo.py
code served (permissive licence) · get_code("d6aec4de1a988995")
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, 1, 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

INIT_ARGS = {
    'dim': 4,
    'num_heads': 2,
    'head_dim': None,
    'qkv_bias': False,
    'qk_scale': None,
    'attn_drop': 0.0,
    'proj_drop': 0.0,
}

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

class ClassAttention(nn.Module):
    """
    Class attention layer from CaiT, see details in CaiT
    Class attention is the post stage in our VOLO, which is optional.
    """

    def __init__(self, dim, num_heads=8, head_dim=None, qkv_bias=False, qk_scale=None, attn_drop=0.0, proj_drop=0.0):
        super().__init__()
        self.num_heads = num_heads
        if head_dim is not None:
            self.head_dim = head_dim
        else:
            head_dim = dim // num_heads
            self.head_dim = head_dim
        self.scale = qk_scale or head_dim ** (-0.5)
        self.kv = nn.Linear(dim, self.head_dim * self.num_heads * 2, bias=qkv_bias)
        self.q = nn.Linear(dim, self.head_dim * self.num_heads, bias=qkv_bias)
        self.attn_drop = nn.Dropout(attn_drop)
        self.proj = nn.Linear(self.head_dim * self.num_heads, dim)
        self.proj_drop = nn.Dropout(proj_drop)

    def forward(self, x):
        B, N, C = x.shape
        kv = self.kv(x).reshape(B, N, 2, self.num_heads, self.head_dim).permute(2, 0, 3, 1, 4)
        k, v = (kv[0], kv[1])
        q = self.q(x[:, :1, :]).reshape(B, self.num_heads, 1, self.head_dim)
        attn = q * self.scale @ k.transpose(-2, -1)
        attn = attn.softmax(dim=-1)
        attn = self.attn_drop(attn)
        cls_embed = (attn @ v).transpose(1, 2).reshape(B, 1, self.head_dim * self.num_heads)
        cls_embed = self.proj(cls_embed)
        cls_embed = self.proj_drop(cls_embed)
        return cls_embed


if __name__ == '__main__':
    model = ClassAttention(**INIT_ARGS)
    output = model(**ARGS)
    print(f"Output shape: {output.shape}")
    print(f"Expected shape: (2, 1, 4)")
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, 1, 4) — shape (2, 1, 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)
ClassBlock Ran
ran on a synthesized input
jiawangbai/HAT/models/volo.py
code served (permissive licence) · get_code("b10f308ac343586f")
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; 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
from timm.models.layers import DropPath

class ClassAttention(nn.Module):
    def __init__(self, dim, num_heads=8, head_dim=None, qkv_bias=False, qk_scale=None, attn_drop=0.0, proj_drop=0.0):
        super().__init__()
        self.num_heads = num_heads
        if head_dim is not None:
            self.head_dim = head_dim
        else:
            head_dim = dim // num_heads
            self.head_dim = head_dim
        self.scale = qk_scale or head_dim ** (-0.5)
        self.kv = nn.Linear(dim, self.head_dim * self.num_heads * 2, bias=qkv_bias)
        self.q = nn.Linear(dim, self.head_dim * self.num_heads, bias=qkv_bias)
        self.attn_drop = nn.Dropout(attn_drop)
        self.proj = nn.Linear(self.head_dim * self.num_heads, dim)
        self.proj_drop = nn.Dropout(proj_drop)

    def forward(self, x):
        B, N, C = x.shape
        kv = self.kv(x).reshape(B, N, 2, self.num_heads, self.head_dim).permute(2, 0, 3, 1, 4)
        k, v = (kv[0], kv[1])
        q = self.q(x[:, :1, :]).reshape(B, self.num_heads, 1, self.head_dim)
        attn = q * self.scale @ k.transpose(-2, -1)
        attn = attn.softmax(dim=-1)
        attn = self.attn_drop(attn)
        cls_embed = (attn @ v).transpose(1, 2).reshape(B, 1, self.head_dim * self.num_heads)
        cls_embed = self.proj(cls_embed)
        cls_embed = self.proj_drop(cls_embed)
        return cls_embed

class Mlp(nn.Module):
    def __init__(self, in_features, hidden_features=None, out_features=None, act_layer=nn.GELU, drop=0.0):
        super().__init__()
        out_features = out_features or in_features
        hidden_features = hidden_features or in_features
        self.fc1 = nn.Linear(in_features, hidden_features)
        self.act = act_layer()
        self.fc2 = nn.Linear(hidden_features, out_features)
        self.drop = nn.Dropout(drop)

    def forward(self, x):
        x = self.fc1(x)
        x = self.act(x)
        x = self.drop(x)
        x = self.fc2(x)
        x = self.drop(x)
        return x

class ClassBlock(nn.Module):
    def __init__(self, dim, num_heads, head_dim=None, mlp_ratio=4.0, qkv_bias=False, qk_scale=None, drop=0.0, attn_drop=0.0, drop_path=0.0, act_layer=nn.GELU, norm_layer=nn.LayerNorm):
        super().__init__()
        self.norm1 = norm_layer(dim)
        self.attn = ClassAttention(dim, num_heads=num_heads, head_dim=head_dim, qkv_bias=qkv_bias, qk_scale=qk_scale, attn_drop=attn_drop, proj_drop=drop)
        self.drop_path = DropPath(drop_path) if drop_path > 0.0 else nn.Identity()
        self.norm2 = norm_layer(dim)
        mlp_hidden_dim = int(dim * mlp_ratio)
        self.mlp = Mlp(in_features=dim, hidden_features=mlp_hidden_dim, act_layer=act_layer, drop=drop)

    def forward(self, x):
        cls_embed = x[:, :1]
        cls_embed = cls_embed + self.drop_path(self.attn(self.norm1(x)))
        cls_embed = cls_embed + self.drop_path(self.mlp(self.norm2(cls_embed)))
        return torch.cat([cls_embed, x[:, 1:]], dim=1)

INIT_ARGS = {
    'dim': 8,
    'num_heads': 2,
    'head_dim': 4,
    'mlp_ratio': 4.0,
    'qkv_bias': False,
    'qk_scale': None,
    'drop': 0.0,
    'attn_drop': 0.0,
    'drop_path': 0.1,
    'act_layer': nn.GELU,
    'norm_layer': nn.LayerNorm
}

ARGS = {
    'x': torch.randn(2, 5, 8)
}
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
Imports
timm, 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 — no output shape is stated: observe_signature.py observed this class with its constructor sizes canonicalised where it could, which the node does not record, so its shape is not stated as this setup block's
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)
Downsample Ran
ran on a synthesized input
jiawangbai/HAT/models/volo.py
code served (permissive licence) · get_code("33ecaec51f88c518")
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 4, dtype family float, shape (2, 8, 8, 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

INIT_ARGS = {
    'in_embed_dim': 4,
    'out_embed_dim': 8,
    'patch_size': 2,
}

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

if __name__ == '__main__':
    downsample = nn.Module.__new__(type('Downsample', (nn.Module,), {
        '__init__': lambda self, in_embed_dim, out_embed_dim, patch_size: (
            super(type(self), self).__init__(),
            setattr(self, 'proj', nn.Conv2d(in_embed_dim, out_embed_dim, kernel_size=patch_size, stride=patch_size))
        ),
        'forward': lambda self, x: (
            x.permute(0, 3, 1, 2),
            self.proj(x.permute(0, 3, 1, 2)),
            self.proj(x.permute(0, 3, 1, 2)).permute(0, 2, 3, 1)
        )[-1]
    }))(**INIT_ARGS)
    
    output = downsample(**ARGS)
    print(f"Output shape: {output.shape}")
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 4, dtype family float, shape (2, 8, 8, 8) — shape (2, 8, 8, 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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
Mlp Ran
ran on a synthesized input
jiawangbai/HAT/models/volo.py
code served (permissive licence) · get_code("f3cd14e6c18a60d8")
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 2, dtype family float, shape (2, 3) 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

INIT_ARGS = {
    'in_features': 4,
    'hidden_features': 8,
    'out_features': 3,
    'act_layer': nn.GELU,
    'drop': 0.1,
}

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

mlp = nn.Module()
mlp.__class__ = type('Mlp', (nn.Module,), {
    '__init__': lambda self, in_features, hidden_features=None, out_features=None, act_layer=nn.GELU, drop=0.0: (
        super(type(self), self).__init__(),
        setattr(self, 'fc1', nn.Linear(in_features, hidden_features or in_features)),
        setattr(self, 'act', act_layer()),
        setattr(self, 'fc2', nn.Linear(hidden_features or in_features, out_features or in_features)),
        setattr(self, 'drop', nn.Dropout(drop)),
    )[-1],
    'forward': lambda self, x: (
        self.drop(self.fc2(self.drop(self.act(self.fc1(x)))))
    ),
})

mlp = type('Mlp', (nn.Module,), {
    '__init__': lambda self, in_features, hidden_features=None, out_features=None, act_layer=nn.GELU, drop=0.0: (
        super(type(self), self).__init__(),
        setattr(self, 'fc1', nn.Linear(in_features, hidden_features or in_features)),
        setattr(self, 'act', act_layer()),
        setattr(self, 'fc2', nn.Linear(hidden_features or in_features, out_features or in_features)),
        setattr(self, 'drop', nn.Dropout(drop)),
    )[-1],
    'forward': lambda self, x: (
        self.drop(self.fc2(self.drop(self.act(self.fc1(x)))))
    ),
})(**INIT_ARGS)

output = mlp(**ARGS)
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 2, dtype family float, shape (2, 3) — shape (2, 3) 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)
OutlookAttention Ran
ran on a synthesized input
jiawangbai/HAT/models/volo.py
code served (permissive licence) · get_code("0b3e7de2ecb2c1e7")
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 4, dtype family float, shape (2, 4, 5, 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
import math

class OutlookAttention(nn.Module):
    """
    Implementation of outlook attention
    --dim: hidden dim
    --num_heads: number of heads
    --kernel_size: kernel size in each window for outlook attention
    return: token features after outlook attention
    """

    def __init__(self, dim, num_heads, kernel_size=3, padding=1, stride=1, qkv_bias=False, qk_scale=None, attn_drop=0.0, proj_drop=0.0):
        super().__init__()
        head_dim = dim // num_heads
        self.num_heads = num_heads
        self.kernel_size = kernel_size
        self.padding = padding
        self.stride = stride
        self.scale = qk_scale or head_dim ** (-0.5)
        self.v = nn.Linear(dim, dim, bias=qkv_bias)
        self.attn = nn.Linear(dim, kernel_size ** 4 * num_heads)
        self.attn_drop = nn.Dropout(attn_drop)
        self.proj = nn.Linear(dim, dim)
        self.proj_drop = nn.Dropout(proj_drop)
        self.unfold = nn.Unfold(kernel_size=kernel_size, padding=padding, stride=stride)
        self.pool = nn.AvgPool2d(kernel_size=stride, stride=stride, ceil_mode=True)

    def forward(self, x):
        B, H, W, C = x.shape
        v = self.v(x).permute(0, 3, 1, 2)
        h, w = (math.ceil(H / self.stride), math.ceil(W / self.stride))
        v = self.unfold(v).reshape(B, self.num_heads, C // self.num_heads, self.kernel_size * self.kernel_size, h * w).permute(0, 1, 4, 3, 2)
        attn = self.pool(x.permute(0, 3, 1, 2)).permute(0, 2, 3, 1)
        attn = self.attn(attn).reshape(B, h * w, self.num_heads, self.kernel_size * self.kernel_size, self.kernel_size * self.kernel_size).permute(0, 2, 1, 3, 4)
        attn = attn * self.scale
        attn = attn.softmax(dim=-1)
        attn = self.attn_drop(attn)
        x = (attn @ v).permute(0, 1, 4, 3, 2).reshape(B, C * self.kernel_size * self.kernel_size, h * w)
        x = torch.nn.functional.fold(x, output_size=(H, W), kernel_size=self.kernel_size, padding=self.padding, stride=self.stride)
        x = self.proj(x.permute(0, 2, 3, 1))
        x = self.proj_drop(x)
        return x


INIT_ARGS = {
    'dim': 8,
    'num_heads': 2,
    'kernel_size': 3,
    'padding': 1,
    'stride': 1,
    'qkv_bias': False,
    'qk_scale': None,
    'attn_drop': 0.0,
    'proj_drop': 0.0,
}

ARGS = {
    'x': torch.randn(2, 4, 5, 8),
}

if __name__ == '__main__':
    model = OutlookAttention(**INIT_ARGS)
    output = model(**ARGS)
    print(f"Output shape: {output.shape}")
    print(f"Output: {output}")
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 4, dtype family float, shape (2, 4, 5, 8) — shape (2, 4, 5, 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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
Outlooker Ran
ran on a synthesized input
jiawangbai/HAT/models/volo.py
code served (permissive licence) · get_code("a114b78025e6c55f")
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 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
import numpy as np
from timm.models.layers import DropPath

INIT_ARGS = {
    'dim': 4,
    'kernel_size': 3,
    'padding': 1,
    'stride': 1,
    'num_heads': 2,
    'mlp_ratio': 2.0,
    'attn_drop': 0.0,
    'drop_path': 0.1,
    'act_layer': torch.nn.GELU,
    'norm_layer': torch.nn.LayerNorm,
    'qkv_bias': False,
    'qk_scale': None
}

# Create input tensor with shape (batch_size, height, width, channels)
batch_size = 2
height = 4
width = 4
channels = INIT_ARGS['dim']

input_tensor = torch.randn(batch_size, height, width, channels)

ARGS = {
    'x': input_tensor
}
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
Imports
numpy, timm, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 4, dtype family float — no output shape is stated: observe_signature.py observed this class with its constructor sizes canonicalised where it could, which the node does not record, so its shape is not stated as this setup block's
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)
PatchEmbed Ran
ran on a synthesized input
jiawangbai/HAT/models/volo.py
code served (permissive licence) · get_code("53a133709900d494")
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 4, dtype family float, shape (2, 48, 8, 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

class PatchEmbed(nn.Module):
    """
    Image to Patch Embedding.
    Different with ViT use 1 conv layer, we use 4 conv layers to do patch embedding
    """

    def __init__(self, img_size=224, stem_conv=False, stem_stride=1, patch_size=8, in_chans=3, hidden_dim=64, embed_dim=384):
        super().__init__()
        assert patch_size in [4, 8, 16]
        self.stem_conv = stem_conv
        if stem_conv:
            self.conv = nn.Sequential(nn.Conv2d(in_chans, hidden_dim, kernel_size=7, stride=stem_stride, padding=3, bias=False), nn.BatchNorm2d(hidden_dim), nn.ReLU(inplace=True), nn.Conv2d(hidden_dim, hidden_dim, kernel_size=3, stride=1, padding=1, bias=False), nn.BatchNorm2d(hidden_dim), nn.ReLU(inplace=True), nn.Conv2d(hidden_dim, hidden_dim, kernel_size=3, stride=1, padding=1, bias=False), nn.BatchNorm2d(hidden_dim), nn.ReLU(inplace=True))
        self.proj = nn.Conv2d(hidden_dim, embed_dim, kernel_size=patch_size // stem_stride, stride=patch_size // stem_stride)
        self.num_patches = img_size // patch_size * (img_size // patch_size)

    def forward(self, x):
        if self.stem_conv:
            x = self.conv(x)
        x = self.proj(x)
        return x


INIT_ARGS = {
    'img_size': 64,
    'stem_conv': True,
    'stem_stride': 1,
    'patch_size': 8,
    'in_chans': 3,
    'hidden_dim': 32,
    'embed_dim': 48,
}

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

if __name__ == '__main__':
    model = PatchEmbed(**INIT_ARGS)
    output = model(**ARGS)
    print(f"Output shape: {output.shape}")
    print(f"Expected num_patches: {model.num_patches}")
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 4, dtype family float, shape (2, 48, 8, 8) — shape (2, 48, 8, 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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
Transformer Ran
ran on a synthesized input
jiawangbai/HAT/models/volo.py
code served (permissive licence) · get_code("f1380508396f9eb9")
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 4, dtype family float, shape (2, 3, 5, 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
from timm.models.layers import DropPath, to_2tuple, trunc_normal_

class Attention(nn.Module):
    """Implementation of self-attention"""

    def __init__(self, dim, num_heads=8, qkv_bias=False, qk_scale=None, attn_drop=0.0, proj_drop=0.0):
        super().__init__()
        self.num_heads = num_heads
        head_dim = dim // num_heads
        self.scale = qk_scale or head_dim ** (-0.5)
        self.qkv = nn.Linear(dim, dim * 3, bias=qkv_bias)
        self.attn_drop = nn.Dropout(attn_drop)
        self.proj = nn.Linear(dim, dim)
        self.proj_drop = nn.Dropout(proj_drop)

    def forward(self, x):
        B, H, W, C = x.shape
        qkv = self.qkv(x).reshape(B, H * W, 3, self.num_heads, C // self.num_heads).permute(2, 0, 3, 1, 4)
        q, k, v = (qkv[0], qkv[1], qkv[2])
        attn = q @ k.transpose(-2, -1) * self.scale
        attn = attn.softmax(dim=-1)
        attn = self.attn_drop(attn)
        x = (attn @ v).transpose(1, 2).reshape(B, H, W, C)
        x = self.proj(x)
        x = self.proj_drop(x)
        return x

class Mlp(nn.Module):
    """Implementation of MLP"""

    def __init__(self, in_features, hidden_features=None, out_features=None, act_layer=nn.GELU, drop=0.0):
        super().__init__()
        out_features = out_features or in_features
        hidden_features = hidden_features or in_features
        self.fc1 = nn.Linear(in_features, hidden_features)
        self.act = act_layer()
        self.fc2 = nn.Linear(hidden_features, out_features)
        self.drop = nn.Dropout(drop)

    def forward(self, x):
        x = self.fc1(x)
        x = self.act(x)
        x = self.drop(x)
        x = self.fc2(x)
        x = self.drop(x)
        return x

class Transformer(nn.Module):
    """
    Implementation of Transformer,
    Transformer is the second stage in our VOLO
    """

    def __init__(self, dim, num_heads, mlp_ratio=4.0, qkv_bias=False, qk_scale=None, attn_drop=0.0, drop_path=0.0, act_layer=nn.GELU, norm_layer=nn.LayerNorm):
        super().__init__()
        self.norm1 = norm_layer(dim)
        self.attn = Attention(dim, num_heads=num_heads, qkv_bias=qkv_bias, qk_scale=qk_scale, attn_drop=attn_drop)
        self.drop_path = DropPath(drop_path) if drop_path > 0.0 else nn.Identity()
        self.norm2 = norm_layer(dim)
        mlp_hidden_dim = int(dim * mlp_ratio)
        self.mlp = Mlp(in_features=dim, hidden_features=mlp_hidden_dim, act_layer=act_layer)

    def forward(self, x):
        x = x + self.drop_path(self.attn(self.norm1(x)))
        x = x + self.drop_path(self.mlp(self.norm2(x)))
        return x


INIT_ARGS = {
    'dim': 4,
    'num_heads': 2,
    'mlp_ratio': 4.0,
    'qkv_bias': False,
    'qk_scale': None,
    'attn_drop': 0.0,
    'drop_path': 0.0,
    'act_layer': nn.GELU,
    'norm_layer': nn.LayerNorm,
}

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

if __name__ == '__main__':
    model = Transformer(**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
timm, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 4, dtype family float, shape (2, 3, 5, 4) — shape (2, 3, 5, 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)
outlooker_blocks Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
jiawangbai/HAT/models/volo.py
code served (permissive licence) · get_code("ba7779c554538760")
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 Sequential. 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)

# Define a minimal block_fn that the function will call
class MinimalOutlookerBlock(nn.Module):
    def __init__(self, dim, kernel_size=3, padding=1, stride=1, num_heads=1, mlp_ratio=3.0, qkv_bias=False, qk_scale=None, attn_drop=0, drop_path=0.0):
        super().__init__()
        self.dim = dim
        self.kernel_size = kernel_size
        self.padding = padding
        self.stride = stride
        self.num_heads = num_heads
        self.mlp_ratio = mlp_ratio
        self.qkv_bias = qkv_bias
        self.qk_scale = qk_scale
        self.attn_drop = attn_drop
        self.drop_path = drop_path
        self.linear = nn.Linear(dim, dim)
    
    def forward(self, x):
        return self.linear(x)

# Define ARGS dictionary with all parameters
ARGS = {
    'block_fn': MinimalOutlookerBlock,
    'index': 0,
    'dim': 64,
    'layers': [2, 3, 4, 2],
    'num_heads': 4,
    'kernel_size': 3,
    'padding': 1,
    'stride': 1,
    'mlp_ratio': 3.0,
    'qkv_bias': False,
    'qk_scale': None,
    'attn_drop': 0.0,
    'drop_path_rate': 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 Sequential — a Sequential output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a Sequential output the recorded ndim 1 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
transformer_blocks Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
jiawangbai/HAT/models/volo.py
code served (permissive licence) · get_code("bcb4ce1c1b25bc6c")
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 Sequential. 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)

# Create a minimal block_fn that accepts the parameters passed by transformer_blocks
class MinimalTransformerBlock(nn.Module):
    def __init__(self, dim, num_heads, mlp_ratio=3.0, qkv_bias=False, qk_scale=None, attn_drop=0, drop_path=0.0):
        super().__init__()
        self.dim = dim
        self.num_heads = num_heads
        self.mlp_ratio = mlp_ratio
        self.qkv_bias = qkv_bias
        self.qk_scale = qk_scale
        self.attn_drop = attn_drop
        self.drop_path = drop_path
        self.linear = nn.Linear(dim, dim)
    
    def forward(self, x):
        return self.linear(x)

# Define ARGS dictionary with all parameters
ARGS = {
    'block_fn': MinimalTransformerBlock,
    'index': 0,
    'dim': 64,
    'layers': [2, 3, 4],
    'num_heads': 4,
    'mlp_ratio': 3.0,
    'qkv_bias': False,
    'qk_scale': None,
    'attn_drop': 0,
    'drop_path_rate': 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 Sequential — a Sequential output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a Sequential output the recorded ndim 1 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
VOLO Not yet run
unverified (harvested, no recorded run)
jiawangbai/HAT/models/volo.py
code served (permissive licence) · get_code("2b66fd4ced7843b3")
How it ran

no invocation recorded.

get_block Not yet run
unverified (harvested, no recorded run)
jiawangbai/HAT/models/volo.py
code served (permissive licence) · get_code("6974cb1ca3926a70")
How it ran

no invocation recorded.

rand_bbox Not yet run
unverified (harvested, no recorded run)
jiawangbai/HAT/models/volo.py
code served (permissive licence) · get_code("b66088e90761117d")
How it ran

no invocation recorded.

Also present in other papers' code

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

FunctionAlso present inEarliest-datedOthers named
Mlp
brick of this paper's assembly: model
130 other papers
34 dated earlier, 5 the same month, 91 later · 114 only as an assembly brick
2003.12039 (2020-03)
RAFT: Recurrent All-Pairs Field Transforms for Optical Flow
2010.11929 (2020-10)
An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale
2012.12877 (2020-12)
Training data-efficient image transformers & distillation through attention
and 127 more not named here
rand_bbox
brick of this paper's assembly: helper
3 other papers
2 dated earlier, 1 later
2106.13112 (2021-06)
VOLO: Vision Outlooker for Visual Recognition
2203.14509 (2022-03)
Automated Progressive Learning for Efficient Training of Vision Transformers
2207.04978 (2022-07)
Wave-ViT: Unifying Wavelet and Transformers for Visual Representation Learning
get_block
brick of this paper's assembly: helper
2 other papers
2 dated earlier
2106.13112 (2021-06)
VOLO: Vision Outlooker for Visual Recognition
2203.14509 (2022-03)
Automated Progressive Learning for Efficient Training of Vision Transformers
outlooker_blocks
brick of this paper's assembly: helper
2 other papers
2 dated earlier
2106.13112 (2021-06)
VOLO: Vision Outlooker for Visual Recognition
2203.14509 (2022-03)
Automated Progressive Learning for Efficient Training of Vision Transformers

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

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 transformer models have shown promising effectiveness in dealing with various vision tasks. However, compared with training Convolutional Neural Network (CNN) models, training Vision Transformer (ViT) models is more difficult and relies on the large-scale training set. To explain this observation we make a hypothesis that ViT models are less effective in capturing the high-frequency components of images than CNN models, and verify it by a frequency analysis. Inspired by this finding, we first investigate the effects of existing techniques for improving ViT models from a new frequency perspective, and find that the success of some techniques (e.g., RandAugment) can be attributed to the better usage of the high-frequency components. Then, to compensate for this insufficient ability of ViT models, we propose HAT, which directly augments high-frequency components of images via adversarial training. We show that HAT can consistently boost the performance of various ViT models (e.g., +1.2% for ViT-B, +0.5% for Swin-B), and especially enhance the advanced model VOLO-D5 to 87.3% that only uses ImageNet-1K data, and the superiority can also be maintained on out-of-distribution data and transferred to downstream tasks. The code is available at: https://github.com/jiawangbai/HAT.

For agents

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

get_harvested_code_for_paper("2204.00993")
get_code_for_paper("2204.00993")
have("2204.00993")

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

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

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

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

Connect an agent — have() is free.