SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2406.07522 · ICLR · 2025

Samba: Simple Hybrid State Space Models for Efficient Unlimited Context Language Modeling

Yang Liu, Chen Liang, Weizhu Chen, Yelong Shen, Liliang Ren, Yadong Lu

arXiv · PDF · Open in the Atlas

Code that ran

1 of 1 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (1 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 1 has no contract verdict; 0 failures of our instrument; 0 no recorded run), measured 2026-11-22; repository links from the Papers with Code archive attributed under CC BY-SA, no affiliation; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2406.07522.json · badge: /api/ran/2406.07522.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
microsoft/Samba canonical (classifier label)
classifier basis: classifier_2025
1 ran · 0 no recorded run
FunctionStatusWhere it lives
MBlock Ran
ran on a synthesized input · constructed an object; no result was computed
microsoft/Samba/lit_gpt/model.py
code served (permissive licence) · get_code("5eee0e9094b24c6d")
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, MBlock: 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 torch import Tensor
from typing import Optional

torch.manual_seed(0)

# Create a simple mixer class that the MBlock expects
class SimpleMixer(nn.Module):
    def __init__(self, dim):
        super().__init__()
        self.dim = dim
        self.linear = nn.Linear(dim, dim)
    
    def forward(self, hidden_states: Tensor, inference_params=None):
        return self.linear(hidden_states)
    
    def allocate_inference_cache(self, batch_size, max_seqlen, dtype=None, **kwargs):
        return None

# Define the RMSNorm class that the code references
class RMSNorm(nn.Module):
    def __init__(self, dim, eps=1e-6):
        super().__init__()
        self.weight = nn.Parameter(torch.ones(dim))
        self.bias = nn.Parameter(torch.zeros(dim))
        self.eps = eps
    
    def forward(self, x):
        return x * torch.rsqrt(x.pow(2).mean(-1, keepdim=True) + self.eps) * self.weight + self.bias

# Create stub functions for fused operations
def layer_norm_fn(hidden_states, weight, bias, residual=None, prenorm=False, residual_in_fp32=False, eps=1e-6):
    if residual is not None:
        hidden_states = hidden_states + residual
    norm_out = torch.nn.functional.layer_norm(hidden_states, (hidden_states.shape[-1],), weight, bias, eps=eps)
    residual = hidden_states.to(torch.float32) if residual_in_fp32 else hidden_states
    return norm_out, residual

def rms_norm_fn(hidden_states, weight, bias, residual=None, prenorm=False, residual_in_fp32=False, eps=1e-6):
    if residual is not None:
        hidden_states = hidden_states + residual
    rms = torch.sqrt(hidden_states.pow(2).mean(-1, keepdim=True) + eps)
    norm_out = (hidden_states / rms) * weight + bias
    residual = hidden_states.to(torch.float32) if residual_in_fp32 else hidden_states
    return norm_out, residual

# Inject these into the module's namespace so MBlock can use them
import sys
current_module = sys.modules[__name__]
setattr(current_module, 'rms_norm_fn', rms_norm_fn)
setattr(current_module, 'layer_norm_fn', layer_norm_fn)
setattr(current_module, 'RMSNorm', RMSNorm)

# Create arguments for MBlock.__init__
dim = 4
mixer_cls = SimpleMixer
norm_cls = nn.LayerNorm
fused_add_norm = False
residual_in_fp32 = False

ARGS = {
    'dim': dim,
    'mixer_cls': mixer_cls,
    'norm_cls': norm_cls,
    'fused_add_norm': fused_add_norm,
    'residual_in_fp32': residual_in_fp32
}
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 MBlock — 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 MBlock 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

Also present in other papers' code

Of 1 samples lifted from this paper's linked repositories, 1 carry a function identity and 0 do not. Of the 1 distinct functions with an identity, 0 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 0 later) and 1 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-22.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

Efficiently modeling sequences with infinite context length has long been a challenging problem. Previous approaches have either suffered from quadratic computational complexity or limited extrapolation ability in length generalization. In this work, we present SAMBA, a simple hybrid architecture that layer-wise combines Mamba, a selective State Space Model (SSM), with Sliding Window Attention (SWA). SAMBA selectively compresses a given sequence into recurrent hidden states while still maintaining the ability to precisely recall recent memories with the attention mechanism. We scale SAMBA up to 3.8B parameters with 3.2T training tokens and demonstrate that it significantly outperforms state-of-the-art models across a variety of benchmarks. Pretrained on sequences of 4K length, SAMBA shows improved perplexity in context lengths of up to 1M in zero-shot. When finetuned on 4K-length sequences, SAMBA efficiently extrapolates to a 256K context length with perfect memory recall on the Passkey Retrieval task, and exhibits superior retrieval extrapolation on the challenging Phonebook task compared to full-attention models. As a linear-time sequence model, SAMBA achieves a 3.73× higher throughput compared to Transformers with grouped-query attention for user prompts of 128K length, and a 3.64× speedup when generating 64K tokens with unlimited streaming. Our code for training on open source data is publicly available at https://github.com/microsoft/Samba.

For agents

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

get_harvested_code_for_paper("2406.07522")
get_code_for_paper("2406.07522")
have("2406.07522")

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

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

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

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

Connect an agent — have() is free.