SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2206.07662 · 2022

SP-ViT: Learning 2D Spatial Priors for Vision Transformers

arXiv · PDF · Open in the Atlas

Code that ran

3 of 7 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 0 have no contract verdict; 3 failures of our instrument; 4 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/2206.07662.json · badge: /api/ran/2206.07662.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
ZhouYuxuanYX/SP-ViT canonical (classifier label)
classifier basis not recorded on the link
3 ran · 4 no recorded run
FunctionStatusWhere it lives
resize_pos_embed Ran
ran; our contract draft was wrong, not the code
ZhouYuxuanYX/SP-ViT/tlt/utils/utils.py
code served (permissive licence) · get_code("d0ffed38e5d3ec0e")
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 (1, 17, 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 math

torch.manual_seed(0)

# posemb: shape (1, num_tokens, embedding_dim)
# The function expects:
# - posemb[:, :1] to extract the class token (shape 1, 1, embedding_dim)
# - posemb[0, 1:] to extract grid tokens (shape num_tokens-1, embedding_dim)
# - The grid tokens should be reshapable to (1, gs_old, gs_old, embedding_dim)
#   so (num_tokens - 1) must be a perfect square

# Let's use gs_old = 3, so we need 3*3 = 9 grid tokens, total 10 tokens
# embedding_dim = 4

gs_old = 3
num_grid_tokens = gs_old * gs_old  # 9
num_tokens = num_grid_tokens + 1   # 10 (including class token)
embedding_dim = 4

posemb = torch.randn(1, num_tokens, embedding_dim)

# posemb_new: shape (1, num_tokens_new, embedding_dim)
# The function uses posemb_new.shape[1] to determine ntok_new
# Let's use gs_new = 4, so num_tokens_new = 4*4 + 1 = 17

gs_new = 4
num_tokens_new = gs_new * gs_new + 1  # 17
posemb_new = torch.randn(1, num_tokens_new, embedding_dim)

ARGS = {
    'posemb': posemb,
    'posemb_new': posemb_new,
}
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 (1, 17, 4) — shape (1, 17, 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: none by the harness; any seed is in the setup block
resize_pos_embed_4d Ran
ran; our contract draft was wrong, not the code
ZhouYuxuanYX/SP-ViT/tlt/utils/utils.py
code served (permissive licence) · get_code("e195f4974ddd5e5c")
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 4, dtype family float, shape (2, 5, 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.functional as F
import logging

torch.manual_seed(0)

# Set up logging to avoid warnings
logging.basicConfig(level=logging.INFO)

# Create tiny 4D position embedding tensors
# Shape: (batch, grid_size, grid_size, channels)
# posemb: old position embeddings with grid size 3
posemb = torch.randn(2, 3, 3, 4)

# posemb_new: new position embeddings with grid size 5
posemb_new = torch.randn(2, 5, 5, 4)

ARGS = {
    'posemb': posemb,
    'posemb_new': posemb_new,
}
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 4, dtype family float, shape (2, 5, 5, 4) — shape (2, 5, 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: none by the harness; any seed is in the setup block
resize_pos_embed_without_cls Ran
ran; our contract draft was wrong, not the code
ZhouYuxuanYX/SP-ViT/tlt/utils/utils.py
code served (permissive licence) · get_code("57a9872e1bb279d1")
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 (1, 16, 780) 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 math

torch.manual_seed(0)

# The function takes two position embedding tensors
# posemb: shape [1, num_tokens_old, embedding_dim]
# posemb_new: shape [1, num_tokens_new, embedding_dim]
# The function extracts posemb[0], which has shape [num_tokens_old, embedding_dim]
# It assumes num_tokens_old is a perfect square (gs_old^2)
# It gets ntok_new from posemb_new.shape[1], which should also be a perfect square (gs_new^2)

# Create posemb with 1 + 64 tokens (1 cls token + 64 spatial = 8x8 grid)
# Shape: [1, 65, 768]
embedding_dim = 768
gs_old = 8
num_tokens_old = 1 + gs_old * gs_old  # 65
posemb = torch.randn(1, num_tokens_old, embedding_dim)

# Create posemb_new with 1 + 16 tokens (1 cls token + 16 spatial = 4x4 grid)
# Shape: [1, 17, 768]
gs_new = 4
num_tokens_new = 1 + gs_new * gs_new  # 17
posemb_new = torch.randn(1, num_tokens_new, embedding_dim)

ARGS = {
    "posemb": posemb,
    "posemb_new": posemb_new,
}
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 (1, 16, 780) — shape (1, 16, 780) 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
get_block Not yet run
unverified (harvested, no recorded run)
ZhouYuxuanYX/SP-ViT/tlt/models/spvit.py
code served (permissive licence) · get_code("219807603e18aac6")
How it ran

no invocation recorded.

get_dpr Not yet run
unverified (harvested, no recorded run)
ZhouYuxuanYX/SP-ViT/tlt/models/spvit.py
code served (permissive licence) · get_code("455054aed5f55cb2")
How it ran

no invocation recorded.

rand_bbox Not yet run
unverified (harvested, no recorded run)
ZhouYuxuanYX/SP-ViT/tlt/models/spvit.py
pointer only (licence: Apache-2.0); the stored copy get_code serves, from deeplearning-wisc/dream-ood, is pointer only (licence: NOASSERTION) · get_code("d34a085d71b8f4b5")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (Apache-2.0), but get_code serves the stored copy, first harvested from deeplearning-wisc/dream-ood, and GitHub could not classify the licence of that repository (NOASSERTION). 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. No invocation recorded.

validate Not yet run
unverified (harvested, no recorded run)
ZhouYuxuanYX/SP-ViT/generate_label.py
code served (permissive licence) · get_code("3d05a39c441f3000")
How it ran

no invocation recorded.

Also present in other papers' code

Of 7 samples lifted from this paper's linked repositories, 7 carry a function identity and 0 do not. Of the 7 distinct functions with an identity, 6 are also present in other papers whose code we hold (6 with at least one paper dated earlier, 0 the same month, 1 later) and 1 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
rand_bbox 13 other papers
8 dated earlier, 4 later, 1 same year, order not determinable
1905.04899 (2019-05)
CutMix: Regularization Strategy to Train Strong Classifiers with Localizable Features
2002.11102 (2020-02)
On Feature Normalization and Data Augmentation
2003.05438 (2020-03)
Un-Mix: Rethinking Image Mixtures for Unsupervised Visual Representation Learning
and 10 more not named here
get_dpr 2 other papers
1 dated earlier, 1 same year, order not determinable
2104.10858 (2021-04)
All Tokens Matter: Token Labeling for Training Better Vision Transformers
136710433 (2022 (year only))
Self-slimmed Vision Transformer
get_block 1 other paper
1 dated earlier
2104.10858 (2021-04)
All Tokens Matter: Token Labeling for Training Better Vision Transformers
resize_pos_embed 1 other paper
1 dated earlier
2106.13112 (2021-06)
VOLO: Vision Outlooker for Visual Recognition
resize_pos_embed_4d 1 other paper
1 dated earlier
2106.13112 (2021-06)
VOLO: Vision Outlooker for Visual Recognition
resize_pos_embed_without_cls 1 other paper
1 dated earlier
2106.13112 (2021-06)
VOLO: Vision Outlooker for Visual Recognition

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

Recently, transformers have shown great potential in image classification and established state-of-the-art results on the ImageNet benchmark. However, compared to CNNs, transformers converge slowly and are prone to overfitting in low-data regimes due to the lack of spatial inductive biases. Such spatial inductive biases can be especially beneficial since the 2D structure of an input image is not well preserved in transformers. In this work, we present Spatial Prior-enhanced Self-Attention (SP-SA), a novel variant of vanilla Self-Attention (SA) tailored for vision transformers. Spatial Priors (SPs) are our proposed family of inductive biases that highlight certain groups of spatial relations. Unlike convolutional inductive biases, which are forced to focus exclusively on hard-coded local regions, our proposed SPs are learned by the model itself and take a variety of spatial relations into account. Specifically, the attention score is calculated with emphasis on certain kinds of spatial relations at each head, and such learned spatial foci can be complementary to each other. Based on SP-SA we propose the SP-ViT family, which consistently outperforms other ViT models with similar GFlops or parameters. Our largest model SP-ViT-L achieves a record-breaking 86.3% Top-1 accuracy with a reduction in the number of parameters by almost 50% compared to previous state-of-the-art model (150M for SP-ViT-L vs 271M for CaiT-M-36) among all ImageNet-1K models trained on 224x224 and fine-tuned on 384x384 resolution w/o extra data.

For agents

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

get_harvested_code_for_paper("2206.07662")
get_code_for_paper("2206.07662")
have("2206.07662")

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

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

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

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

Connect an agent — have() is free.