SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2103.14899 · ICCV · 2021

CrossViT: Cross-Attention Multi-Scale Vision Transformer for Image Classification

Richard Chen, Rameswar Panda, Quanfu Fan

arXiv · PDF · Open in the Atlas

Code that ran

17 of 26 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (10 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 1 violated it and 16 have no contract verdict; 0 failures of our instrument; 9 no recorded run), measured 2026-11-21; 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/2103.14899.json · badge: /api/ran/2103.14899.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
conceptofmind/CrossViT-flax community
Papers with Code archive
5 ran · 3 no recorded run
ahmedelmahy/myownvit community
Papers with Code archive
5 ran · 2 no recorded run
IBM/CrossViT marked official in Papers with Code
Papers with Code archive
4 ran · 2 no recorded run
rishikksh20/CrossViT-pytorch community
Papers with Code archive
3 ran · 2 no recorded run
FunctionStatusWhere it lives
Attention Ran
ran on a synthesized input · constructed an object; no result was computed
rishikksh20/CrossViT-pytorch/crossvit.py
code served (permissive licence) · get_code("411c4d270072eb2e")
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, Attention: 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

torch.manual_seed(0)

# The Attention module expects:
# - dim: input dimension
# - heads: number of attention heads (default 8)
# - dim_head: dimension per head (default 64)
# - dropout: dropout rate (default 0.0)

# For forward(), it expects:
# - x: tensor of shape (batch, sequence_length, dim)

ARGS = {
    "dim": 64,
    "heads": 4,
    "dim_head": 16,
    "dropout": 0.1,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
einops, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Attention — 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 Attention 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
Attention Ran
ran on a synthesized input
ahmedelmahy/myownvit/vit_pytorch/cross_vit.py
code served (permissive licence) · get_code("39b524cdd79f5d2e")
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, 5, 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
from torch import nn, einsum
from einops import rearrange, repeat

def default(val, d):
    return val if exists(val) else d

def exists(val):
    return val is not None

class Attention(nn.Module):

    def __init__(self, dim, heads=8, dim_head=64, dropout=0.0):
        super().__init__()
        inner_dim = dim_head * heads
        self.heads = heads
        self.scale = dim_head ** (-0.5)
        self.attend = nn.Softmax(dim=-1)
        self.to_q = nn.Linear(dim, inner_dim, bias=False)
        self.to_kv = nn.Linear(dim, inner_dim * 2, bias=False)
        self.to_out = nn.Sequential(nn.Linear(inner_dim, dim), nn.Dropout(dropout))

    def forward(self, x, context=None, kv_include_self=False):
        b, n, _, h = (*x.shape, self.heads)
        context = default(context, x)
        if kv_include_self:
            context = torch.cat((x, context), dim=1)
        qkv = (self.to_q(x), *self.to_kv(context).chunk(2, dim=-1))
        q, k, v = map(lambda t: rearrange(t, 'b n (h d) -> b h n d', h=h), qkv)
        dots = einsum('b h i d, b h j d -> b h i j', q, k) * self.scale
        attn = self.attend(dots)
        out = einsum('b h i j, b h j d -> b h i d', attn, v)
        out = rearrange(out, 'b h n d -> b n (h d)')
        return self.to_out(out)

INIT_ARGS = {
    'dim': 16,
    'heads': 2,
    'dim_head': 8,
    'dropout': 0.1,
}

ARGS = {
    'x': torch.randn(2, 5, 16),
    'context': None,
    'kv_include_self': False,
}

if __name__ == '__main__':
    attention = Attention(**INIT_ARGS)
    output = attention(**ARGS)
    print(f"Output shape: {output.shape}")
    print(f"Expected shape: (2, 5, 16)")
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
Imports
einops, 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, 5, 16) — shape (2, 5, 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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
CrossAttention Ran
ran on a synthesized input
rishikksh20/CrossViT-pytorch/crossvit.py
code served (permissive licence) · get_code("8abca80f7f8a5dda")
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 numpy as np

# INIT_ARGS for CrossAttention.__init__
INIT_ARGS = {
    'dim': 16,
    'heads': 4,
    'dim_head': 8,
    'dropout': 0.1
}

# ARGS for CrossAttention.forward
# The forward method expects x_qkv with shape (batch, sequence_length, dim)
# The query is extracted from x_qkv[:, 0], so we need at least 1 token
ARGS = {
    'x_qkv': torch.randn(2, 5, 16)  # batch=2, seq_len=5, dim=16
}
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
Imports
einops, numpy, 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)
CrossAttention Ran
ran on a synthesized input · constructed an object; no result was computed
IBM/CrossViT/models/crossvit.py
code served (permissive licence) · get_code("9811d06fb8557fa5")
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, CrossAttention: 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

torch.manual_seed(0)

# Create a minimal valid input tensor
# Shape: (batch_size=2, num_tokens=5, dim=4)
x = torch.randn(2, 5, 4)

# Define ARGS dict with all parameters for CrossAttention.__init__
ARGS = {
    'dim': 4,
    'num_heads': 2,
    'qkv_bias': False,
    'qk_scale': None,
    'attn_drop': 0.0,
    'proj_drop': 0.0,
}
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 CrossAttention — 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 CrossAttention 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
CrossAttentionBlock Ran
ran on a synthesized input · constructed an object; no result was computed
IBM/CrossViT/models/crossvit.py
code served (permissive licence) · get_code("185cacf0bed5e23b")
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, CrossAttentionBlock: 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
from timm.models.vision_transformer import Mlp

torch.manual_seed(0)

ARGS = {
    "dim": 64,
    "num_heads": 8,
    "mlp_ratio": 4.0,
    "qkv_bias": False,
    "qk_scale": None,
    "drop": 0.1,
    "attn_drop": 0.1,
    "drop_path": 0.1,
    "act_layer": nn.GELU,
    "norm_layer": nn.LayerNorm,
    "has_mlp": True,
}
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 CrossAttentionBlock — 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 CrossAttentionBlock 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
CrossTransformer Ran
ran on a synthesized input
ahmedelmahy/myownvit/vit_pytorch/cross_vit.py
code served (permissive licence) · get_code("7909555e0d7a8a93")
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 tuple. 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
from torch import nn, einsum
from einops import rearrange, repeat

def exists(val):
    return val is not None

def default(val, d):
    return val if exists(val) else d

class Attention(nn.Module):

    def __init__(self, dim, heads=8, dim_head=64, dropout=0.0):
        super().__init__()
        inner_dim = dim_head * heads
        self.heads = heads
        self.scale = dim_head ** (-0.5)
        self.attend = nn.Softmax(dim=-1)
        self.to_q = nn.Linear(dim, inner_dim, bias=False)
        self.to_kv = nn.Linear(dim, inner_dim * 2, bias=False)
        self.to_out = nn.Sequential(nn.Linear(inner_dim, dim), nn.Dropout(dropout))

    def forward(self, x, context=None, kv_include_self=False):
        b, n, _, h = (*x.shape, self.heads)
        context = default(context, x)
        if kv_include_self:
            context = torch.cat((x, context), dim=1)
        qkv = (self.to_q(x), *self.to_kv(context).chunk(2, dim=-1))
        q, k, v = map(lambda t: rearrange(t, 'b n (h d) -> b h n d', h=h), qkv)
        dots = einsum('b h i d, b h j d -> b h i j', q, k) * self.scale
        attn = self.attend(dots)
        out = einsum('b h i j, b h j d -> b h i d', attn, v)
        out = rearrange(out, 'b h n d -> b n (h d)')
        return self.to_out(out)

class PreNorm(nn.Module):

    def __init__(self, dim, fn):
        super().__init__()
        self.norm = nn.LayerNorm(dim)
        self.fn = fn

    def forward(self, x, **kwargs):
        return self.fn(self.norm(x), **kwargs)

class ProjectInOut(nn.Module):

    def __init__(self, dim_in, dim_out, fn):
        super().__init__()
        self.fn = fn
        need_projection = dim_in != dim_out
        self.project_in = nn.Linear(dim_in, dim_out) if need_projection else nn.Identity()
        self.project_out = nn.Linear(dim_out, dim_in) if need_projection else nn.Identity()

    def forward(self, x, *args, **kwargs):
        x = self.project_in(x)
        x = self.fn(x, *args, **kwargs)
        x = self.project_out(x)
        return x

class CrossTransformer(nn.Module):

    def __init__(self, sm_dim, lg_dim, depth, heads, dim_head, dropout):
        super().__init__()
        self.layers = nn.ModuleList([])
        for _ in range(depth):
            self.layers.append(nn.ModuleList([ProjectInOut(sm_dim, lg_dim, PreNorm(lg_dim, Attention(lg_dim, heads=heads, dim_head=dim_head, dropout=dropout))), ProjectInOut(lg_dim, sm_dim, PreNorm(sm_dim, Attention(sm_dim, heads=heads, dim_head=dim_head, dropout=dropout)))]))

    def forward(self, sm_tokens, lg_tokens):
        (sm_cls, sm_patch_tokens), (lg_cls, lg_patch_tokens) = map(lambda t: (t[:, :1], t[:, 1:]), (sm_tokens, lg_tokens))
        for sm_attend_lg, lg_attend_sm in self.layers:
            sm_cls = sm_attend_lg(sm_cls, context=lg_patch_tokens, kv_include_self=True) + sm_cls
            lg_cls = lg_attend_sm(lg_cls, context=sm_patch_tokens, kv_include_self=True) + lg_cls
        sm_tokens = torch.cat((sm_cls, sm_patch_tokens), dim=1)
        lg_tokens = torch.cat((lg_cls, lg_patch_tokens), dim=1)
        return (sm_tokens, lg_tokens)

INIT_ARGS = {
    'sm_dim': 4,
    'lg_dim': 6,
    'depth': 2,
    'heads': 2,
    'dim_head': 3,
    'dropout': 0.1,
}

ARGS = {
    'sm_tokens': torch.randn(2, 5, 4),
    'lg_tokens': torch.randn(2, 7, 6),
}

if __name__ == '__main__':
    model = CrossTransformer(**INIT_ARGS)
    output = model(**ARGS)
    print("Output shapes:", output[0].shape, output[1].shape)
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
Imports
einops, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple — a tuple output has no array shape of its own; none is 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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
ImageEmbedder Ran
ran on a synthesized input · constructed an object; no result was computed
conceptofmind/CrossViT-flax/cross_vit_flax/cross_vit_flax.py
code served (permissive licence) · get_code("541e36b2edd2e342")
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, ImageEmbedder: 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 jax
import jax.numpy as jnp
from flax import linen as nn
from einops import rearrange, repeat

class ImageEmbedder(nn.Module):
    dim: int
    image_size: int
    patch_size: int
    dropout: float = 0.0

    @nn.compact
    def __call__(self, x):
        assert self.image_size % self.patch_size == 0, 'Image dimensions must be divisible by the patch size.'
        num_patches = (self.image_size // self.patch_size) ** 2
        pos_embedding = self.param('pos_embedding', nn.initializers.zeros, [1, num_patches + 1, self.dim])
        cls_token = self.param('cls', nn.initializers.zeros, [1, 1, self.dim])
        x = rearrange(x, 'b (h p1) (w p2) c -> b (h w) (p1 p2 c)', p1=self.patch_size, p2=self.patch_size)
        x = nn.Dense(features=self.dim)(x)
        b, n, d = x.shape
        cls_tokens = repeat(cls_token, '() n d -> b n d', b=b)
        x = jnp.concatenate([cls_tokens, x], axis=1)
        x += pos_embedding[:, :n + 1]
        x = nn.Dropout(rate=self.dropout)(x, deterministic=False)
        return x

dim = 4
image_size = 8
patch_size = 4
dropout = 0.1

batch_size = 2
channels = 3

x = jnp.ones((batch_size, image_size, image_size, channels))

ARGS = {
    'dim': dim,
    'image_size': image_size,
    'patch_size': patch_size,
    'dropout': dropout
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
einops, flax, jax — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type ImageEmbedder — 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 ImageEmbedder 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
ImageEmbedder Ran
ran on a synthesized input
ahmedelmahy/myownvit/vit_pytorch/cross_vit.py
code served (permissive licence) · get_code("0a16f340785793af")
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, 17, 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
from torch import nn, einsum
from einops import rearrange, repeat
from einops.layers.torch import Rearrange

class ImageEmbedder(nn.Module):

    def __init__(self, *, dim, image_size, patch_size, dropout=0.0):
        super().__init__()
        assert image_size % patch_size == 0, 'Image dimensions must be divisible by the patch size.'
        num_patches = (image_size // patch_size) ** 2
        patch_dim = 3 * patch_size ** 2
        self.to_patch_embedding = nn.Sequential(Rearrange('b c (h p1) (w p2) -> b (h w) (p1 p2 c)', p1=patch_size, p2=patch_size), nn.Linear(patch_dim, dim))
        self.pos_embedding = nn.Parameter(torch.randn(1, num_patches + 1, dim))
        self.cls_token = nn.Parameter(torch.randn(1, 1, dim))
        self.dropout = nn.Dropout(dropout)

    def forward(self, img):
        x = self.to_patch_embedding(img)
        b, n, _ = x.shape
        cls_tokens = repeat(self.cls_token, '() n d -> b n d', b=b)
        x = torch.cat((cls_tokens, x), dim=1)
        x += self.pos_embedding[:, :n + 1]
        return self.dropout(x)


INIT_ARGS = {
    'dim': 8,
    'image_size': 8,
    'patch_size': 2,
    'dropout': 0.1,
}

ARGS = {
    'img': torch.randn(2, 3, 8, 8),
}

if __name__ == '__main__':
    model = ImageEmbedder(**INIT_ARGS)
    output = model(**ARGS)
    print(f"Output shape: {output.shape}")
    print(f"Expected shape: (2, 17, 8)")
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
Imports
einops, 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, 17, 8) — shape (2, 17, 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)
MultiScaleEncoder Ran
ran on a synthesized input · constructed an object; no result was computed
conceptofmind/CrossViT-flax/cross_vit_flax/cross_vit_flax.py
code served (permissive licence) · get_code("18ea900a9c20be8f")
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, MultiScaleEncoder: 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 jax
import jax.numpy as jnp
from jax import random

# Define helper functions that are used in the code
def exists(val):
    return val is not None

def default(val, d):
    return val if exists(val) else d

# Create small test inputs
batch_size = 2
sm_seq_len = 5
lg_seq_len = 7
sm_dim = 4
lg_dim = 6

# Small model parameters
sm_enc_params = {
    "depth": 1,
    "heads": 2,
    "dim_head": 2,
    "mlp_dim": 8,
}

lg_enc_params = {
    "depth": 1,
    "heads": 2,
    "dim_head": 3,
    "mlp_dim": 12,
}

# Create input tensors
# sm_tokens: (batch, seq_len, dim)
sm_tokens = jnp.ones((batch_size, sm_seq_len, sm_dim))
# lg_tokens: (batch, seq_len, dim)
lg_tokens = jnp.ones((batch_size, lg_seq_len, lg_dim))

inputs = (sm_tokens, lg_tokens)

# Define the ARGS dictionary with all parameters for MultiScaleEncoder
ARGS = {
    "depth": 2,
    "sm_dim": sm_dim,
    "lg_dim": lg_dim,
    "sm_enc_params": sm_enc_params,
    "lg_enc_params": lg_enc_params,
    "cross_attn_heads": 2,
    "cross_attn_depth": 1,
    "cross_attn_dim_head": 2,
    "dropout": 0.1,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
einops, flax, jax — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type MultiScaleEncoder — 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 MultiScaleEncoder 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
PatchEmbed Ran
ran on a synthesized input · constructed an object; no result was computed
IBM/CrossViT/models/crossvit.py
code served (permissive licence) · get_code("2562a86d027ed434")
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, PatchEmbed: 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)

ARGS = {
    "img_size": 224,
    "patch_size": 16,
    "in_chans": 3,
    "embed_dim": 768,
    "multi_conv": False,
}
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 PatchEmbed — 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 PatchEmbed 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
PreNorm Ran
ran on a synthesized input · constructed an object; no result was computed
conceptofmind/CrossViT-flax/cross_vit_flax/cross_vit_flax.py
code served (permissive licence) · get_code("d7aaba5132053213")
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, PreNorm: 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 jax
import jax.numpy as jnp
import flax.linen as nn

# Define a simple callable function that will be used as fn in PreNorm
class SimpleMLP(nn.Module):
    @nn.compact
    def __call__(self, x, **kwargs):
        x = nn.Dense(3)(x)
        return x

# Create an instance of the callable to pass as fn parameter
fn_instance = SimpleMLP()

# Construct ARGS dict with all parameters of PreNorm
ARGS = {
    "fn": fn_instance
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
flax, jax — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type PreNorm — 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 PreNorm 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
ProjectInOut Ran
ran on a synthesized input · constructed an object; no result was computed
conceptofmind/CrossViT-flax/cross_vit_flax/cross_vit_flax.py
code served (permissive licence) · get_code("395f410c7cd053df")
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, ProjectInOut: 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 jax
import jax.numpy as jnp
import flax.linen as nn
from typing import Callable

# Define a simple callable function that will be used as fn
class SimpleFn(nn.Module):
    @nn.compact
    def __call__(self, x, *args, **kwargs):
        # Simple identity-like operation that preserves shape
        x = nn.Dense(features=x.shape[-1])(x)
        return x

# Create instances
dim_in = 4
dim_out = 5
fn = SimpleFn()

ARGS = {
    "dim_in": dim_in,
    "dim_out": dim_out,
    "fn": fn,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
flax, jax — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type ProjectInOut — 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 ProjectInOut 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
ProjectInOut Ran
ran on a synthesized input
ahmedelmahy/myownvit/vit_pytorch/cross_vit.py
code served (permissive licence) · get_code("5c51a399079da30b")
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, 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
from torch import nn, einsum

class ProjectInOut(nn.Module):

    def __init__(self, dim_in, dim_out, fn):
        super().__init__()
        self.fn = fn
        need_projection = dim_in != dim_out
        self.project_in = nn.Linear(dim_in, dim_out) if need_projection else nn.Identity()
        self.project_out = nn.Linear(dim_out, dim_in) if need_projection else nn.Identity()

    def forward(self, x, *args, **kwargs):
        x = self.project_in(x)
        x = self.fn(x, *args, **kwargs)
        x = self.project_out(x)
        return x


class SimpleFunction(nn.Module):
    def forward(self, x):
        return x * 2


INIT_ARGS = {
    'dim_in': 4,
    'dim_out': 3,
    'fn': SimpleFunction()
}

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

if __name__ == '__main__':
    module = ProjectInOut(**INIT_ARGS)
    output = module(**ARGS)
    print(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 2, dtype family float, shape (2, 4) — shape (2, 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)
Transformer Ran
ran on a synthesized input · constructed an object; no result was computed
rishikksh20/CrossViT-pytorch/crossvit.py
code served (permissive licence) · get_code("45127327251f05d5")
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, Transformer: 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

torch.manual_seed(0)

ARGS = {
    'dim': 4,
    'depth': 2,
    'heads': 2,
    'dim_head': 2,
    'mlp_dim': 8,
    'dropout': 0.1
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
einops, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Transformer — 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 Transformer 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
Transformer Ran
ran on a synthesized input · constructed an object; no result was computed
conceptofmind/CrossViT-flax/cross_vit_flax/cross_vit_flax.py
code served (permissive licence) · get_code("0415c013e361e191")
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, Transformer: 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 jax
import jax.numpy as jnp

# Initialize JAX random key
key = jax.random.PRNGKey(0)

# Define small but distinct dimensions
dim = 4
heads = 2
dim_head = 2
depth = 1
mlp_dim = 8
dropout = 0.1

# Create input tensor: (batch_size=2, sequence_length=3, dim=4)
batch_size = 2
seq_length = 3
x = jnp.ones((batch_size, seq_length, dim), dtype=jnp.float32)

ARGS = {
    "dim": dim,
    "depth": depth,
    "heads": heads,
    "dim_head": dim_head,
    "mlp_dim": mlp_dim,
    "dropout": dropout,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
einops, flax, jax — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Transformer — 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 Transformer 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
Transformer Ran
ran on a synthesized input
ahmedelmahy/myownvit/vit_pytorch/cross_vit.py
code served (permissive licence) · get_code("139bcf50e1423e16")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) and returned Tensor, ndim 3, dtype family float, shape (2, 3, 4) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
from torch import nn, einsum
from einops import rearrange, repeat

def exists(val):
    return val is not None

def default(val, d):
    return val if exists(val) else d

class Attention(nn.Module):

    def __init__(self, dim, heads=8, dim_head=64, dropout=0.0):
        super().__init__()
        inner_dim = dim_head * heads
        self.heads = heads
        self.scale = dim_head ** (-0.5)
        self.attend = nn.Softmax(dim=-1)
        self.to_q = nn.Linear(dim, inner_dim, bias=False)
        self.to_kv = nn.Linear(dim, inner_dim * 2, bias=False)
        self.to_out = nn.Sequential(nn.Linear(inner_dim, dim), nn.Dropout(dropout))

    def forward(self, x, context=None, kv_include_self=False):
        b, n, _, h = (*x.shape, self.heads)
        context = default(context, x)
        if kv_include_self:
            context = torch.cat((x, context), dim=1)
        qkv = (self.to_q(x), *self.to_kv(context).chunk(2, dim=-1))
        q, k, v = map(lambda t: rearrange(t, 'b n (h d) -> b h n d', h=h), qkv)
        dots = einsum('b h i d, b h j d -> b h i j', q, k) * self.scale
        attn = self.attend(dots)
        out = einsum('b h i j, b h j d -> b h i d', attn, v)
        out = rearrange(out, 'b h n d -> b n (h d)')
        return self.to_out(out)

class FeedForward(nn.Module):

    def __init__(self, dim, hidden_dim, dropout=0.0):
        super().__init__()
        self.net = nn.Sequential(nn.Linear(dim, hidden_dim), nn.GELU(), nn.Dropout(dropout), nn.Linear(hidden_dim, dim), nn.Dropout(dropout))

    def forward(self, x):
        return self.net(x)

class PreNorm(nn.Module):

    def __init__(self, dim, fn):
        super().__init__()
        self.norm = nn.LayerNorm(dim)
        self.fn = fn

    def forward(self, x, **kwargs):
        return self.fn(self.norm(x), **kwargs)

class Transformer(nn.Module):

    def __init__(self, dim, depth, heads, dim_head, mlp_dim, dropout=0.0):
        super().__init__()
        self.layers = nn.ModuleList([])
        self.norm = nn.LayerNorm(dim)
        for _ in range(depth):
            self.layers.append(nn.ModuleList([PreNorm(dim, Attention(dim, heads=heads, dim_head=dim_head, dropout=dropout)), PreNorm(dim, FeedForward(dim, mlp_dim, dropout=dropout))]))

    def forward(self, x):
        for attn, ff in self.layers:
            x = attn(x) + x
            x = ff(x) + x
        return self.norm(x)

INIT_ARGS = {
    'dim': 4,
    'depth': 2,
    'heads': 2,
    'dim_head': 2,
    'mlp_dim': 8,
    'dropout': 0.0
}

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

if __name__ == '__main__':
    model = Transformer(**INIT_ARGS)
    output = model(**ARGS)
    print(f"Output shape: {output.shape}")
    print(f"Expected shape: (2, 3, 4)")
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
Imports
einops, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 3, dtype family float, shape (2, 3, 4) — shape (2, 3, 4) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
_compute_num_patches Ran
ran, violated the contract we drafted
IBM/CrossViT/models/crossvit.py
code served (permissive licence) · get_code("54f90cefd4fe4358")
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 list, ndim 1, dtype family int; 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

torch.manual_seed(0)

ARGS = {
    "img_size": [224, 256],
    "patches": [16, 16]
}
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 list, ndim 1, dtype family int — a list 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
Attention Not yet run
unverified (harvested, no recorded run)
conceptofmind/CrossViT-flax/cross_vit_flax/cross_vit_flax.py
code served (permissive licence) · get_code("695e0238d8d29d65")
How it ran

no invocation recorded.

CrossTransformer Not yet run
unverified (harvested, no recorded run)
conceptofmind/CrossViT-flax/cross_vit_flax/cross_vit_flax.py
code served (permissive licence) · get_code("fcda9506e4ba0369")
How it ran

no invocation recorded.

CrossViT Not yet run
unverified (harvested, no recorded run)
rishikksh20/CrossViT-pytorch/crossvit.py
code served (permissive licence) · get_code("e9810edd3a725477")
How it ran

no invocation recorded.

CrossViT Not yet run
unverified (harvested, no recorded run)
conceptofmind/CrossViT-flax/cross_vit_flax/cross_vit_flax.py
code served (permissive licence) · get_code("54eeb67b517aba4e")
How it ran

no invocation recorded.

CrossViT Not yet run
unverified (harvested, no recorded run)
ahmedelmahy/myownvit/vit_pytorch/cross_vit.py
code served (permissive licence) · get_code("74763df32bbe08b3")
How it ran

no invocation recorded.

MultiScaleBlock Not yet run
unverified (harvested, no recorded run)
IBM/CrossViT/models/crossvit.py
code served (permissive licence) · get_code("6eb91fffc193bc8d")
How it ran

no invocation recorded.

MultiScaleEncoder Not yet run
unverified (harvested, no recorded run)
ahmedelmahy/myownvit/vit_pytorch/cross_vit.py
code served (permissive licence) · get_code("6f5a3f2db3ea4ac5")
How it ran

no invocation recorded.

MultiScaleTransformerEncoder Not yet run
unverified (harvested, no recorded run)
rishikksh20/CrossViT-pytorch/crossvit.py
code served (permissive licence) · get_code("00453bc8eaf62cc7")
How it ran

no invocation recorded.

VisionTransformer Not yet run
unverified (harvested, no recorded run)
IBM/CrossViT/models/crossvit.py
code served (permissive licence) · get_code("b05cff1db97d5001")
How it ran

no invocation recorded.

Also present in other papers' code

Of 26 samples lifted from this paper's linked repositories, 26 carry a function identity and 0 do not. Of the 26 distinct functions with an identity, 4 are also present in other papers whose code we hold (2 with at least one paper dated earlier, 4 the same month, 4 later) and 22 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
Transformer
brick of this paper's assembly: helper
11 other papers
2 dated earlier, 1 the same month, 8 later · 2 only as an assembly brick
2010.11929 (2020-10)
An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale
2101.11986 (2021-01)
Tokens-to-Token ViT: Training Vision Transformers from Scratch on ImageNet
2103.16302 (2021-03)
Rethinking Spatial Dimensions of Vision Transformers
and 8 more not named here
Attention
brick of this paper's assembly: helper
6 other papers
2 the same month, 4 later · 2 only as an assembly brick
2103.11816 (2021-03)
Incorporating Convolution Designs into Visual Transformers
2103.15691 (2021-03)
ViViT: A Video Vision Transformer
2207.06405 (2022-07)
Masked Autoencoders that Listen
and 3 more not named here
PreNorm
brick of this paper's assembly: helper
4 other papers
1 dated earlier, 2 the same month, 1 later · 2 only as an assembly brick
2101.11986 (2021-01)
Tokens-to-Token ViT: Training Vision Transformers from Scratch on ImageNet
2103.15808 (2021-03)
CvT: Introducing Convolutions to Vision Transformers
2103.16302 (2021-03)
Rethinking Spatial Dimensions of Vision Transformers
and 1 more not named here
Transformer
brick of this paper's assembly: model
2 other papers
1 the same month, 1 later
2103.15691 (2021-03)
ViViT: A Video Vision Transformer
2301.04944 (2023-01)
ViTs for SITS: Vision Transformers for Satellite Image Time Series

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

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 recently developed vision transformer (ViT) has achieved promising results on image classification compared to convolutional neural networks. Inspired by this, in this paper, we study how to learn multi-scale feature representations in transformer models for image classification. To this end, we propose a dual-branch transformer to combine image patches (i.e., tokens in a transformer) of different sizes to produce stronger image features. Our approach processes small-patch and large-patch tokens with two separate branches of different computational complexity and these tokens are then fused purely by attention multiple times to complement each other. Furthermore, to reduce computation, we develop a simple yet effective token fusion module based on cross attention, which uses a single token for each branch as a query to exchange information with other branches. Our proposed cross-attention only requires linear time for both computational and memory complexity instead of quadratic time otherwise. Extensive experiments demonstrate that our approach performs better than or on par with several concurrent works on vision transformer, in addition to efficient CNN models. For example, on the ImageNet1K dataset, with some architectural changes, our approach outperforms the recent DeiT by a large margin of 2% with a small to moderate increase in FLOPs and model parameters. Our source codes and models are available at https://github.com/IBM/CrossViT.

For agents

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

get_harvested_code_for_paper("2103.14899")
get_code_for_paper("2103.14899")
have("2103.14899")

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

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

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

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

Connect an agent — have() is free.