SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2406.04303 · ICLR · 2025

Vision-LSTM: xLSTM as Generic Vision Backbone

Johannes Brandstetter, Sepp Hochreiter, Maximilian Beck, Benedikt Alkin, Korbinian Pöppel

arXiv · PDF · Open in the Atlas

Code that ran

14 of 19 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 1 honoured the contract we drafted, 0 violated it and 7 have no contract verdict; 6 failures of our instrument; 5 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/2406.04303.json · badge: /api/ran/2406.04303.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
NX-AI/vision-lstm canonical (classifier label)
classifier basis: classifier_2025
14 ran · 5 no recorded run
FunctionStatusWhere it lives
CausalConv1d Ran
ran on a synthesized input
NX-AI/vision-lstm/vision_lstm/vision_lstm.py
code served (permissive licence) · get_code("f8ca69c110b41703")
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, 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 einops
from torch import nn

class CausalConv1d(nn.Module):
    """
    Implements causal depthwise convolution of a time series tensor.
    Input:  Tensor of shape (B,T,F), i.e. (batch, time, feature)
    Output: Tensor of shape (B,T,F)

    Args:
        feature_dim: number of features in the input tensor
        kernel_size: size of the kernel for the depthwise convolution
        causal_conv_bias: whether to use bias in the depthwise convolution
        channel_mixing: whether to use channel mixing (i.e. groups=1) or not (i.e. groups=feature_dim)
                        If True, it mixes the convolved features across channels.
                        If False, all the features are convolved independently.
    """

    def __init__(self, dim, kernel_size=4, bias=True):
        super().__init__()
        self.dim = dim
        self.kernel_size = kernel_size
        self.bias = bias
        self.pad = kernel_size - 1
        self.conv = nn.Conv1d(in_channels=dim, out_channels=dim, kernel_size=kernel_size, padding=self.pad, groups=dim, bias=bias)
        self.reset_parameters()

    def reset_parameters(self):
        self.conv.reset_parameters()

    def forward(self, x: torch.Tensor) -> torch.Tensor:
        x = einops.rearrange(x, 'b l d -> b d l')
        x = self.conv(x)
        x = x[:, :, :-self.pad]
        x = einops.rearrange(x, 'b d l -> b l d')
        return x


INIT_ARGS = {
    'dim': 4,
    'kernel_size': 3,
    'bias': True,
}

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

if __name__ == '__main__':
    model = CausalConv1d(**INIT_ARGS)
    output = model(**ARGS)
    print(f"Input shape: {ARGS['x'].shape}")
    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
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, 4) — shape (2, 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)
DropPath Ran
ran on a synthesized input
NX-AI/vision-lstm/vision_lstm/vision_lstm.py
code served (permissive licence) · get_code("5fa540c6a1346171")
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

class DropPath(nn.Sequential):
    """
    Efficiently drop paths (Stochastic Depth) per sample such that dropped samples are not processed.
    This is a subclass of nn.Sequential and can be used either as standalone Module or like nn.Sequential.
    Examples::
        >>> # use as nn.Sequential module
        >>> sequential_droppath = DropPath(nn.Linear(4, 4), drop_prob=0.2)
        >>> y = sequential_droppath(torch.randn(10, 4))

        >>> # use as standalone module
        >>> standalone_layer = nn.Linear(4, 4)
        >>> standalone_droppath = DropPath(drop_prob=0.2)
        >>> y = standalone_droppath(torch.randn(10, 4), standalone_layer)
    """

    def __init__(self, *args, drop_prob: float=0.0, scale_by_keep: bool=True, stochastic_drop_prob: bool=False, drop_prob_tolerance: float=0.01):
        super().__init__(*args)
        assert 0.0 <= drop_prob < 1.0
        self._drop_prob = drop_prob
        self.scale_by_keep = scale_by_keep
        self.stochastic_drop_prob = stochastic_drop_prob
        self.drop_prob_tolerance = drop_prob_tolerance

    @property
    def drop_prob(self):
        return self._drop_prob

    @drop_prob.setter
    def drop_prob(self, value):
        assert 0.0 <= value < 1.0
        self._drop_prob = value

    @property
    def keep_prob(self):
        return 1.0 - self.drop_prob

    def forward(self, x, residual_path=None, residual_path_kwargs=None):
        assert (len(self) == 0) ^ (residual_path is None)
        residual_path_kwargs = residual_path_kwargs or {}
        if self.drop_prob == 0.0 or not self.training:
            if residual_path is None:
                return x + super().forward(x, **residual_path_kwargs)
            else:
                return x + residual_path(x, **residual_path_kwargs)
        bs = len(x)
        keep_count = max(int(bs * self.keep_prob), 1)
        actual_keep_prob = keep_count / bs
        drop_path_delta = self.keep_prob - actual_keep_prob
        if self.stochastic_drop_prob or drop_path_delta > self.drop_prob_tolerance:
            shape = (x.shape[0],) + (1,) * (x.ndim - 1)
            random_tensor = x.new_empty(shape).bernoulli_(self.keep_prob)
            if self.scale_by_keep:
                random_tensor.div_(self.keep_prob)
            if residual_path is None:
                return x + super().forward(x, **residual_path_kwargs) * random_tensor
            else:
                return x + residual_path(x, **residual_path_kwargs) * random_tensor
        scale = bs / keep_count
        perm = torch.randperm(bs, device=x.device)[:keep_count]
        if self.scale_by_keep:
            alpha = scale
        else:
            alpha = 1.0
        residual_path_kwargs = {key: value[perm] if torch.is_tensor(value) else value for key, value in residual_path_kwargs.items()}
        if residual_path is None:
            residual = super().forward(x[perm], **residual_path_kwargs)
        else:
            residual = residual_path(x[perm], **residual_path_kwargs)
        return torch.index_add(x.flatten(start_dim=1), dim=0, index=perm, source=residual.to(x.dtype).flatten(start_dim=1), alpha=alpha).view_as(x)

    def extra_repr(self):
        return f'drop_prob={round(self.drop_prob, 3):0.3f}'


INIT_ARGS = {
    'drop_prob': 0.3,
    'scale_by_keep': True,
    'stochastic_drop_prob': False,
    'drop_prob_tolerance': 0.01,
}

ARGS = {
    'x': torch.randn(2, 4),
    'residual_path': nn.Linear(4, 4),
    'residual_path_kwargs': {},
}

if __name__ == '__main__':
    droppath = DropPath(nn.Linear(4, 4), **INIT_ARGS)
    droppath.train()
    output = droppath(**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 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)
LayerNorm Ran
ran on a synthesized input
NX-AI/vision-lstm/vision_lstm/vision_lstm.py
code served (permissive licence) · get_code("a796b1f63f3dfbce")
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
import torch.nn.functional as F
from torch import nn

class LayerNorm(nn.Module):
    """ LayerNorm but with an optional bias. PyTorch doesn't support simply bias=False. """

    def __init__(self, ndim: int=-1, weight: bool=True, bias: bool=False, eps: float=1e-05, residual_weight: bool=True):
        super().__init__()
        self.weight = nn.Parameter(torch.zeros(ndim)) if weight else None
        self.bias = nn.Parameter(torch.zeros(ndim)) if bias else None
        self.eps = eps
        self.residual_weight = residual_weight
        self.ndim = ndim
        self.reset_parameters()

    @property
    def weight_proxy(self) -> torch.Tensor:
        if self.weight is None:
            return None
        if self.residual_weight:
            return 1.0 + self.weight
        else:
            return self.weight

    def forward(self, x: torch.Tensor) -> torch.Tensor:
        return F.layer_norm(x, normalized_shape=(self.ndim,), weight=self.weight_proxy, bias=self.bias, eps=self.eps)

    def reset_parameters(self):
        if self.weight_proxy is not None:
            if self.residual_weight:
                nn.init.zeros_(self.weight)
            else:
                nn.init.ones_(self.weight)
        if self.bias is not None:
            nn.init.zeros_(self.bias)


INIT_ARGS = {
    'ndim': 4,
    'weight': True,
    'bias': False,
    'eps': 1e-05,
    'residual_weight': True,
}

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

if __name__ == '__main__':
    layer_norm = LayerNorm(**INIT_ARGS)
    output = layer_norm(**ARGS)
    print(f"Input shape: {ARGS['x'].shape}")
    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 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)
LinearHeadwiseExpand Ran
ran on a synthesized input
NX-AI/vision-lstm/vision_lstm/vision_lstm.py
code served (permissive licence) · get_code("22cd5400a08af55a")
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, 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 math
import einops
import torch
from torch import nn

class LinearHeadwiseExpand(nn.Module):
    """
    This is a structured projection layer that projects the input to a higher dimension.
    It only allows integer up-projection factors, i.e. the output dimension is a multiple of the input dimension.
    """

    def __init__(self, dim, num_heads, bias=False):
        super().__init__()
        assert dim % num_heads == 0
        self.dim = dim
        self.num_heads = num_heads
        dim_per_head = dim // num_heads
        self.weight = nn.Parameter(torch.empty(num_heads, dim_per_head, dim_per_head))
        if bias:
            self.bias = nn.Parameter(torch.empty(dim))
        else:
            self.bias = None
        self.reset_parameters()

    def reset_parameters(self):
        nn.init.normal_(self.weight.data, mean=0.0, std=math.sqrt(2 / 5 / self.weight.shape[-1]))
        if self.bias is not None:
            nn.init.zeros_(self.bias.data)

    def forward(self, x: torch.Tensor) -> torch.Tensor:
        x = einops.rearrange(x, '... (nh d) -> ... nh d', nh=self.num_heads)
        x = einops.einsum(x, self.weight, '... nh d, nh out_d d -> ... nh out_d')
        x = einops.rearrange(x, '... nh out_d -> ... (nh out_d)')
        if self.bias is not None:
            x = x + self.bias
        return x

    def extra_repr(self):
        return f'dim={self.dim}, num_heads={self.num_heads}, bias={self.bias is not None}, '


INIT_ARGS = {
    'dim': 8,
    'num_heads': 2,
    'bias': True,
}

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

if __name__ == '__main__':
    module = LinearHeadwiseExpand(**INIT_ARGS)
    output = module(**ARGS)
    print(f"Input shape: {ARGS['x'].shape}")
    print(f"Output shape: {output.shape}")
    print(f"Module: {module}")
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 2, dtype family float, shape (2, 8) — shape (2, 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)
MultiHeadLayerNorm Ran
ran on a synthesized input
NX-AI/vision-lstm/vision_lstm/vision_lstm.py
code served (permissive licence) · get_code("70db181d80fa624d")
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, 4, 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
from torch import nn

class LayerNorm(nn.Module):
    """ LayerNorm but with an optional bias. PyTorch doesn't support simply bias=False. """

    def __init__(self, ndim: int=-1, weight: bool=True, bias: bool=False, eps: float=1e-05, residual_weight: bool=True):
        super().__init__()
        self.weight = nn.Parameter(torch.zeros(ndim)) if weight else None
        self.bias = nn.Parameter(torch.zeros(ndim)) if bias else None
        self.eps = eps
        self.residual_weight = residual_weight
        self.ndim = ndim
        self.reset_parameters()

    @property
    def weight_proxy(self) -> torch.Tensor:
        if self.weight is None:
            return None
        if self.residual_weight:
            return 1.0 + self.weight
        else:
            return self.weight

    def forward(self, x: torch.Tensor) -> torch.Tensor:
        return F.layer_norm(x, normalized_shape=(self.ndim,), weight=self.weight_proxy, bias=self.bias, eps=self.eps)

    def reset_parameters(self):
        if self.weight_proxy is not None:
            if self.residual_weight:
                nn.init.zeros_(self.weight)
            else:
                nn.init.ones_(self.weight)
        if self.bias is not None:
            nn.init.zeros_(self.bias)

class MultiHeadLayerNorm(LayerNorm):

    def forward(self, x: torch.Tensor) -> torch.Tensor:
        assert x.ndim == 4, 'Input must be 4D tensor (B, NH, S, DH)'
        B, NH, S, DH = x.shape
        gn_in_1 = x.transpose(1, 2)
        gn_in_2 = gn_in_1.reshape(B * S, NH * DH)
        out = F.group_norm(gn_in_2, num_groups=NH, weight=self.weight_proxy, bias=self.bias, eps=self.eps)
        out = out.view(B, S, NH, DH).transpose(1, 2)
        return out


INIT_ARGS = {
    'ndim': 12,
    'weight': True,
    'bias': False,
    'eps': 1e-05,
    'residual_weight': True
}

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

if __name__ == '__main__':
    model = MultiHeadLayerNorm(**INIT_ARGS)
    output = model(**ARGS)
    print(f"Input shape: {ARGS['x'].shape}")
    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 4, dtype family float, shape (2, 3, 4, 4) — shape (2, 3, 4, 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)
VitPatchEmbed Ran
ran on a synthesized input
NX-AI/vision-lstm/vision_lstm/vision_lstm.py
code served (permissive licence) · get_code("6b7511b39ecf627e")
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 einops
import numpy as np
import collections
import itertools

def _ntuple(n):
    def parse(x):
        if isinstance(x, collections.abc.Iterable):
            assert len(x) == n
            return x
        return tuple(itertools.repeat(x, n))
    return parse

def to_ntuple(x, n):
    return _ntuple(n=n)(x)

class VitPatchEmbed(nn.Module):
    def __init__(self, dim, num_channels, resolution, patch_size, stride=None, init_weights='xavier_uniform'):
        super().__init__()
        self.resolution = resolution
        self.init_weights = init_weights
        self.ndim = len(resolution)
        self.patch_size = to_ntuple(patch_size, n=self.ndim)
        if stride is None:
            self.stride = self.patch_size
        else:
            self.stride = to_ntuple(stride, n=self.ndim)
        for i in range(self.ndim):
            assert resolution[i] % self.patch_size[i] == 0, f'resolution[{i}] % patch_size[{i}] != 0 (resolution={resolution} patch_size={patch_size})'
        self.seqlens = [resolution[i] // self.patch_size[i] for i in range(self.ndim)]
        if self.patch_size == self.stride:
            self.num_patches = int(np.prod(self.seqlens))
        else:
            if self.ndim == 1:
                conv_func = torch.nn.functional.conv1d
            elif self.ndim == 2:
                conv_func = torch.nn.functional.conv2d
            elif self.ndim == 3:
                conv_func = torch.nn.functional.conv3d
            else:
                raise NotImplementedError
            self.num_patches = conv_func(input=torch.zeros(1, 1, *resolution), weight=torch.zeros(1, 1, *self.patch_size), stride=self.stride).numel()
        if self.ndim == 1:
            conv_ctor = nn.Conv1d
        elif self.ndim == 2:
            conv_ctor = nn.Conv2d
        elif self.ndim == 3:
            conv_ctor = nn.Conv3d
        else:
            raise NotImplementedError
        self.proj = conv_ctor(num_channels, dim, kernel_size=self.patch_size, stride=self.stride)
        self.reset_parameters()

    def reset_parameters(self):
        if self.init_weights == 'torch':
            pass
        elif self.init_weights == 'xavier_uniform':
            w = self.proj.weight.data
            nn.init.xavier_uniform_(w.view([w.shape[0], -1]))
            nn.init.zeros_(self.proj.bias)
        else:
            raise NotImplementedError

    def forward(self, x):
        assert all((x.size(i + 2) % self.patch_size[i] == 0 for i in range(self.ndim))), f'x.shape={x.shape} incompatible with patch_size={self.patch_size}'
        x = self.proj(x)
        x = einops.rearrange(x, 'b c ... -> b ... c')
        return x

INIT_ARGS = {
    'dim': 8,
    'num_channels': 3,
    'resolution': (16, 20),
    'patch_size': 4,
    'stride': None,
    'init_weights': 'xavier_uniform'
}

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

if __name__ == '__main__':
    model = VitPatchEmbed(**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
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 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)
VitPosEmbed2d Ran
ran on a synthesized input
NX-AI/vision-lstm/vision_lstm/vision_lstm.py
code served (permissive licence) · get_code("e56c0fd30e56fabf")
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, 3, 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 einops
import torch.nn.functional as F

def interpolate_sincos(embed, seqlens, mode='bicubic'):
    assert embed.ndim - 2 == len(seqlens)
    embed = F.interpolate(einops.rearrange(embed, '1 ... dim -> 1 dim ...'), size=seqlens, mode=mode)
    embed = einops.rearrange(embed, '1 dim ... -> 1 ... dim')
    return embed

class VitPosEmbed2d(nn.Module):

    def __init__(self, seqlens, dim: int, allow_interpolation: bool=True):
        super().__init__()
        self.seqlens = seqlens
        self.dim = dim
        self.allow_interpolation = allow_interpolation
        self.embed = nn.Parameter(torch.zeros(1, *seqlens, dim))
        self.reset_parameters()

    @property
    def _expected_x_ndim(self):
        return len(self.seqlens) + 2

    def reset_parameters(self):
        nn.init.trunc_normal_(self.embed, std=0.02)

    def forward(self, x):
        assert x.ndim == self._expected_x_ndim
        if x.shape[1:] != self.embed.shape[1:]:
            assert self.allow_interpolation
            embed = interpolate_sincos(embed=self.embed, seqlens=x.shape[1:-1])
        else:
            embed = self.embed
        return x + embed


INIT_ARGS = {
    'seqlens': (4, 3),
    'dim': 8,
    'allow_interpolation': True,
}

ARGS = {
    'x': torch.randn(2, 4, 3, 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 4, dtype family float, shape (2, 4, 3, 8) — shape (2, 4, 3, 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)
_ntuple Ran
ran; our contract draft was wrong, not the code
NX-AI/vision-lstm/vision_lstm/vision_lstm.py
code served (permissive licence) · get_code("90263a78b0923104")
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 function. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import collections
import itertools

def _ntuple(n):
    def parse(x):
        if isinstance(x, collections.abc.Iterable):
            assert len(x) == n
            return x
        return tuple(itertools.repeat(x, n))
    return parse

# Test with different values of n
ARGS = {
    "n": 3
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type function — a function output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a function output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
bias_linspace_init_ Ran
ran; our contract draft was wrong, not the code
NX-AI/vision-lstm/vision_lstm/vision_lstm.py
code served (permissive licence) · get_code("705d17e5f5c0489b")
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 1, dtype family float, shape (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

torch.manual_seed(0)

# Create a 1-dimensional bias tensor with 4 elements
bias_param = torch.randn(4)

ARGS = {
    'param': bias_param,
    'start': 3.4,
    'end': 6.0,
}
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 1, dtype family float, shape (4,) — shape (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
interpolate_sincos Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
NX-AI/vision-lstm/vision_lstm/vision_lstm.py
code served (permissive licence) · get_code("3852783d3c31c6c8")
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 4, dtype family float, shape (1, 3, 7, 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 einops
import torch.nn.functional as F

torch.manual_seed(0)

# The function expects:
# - embed: a tensor with shape (1, *spatial_dims, dim)
# - seqlens: a sequence of integers representing target spatial dimensions
# - mode: a string for interpolation mode

# For a 2D case (e.g., image-like):
# embed should have shape (1, height, width, dim)
# seqlens should be [target_height, target_width]

embed = torch.randn(1, 4, 5, 8)  # (batch=1, height=4, width=5, dim=8)
seqlens = [3, 7]  # target spatial dimensions
mode = 'bicubic'

ARGS = {
    'embed': embed,
    'seqlens': seqlens,
    'mode': mode
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
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 4, dtype family float, shape (1, 3, 7, 8) — shape (1, 3, 7, 8) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
parallel_stabilized_simple Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
NX-AI/vision-lstm/vision_lstm/vision_lstm.py
code served (permissive licence) · get_code("124d9b21f82fcec5")
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 4, dtype family float, shape (2, 3, 4, 5) 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)

# Define tensor dimensions
B = 2  # batch size
NH = 3  # number of heads
S = 4  # sequence length
DH = 5  # head dimension

# Create tensors with the required shapes
queries = torch.randn(B, NH, S, DH)
keys = torch.randn(B, NH, S, DH)
values = torch.randn(B, NH, S, DH)
igate_preact = torch.randn(B, NH, S, 1)
fgate_preact = torch.randn(B, NH, S, 1)

# Create lower triangular matrix (optional parameter)
lower_triangular_matrix = torch.tril(torch.ones((S, S), dtype=torch.bool))

# Define ARGS dictionary with all parameters
ARGS = {
    'queries': queries,
    'keys': keys,
    'values': values,
    'igate_preact': igate_preact,
    'fgate_preact': fgate_preact,
    'lower_triangular_matrix': lower_triangular_matrix,
    'stabilize_rowwise': True,
    'eps': 1e-6
}
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 4, dtype family float, shape (2, 3, 4, 5) — shape (2, 3, 4, 5) 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
small_init_ Ran
ran; our contract draft was wrong, not the code
NX-AI/vision-lstm/vision_lstm/vision_lstm.py
code served (permissive licence) · get_code("83954f29f639db88")
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 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
import math

torch.manual_seed(0)

# Create a small tensor parameter to initialize
param = torch.empty(2, 4)

# The function takes a dimension parameter
dim = 4

ARGS = {
    "param": param,
    "dim": dim,
}
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 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: none by the harness; any seed is in the setup block
to_ntuple Ran
ran, honoured the contract we drafted
NX-AI/vision-lstm/vision_lstm/vision_lstm.py
code served (permissive licence) · get_code("8aecee1d48ec4f1e")
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 tuple, 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 collections
import itertools

def _ntuple(n):
    def parse(x):
        if isinstance(x, collections.abc.Iterable):
            assert len(x) == n
            return x
        return tuple(itertools.repeat(x, n))
    return parse

def to_ntuple(x, n):
    return _ntuple(n=n)(x)

# Test case 1: scalar input
ARGS = {
    "x": 5,
    "n": 3
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple, ndim 1, dtype family int — a tuple output has no array shape of its own; none is stated
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
wang_init_ Ran
ran; our contract draft was wrong, not the code
NX-AI/vision-lstm/vision_lstm/vision_lstm.py
code served (permissive licence) · get_code("b5ad18007daa65d1")
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 2, dtype family float, shape (4, 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 math

torch.manual_seed(0)

# Create a small tensor parameter to initialize
param = torch.empty(4, 3)

# Set up the arguments
dim = 4
num_blocks = 2

ARGS = {
    "param": param,
    "dim": dim,
    "num_blocks": num_blocks,
}
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 2, dtype family float, shape (4, 3) — shape (4, 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
MatrixLSTMCell Not yet run
unverified (harvested, no recorded run)
NX-AI/vision-lstm/vision_lstm/vision_lstm.py
code served (permissive licence) · get_code("0c409c165a499499")
How it ran

no invocation recorded.

SequenceTraversal Not yet run
unverified (harvested, no recorded run)
NX-AI/vision-lstm/vision_lstm/vision_lstm.py
code served (permissive licence) · get_code("83c87d311ea75cbc")
How it ran

no invocation recorded.

ViLBlock Not yet run
unverified (harvested, no recorded run)
NX-AI/vision-lstm/vision_lstm/vision_lstm.py
code served (permissive licence) · get_code("a74a2b2b5da0ef34")
How it ran

no invocation recorded.

ViLLayer Not yet run
unverified (harvested, no recorded run)
NX-AI/vision-lstm/vision_lstm/vision_lstm.py
code served (permissive licence) · get_code("b9defe989265d1d9")
How it ran

no invocation recorded.

VisionLSTM Not yet run
unverified (harvested, no recorded run)
NX-AI/vision-lstm/vision_lstm/vision_lstm.py
code served (permissive licence) · get_code("061ae51a3df25f67")
How it ran

no invocation recorded.

Also present in other papers' code

Of 19 samples lifted from this paper's linked repositories, 19 carry a function identity and 0 do not. Of the 19 distinct functions with an identity, 4 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 3 the same month, 2 later) and 15 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
bias_linspace_init_
brick of this paper's assembly: helper
3 other papers
1 the same month, 2 later
2406.02918 (2024-06)
U-KAN Makes Strong Backbone for Medical Image Segmentation and Generation
2411.04165 (2024-11)
Bio-xLSTM: Generative modeling, representation and in-context learning of biological and chemical sequences
2503.13427 (2025-03)
xLSTM 7B: A Recurrent LLM for Fast and Efficient Inference
wang_init_
brick of this paper's assembly: helper
2 other papers
2 later
2411.04165 (2024-11)
Bio-xLSTM: Generative modeling, representation and in-context learning of biological and chemical sequences
2503.13427 (2025-03)
xLSTM 7B: A Recurrent LLM for Fast and Efficient Inference
interpolate_sincos
brick of this paper's assembly: helper
1 other paper
1 the same month
2406.02918 (2024-06)
U-KAN Makes Strong Backbone for Medical Image Segmentation and Generation
small_init_
brick of this paper's assembly: helper
1 other paper
1 the same month
2406.02918 (2024-06)
U-KAN Makes Strong Backbone for Medical Image Segmentation and Generation

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

Transformers are widely used as generic backbones in computer vision, despite initially introduced for natural language processing. Recently, the Long Short-Term Memory (LSTM) has been extended to a scalable and performant architecture -the xLSTM -which overcomes long-standing LSTM limitations via exponential gating and parallelizable matrix memory structure. In this paper, we introduce Vision-LSTM (ViL), an adaption of the xLSTM building blocks to computer vision. ViL comprises a stack of xLSTM blocks where odd blocks process the sequence of patch tokens from top to bottom while even blocks go from bottom to top. ViL achieves strong performances on classification, transfer learning and segmentation tasks as well as a beneficial pre-training cost-to-performance trade-off. Experiments show that ViL holds promise to be further deployed as new generic backbone for computer vision architectures. Project page: https://nx-ai.github.io/vision-lstm/ 10 18 10 19 Pre-training FLOPS 60 65 Performance [%] 256 2 512 2 1024 2 2048 2 Resolution 10 8 10 9 10 10 10 11 FLOPS Vision-Transformer Vision-Mamba Vision-LSTM Figure 1: The efficient and scalable design of Vision-LSTM shows strong performances, uses less FLOPS than Transformer/Mamba counterparts and scales linear to higher resolutions. Performance is averaged over ImageNet accuracy, ADE20K mIoU and VTAB-1K accuracy.

For agents

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

get_harvested_code_for_paper("2406.04303")
get_code_for_paper("2406.04303")
have("2406.04303")

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

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

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

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

Connect an agent — have() is free.