SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2106.02034 · NeurIPS · 2021

DynamicViT: Efficient Vision Transformers with Dynamic Token Sparsification

Cho-Jui Hsieh, Yongming Rao, Wenliang Zhao, Benlin Liu, Jiwen Lu, Jie Zhou

arXiv · PDF · Open in the Atlas

Code that ran

7 of 9 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (2 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; 3 failures of our instrument; 2 no recorded run), measured 2026-11-22; 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/2106.02034.json · badge: /api/ran/2106.02034.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
raoyongming/DynamicViT canonical (classifier label)
classifier basis: classifier_2025
5 ran · 2 no recorded run
vision-sjtu/quadmamba community
Papers with Code archive
1 ran · 0 no recorded run
copy not recorded community
not in the paper's declared repositories
1 ran · 0 no recorded run
FunctionStatusWhere it lives
Block Ran
ran on a synthesized input · constructed an object; no result was computed
raoyongming/DynamicViT/models/dyvit.py
code served (permissive licence) · get_code("a559e910dfa91050")
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, Block: 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
import torch.nn as nn
from timm.models.layers import DropPath

torch.manual_seed(0)

ARGS = {
    'dim': 4,
    'num_heads': 2,
    '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,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
timm, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Block — 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 Block 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
HybridEmbed Ran
ran on a synthesized input · constructed an object; no result was computed
raoyongming/DynamicViT/models/dyvit.py
code served (permissive licence) · get_code("d033f4bb9f95a41d")
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, HybridEmbed: 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
import torch.nn as nn
from timm.models.layers import DropPath, to_2tuple, trunc_normal_

torch.manual_seed(0)

# Create a minimal backbone CNN that outputs feature maps
class MinimalBackbone(nn.Module):
    def __init__(self, in_chans=3, out_chans=64):
        super().__init__()
        self.conv1 = nn.Conv2d(in_chans, out_chans, kernel_size=3, padding=1)
        self.num_features = out_chans
    
    def forward(self, x):
        x = self.conv1(x)
        return x

# Create backbone instance
backbone = MinimalBackbone(in_chans=3, out_chans=64)

# Define ARGS dict with all parameters
ARGS = {
    'backbone': backbone,
    'img_size': 224,
    'feature_size': None,
    'in_chans': 3,
    'embed_dim': 768,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
timm, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type HybridEmbed — 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 HybridEmbed 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
Predictor Ran
ran on a synthesized input
vision-sjtu/quadmamba/classification/models/csms6s.py
code served (permissive licence) · get_code("c2f59e9256846dc1")
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

class Predictor(nn.Module):
    """ Image to Patch Embedding
    """
    def __init__(self, embed_dim=384, k=1):
        super().__init__()
        self.out_conv = nn.Sequential(
            nn.Conv2d(embed_dim, embed_dim // 2, kernel_size=1, stride=1),
            nn.GELU(),
            nn.Conv2d(embed_dim // 2, embed_dim // 4, kernel_size=1, stride=1),
            nn.GELU(),
            nn.Conv2d(embed_dim // 4, k, kernel_size=1, stride=1)
        )

    def forward(self, x):
        mask = self.out_conv(x)
        B, C, H, W = mask.size()
        return mask

INIT_ARGS = {
    'embed_dim': 4,
    'k': 3
}

ARGS = {
    'x': torch.randn(2, 4, 6, 5)
}
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)
PredictorLG Ran
ran on a synthesized input
raoyongming/DynamicViT/models/dyvit.py
code served (permissive licence) · get_code("58b57ebe8cc76422")
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

class PredictorLG(nn.Module):
    """ Image to Patch Embedding
    """

    def __init__(self, embed_dim=384):
        super().__init__()
        self.in_conv = nn.Sequential(nn.LayerNorm(embed_dim), nn.Linear(embed_dim, embed_dim), nn.GELU())
        self.out_conv = nn.Sequential(nn.Linear(embed_dim, embed_dim // 2), nn.GELU(), nn.Linear(embed_dim // 2, embed_dim // 4), nn.GELU(), nn.Linear(embed_dim // 4, 2), nn.LogSoftmax(dim=-1))

    def forward(self, x, policy):
        x = self.in_conv(x)
        B, N, C = x.size()
        local_x = x[:, :, :C // 2]
        global_x = (x[:, :, C // 2:] * policy).sum(dim=1, keepdim=True) / torch.sum(policy, dim=1, keepdim=True)
        x = torch.cat([local_x, global_x.expand(B, N, C // 2)], dim=-1)
        return self.out_conv(x)


INIT_ARGS = {
    'embed_dim': 8
}

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

if __name__ == '__main__':
    model = PredictorLG(**INIT_ARGS)
    output = model(**ARGS)
    print(f"Output shape: {output.shape}")
    print(f"Output:\n{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 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)
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 facebookresearch/barlowtwins
pointer only · get_code("b0f936d4d6ae3b8c")
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.

batch_index_select Ran
ran; our contract draft was wrong, not the code
raoyongming/DynamicViT/models/dyvit.py
code served (permissive licence) · get_code("908619be92da9903")
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, 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

torch.manual_seed(0)

# Test case 1: 3D tensor
x_3d = torch.randn(2, 4, 3)  # B=2, N=4, C=3
idx_3d = torch.tensor([[0, 2], [1, 3]])  # B=2, N_new=2

# Test case 2: 2D tensor
x_2d = torch.randn(2, 4)  # B=2, N=4
idx_2d = torch.tensor([[0, 2], [1, 3]])  # B=2, N_new=2

# Use the 3D case for ARGS
ARGS = {
    "x": x_3d,
    "idx": idx_3d,
}
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, 2, 3) — shape (2, 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: none by the harness; any seed is in the setup block
validate Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
raoyongming/DynamicViT/infer.py
code served (permissive licence) · get_code("31e761629295b753")
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) and returned Tensor, ndim 0, 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

torch.manual_seed(0)

# Create a minimal model that accepts images and outputs logits
class MinimalModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 10)  # 10 classes for top-5 accuracy
    
    def forward(self, x):
        # Flatten input and pass through linear layer
        x = x.view(x.size(0), -1)
        return self.linear(x)

# Create a minimal criterion (loss function)
criterion = nn.CrossEntropyLoss()

# Create a minimal model
model = MinimalModel()

# Create a minimal data loader (list of batches)
# Each batch is (images, target)
val_loader = [
    (torch.randn(2, 1, 2, 2), torch.randint(0, 10, (2,))),
    (torch.randn(2, 1, 2, 2), torch.randint(0, 10, (2,))),
    (torch.randn(2, 1, 2, 2), torch.randint(0, 10, (2,))),
]

ARGS = {
    'val_loader': val_loader,
    'model': model,
    'criterion': criterion,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
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 0, dtype family float — no output shape is stated: observe_signature.py could not observe it (call:AssertionError)
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
Attention Not yet run
unverified (harvested, no recorded run)
raoyongming/DynamicViT/models/dyvit.py
code served (permissive licence) · get_code("575ff52688baea94")
How it ran

no invocation recorded.

VisionTransformerDiffPruning Not yet run
unverified (harvested, no recorded run)
raoyongming/DynamicViT/models/dyvit.py
code served (permissive licence) · get_code("641fc76ec2423f31")
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, 4 are also present in other papers whose code we hold (2 with at least one paper dated earlier, 1 the same month, 4 later) and 5 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 116 other papers
19 dated earlier, 2 the same month, 95 later · 8 only as an assembly brick
1502.03044 (2015-02)
Show, Attend and Tell: Neural Image Caption Generation with Visual Attention
1610.05820 (2016-10)
Membership Inference Attacks Against Machine Learning Models
1905.03696 (2019-05)
HAWQ: Hessian AWare Quantization of Neural Networks with Mixed-Precision
and 113 more not named here
batch_index_select
brick of this paper's assembly: helper
10 other papers
10 later · 1 only as an assembly brick
2202.06258 (2022-02)
Flowformer: Linearizing Transformers with Conservation Flows
aaai_25860 (2023 (year only))
CF-ViT: A General Coarse-to-Fine Method for Vision Transformer
2304.10716 (2023-04)
Joint Token Pruning and Squeezing Towards More Aggressive Compression of Vision Transformers
and 7 more not named here
HybridEmbed
brick of this paper's assembly: helper
6 other papers
1 dated earlier, 5 later · 3 only as an assembly brick
2105.14432 (2021-05)
TransMatcher: Deep Image Matching Through Transformers for Generalizable Person Re-identification
2303.13755 (2023-03)
Sparsifiner: Learning Sparse Instance-Dependent Attention for Efficient Vision Transformers
2308.03322 (2023-08)
Part-Aware Transformer for Generalizable Person Re-identification
and 3 more not named here
validate 1 other paper
1 later
2207.01580 (2022-07)
Dynamic Spatial Sparsification for Efficient Vision Transformers and Convolutional Neural Networks

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

Attention is sparse in vision transformers. We observe the final prediction in vision transformers is only based on a subset of most informative tokens, which is sufficient for accurate image recognition. Based on this observation, we propose a dynamic token sparsification framework to prune redundant tokens progressively and dynamically based on the input. Specifically, we devise a lightweight prediction module to estimate the importance score of each token given the current features. The module is added to different layers to prune redundant tokens hierarchically. To optimize the prediction module in an end-to-end manner, we propose an attention masking strategy to differentiably prune a token by blocking its interactions with other tokens. Benefiting from the nature of self-attention, the unstructured sparse tokens are still hardware friendly, which makes our framework easy to achieve actual speed-up. By hierarchically pruning 66% of the input tokens, our method greatly reduces 31% ∼ 37% FLOPs and improves the throughput by over 40% while the drop of accuracy is within 0.5% for various vision transformers. Equipped with the dynamic token sparsification framework, DynamicViT models can achieve very competitive complexity/accuracy trade-offs compared to state-of-the-art CNNs and vision transformers on ImageNet. Code is available at https://github.com/ raoyongming/DynamicViT.

For agents

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

get_harvested_code_for_paper("2106.02034")
get_code_for_paper("2106.02034")
have("2106.02034")

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

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

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

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

Connect an agent — have() is free.