SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2408.15237 · NeurIPS · 2024

The Mamba in the Llama: Distilling and Accelerating Hybrid Models

Alexander Rush, Tri Dao, Daniele Paliotta, Junxiong Wang, Avner May

arXiv · PDF · Open in the Atlas

Code that ran

9 of 14 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 0 have no contract verdict; 9 failures of our instrument; 5 no recorded run); 1 of them was also run on the host, not in the jail, by the peer-agreement lane that set its level, 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/2408.15237.json · badge: /api/ran/2408.15237.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
itsdaniele/speculative_mamba canonical (classifier label)
classifier basis: census
6 ran · 5 no recorded run
jxiw/mambainllama canonical (classifier label)
classifier basis: census
3 ran · 0 no recorded run
FunctionStatusWhere it lives
repeat_kv Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
jxiw/mambainllama/mamba/hybrid_mamba_layer.py
code served (permissive licence) · get_code("3c76e52815c5401d")
How it ran

Ran in Syntology's jail 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, 6, 5, 4) as a later run recorded it. The image it ran in was not recorded. The comparison behind this sample's level is a different run: the peer-agreement lane ran it again on the host, not in the jail (report dated 2026-09-04T23:23:17Z). 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 small tensor with shape (batch, num_key_value_heads, seqlen, head_dim)
# Using distinct sizes: batch=2, num_key_value_heads=3, seqlen=5, head_dim=4
hidden_states = torch.randn(2, 3, 5, 4)

# n_rep is the repetition factor
n_rep = 2

ARGS = {
    "hidden_states": hidden_states,
    "n_rep": n_rep,
}
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, 6, 5, 4) — shape (2, 6, 5, 4) as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
construct_layer_dict Ran
ran; our contract draft was wrong, not the code
jxiw/mambainllama/util.py
code served (permissive licence) · get_code("e845d6cad3dda7eb")
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 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
import numpy as np

torch.manual_seed(0)

# Create a mock safetensors dictionary with model weights
safetensors_dict = {
    'model.layers.0.attention.q_proj.weight': torch.randn(4, 3),
    'model.layers.0.attention.k_proj.weight': torch.randn(4, 3),
    'model.layers.0.mlp.up_proj.weight': torch.randn(5, 4),
    'model.layers.1.mamba.in_proj.weight': torch.randn(6, 3),
    'model.layers.1.mamba.out_proj.weight': torch.randn(4, 6),
    'model.layers.2.attention.v_proj.weight': torch.randn(4, 3),
    'model.layers.2.mlp.down_proj.weight': torch.randn(3, 4),
}

num_hidden_layers = 3

ARGS = {
    'safetensors_dict': safetensors_dict,
    'num_hidden_layers': num_hidden_layers,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, 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: none by the harness; any seed is in the setup block
layer_norm_ref Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
itsdaniele/speculative_mamba/specmamba/ops/triton/layernorm.py
pointer only (licence: Apache-2.0); the stored copy get_code serves, from XsChen524/mode-mamba-ts, is pointer only (licence: NONE) · get_code("2ce8fcf5bedd19ec")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (Apache-2.0), but get_code serves the stored copy, first harvested from XsChen524/mode-mamba-ts, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

load_safetensors_to_dict Ran
ran; our contract draft was wrong, not the code
jxiw/mambainllama/util.py
code served (permissive licence) · get_code("72afeaae843bd353")
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 dict. 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
import os
import tempfile
from safetensors.torch import save_file

torch.manual_seed(0)

# Create a temporary directory with safetensors files
temp_dir = tempfile.mkdtemp()

# Create some sample tensors
tensor1 = torch.randn(2, 4)
tensor2 = torch.randn(3, 5)
tensor3 = torch.randn(2, 2)

# Save tensors as safetensors files
save_file({"weight": tensor1, "bias": tensor2}, os.path.join(temp_dir, "model_part1.safetensors"))
save_file({"embedding": tensor3}, os.path.join(temp_dir, "model_part2.safetensors"))

ARGS = {
    "directory": temp_dir
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
safetensors, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict 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
modify_logit_for_repetition_penalty Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
itsdaniele/speculative_mamba/specmamba/utils/generation.py
pointer only (licence: Apache-2.0); the stored copy get_code serves, from XsChen524/mode-mamba-ts, is pointer only (licence: NONE) · get_code("da95e9a7906f3d52")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (Apache-2.0), but get_code serves the stored copy, first harvested from XsChen524/mode-mamba-ts, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

rms_norm_ref Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
itsdaniele/speculative_mamba/specmamba/ops/triton/layernorm.py
pointer only (licence: Apache-2.0); the stored copy get_code serves, from XsChen524/mode-mamba-ts, is pointer only (licence: NONE) · get_code("ab802ae3195c6316")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (Apache-2.0), but get_code serves the stored copy, first harvested from XsChen524/mode-mamba-ts, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

sample Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
itsdaniele/speculative_mamba/specmamba/utils/generation.py
code served (permissive licence) · get_code("6629f11cee862c38")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Tensor, ndim 1, dtype family int, shape (2,) 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 small batch of logits: (batch_size=2, vocab_size=4)
logits = torch.randn(2, 4)

ARGS = {
    "logits": logits,
    "top_k": 2,
    "top_p": 0.9,
    "min_p": 0.1,
    "temperature": 1.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 Tensor, ndim 1, dtype family int, shape (2,) — shape (2,) 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
selective_scan_ref Ran
ran; our contract draft was wrong, not the code
itsdaniele/speculative_mamba/specmamba/ops/selective_scan_interface.py
code served (permissive licence) · get_code("ba7b868fec181b57")
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 3, dtype family float, shape (2, 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 torch.nn.functional as F

torch.manual_seed(0)

# Define dimensions
batch = 2
dim = 4
dstate = 3
seq_len = 5

# u: r(B D L) - input
u = torch.randn(batch, dim, seq_len)

# delta: r(B D L) - delta values
delta = torch.randn(batch, dim, seq_len)

# A: c(D N) or r(D N) - state transition matrix
A = torch.randn(dim, dstate)

# B: c(D N) or r(B N L) or r(B N 2L) or r(B G N L) or (B G N L)
# Using r(B N L) form
B = torch.randn(batch, dstate, seq_len)

# C: c(D N) or r(B N L) or r(B N 2L) or r(B G N L) or (B G N L)
# Using r(B N L) form
C = torch.randn(batch, dstate, seq_len)

# D: r(D) - optional feedthrough
D = torch.randn(dim)

# z: r(B D L) - optional gating
z = torch.randn(batch, dim, seq_len)

# delta_bias: r(D), fp32
delta_bias = torch.randn(dim, dtype=torch.float32)

# delta_softplus: bool
delta_softplus = False

# return_last_state: bool
return_last_state = False

ARGS = {
    "u": u,
    "delta": delta,
    "A": A,
    "B": B,
    "C": C,
    "D": D,
    "z": z,
    "delta_bias": delta_bias,
    "delta_softplus": delta_softplus,
    "return_last_state": return_last_state,
}
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 3, dtype family float, shape (2, 4, 5) — shape (2, 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
selective_state_update_ref Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
itsdaniele/speculative_mamba/specmamba/ops/triton/selective_state_update.py
pointer only (licence: Apache-2.0); the stored copy get_code serves, from XsChen524/mode-mamba-ts, is pointer only (licence: NONE) · get_code("c720b3f33d90d4f4")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (Apache-2.0), but get_code serves the stored copy, first harvested from XsChen524/mode-mamba-ts, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

decode Not yet run
unverified (harvested, no recorded run)
itsdaniele/speculative_mamba/specmamba/utils/generation.py
code served (permissive licence) · get_code("57563881caa239a8")
How it ran

no invocation recorded.

initialize_inference_params Not yet run
unverified (harvested, no recorded run)
itsdaniele/speculative_mamba/speculative_mamba/decode_speculative.py
code served (permissive licence) · get_code("3c9b265c08fe3b25")
How it ran

no invocation recorded.

load_config_hf Not yet run
unverified (harvested, no recorded run)
itsdaniele/speculative_mamba/specmamba/utils/hf.py
pointer only (licence: Apache-2.0); the stored copy get_code serves, from XsChen524/mode-mamba-ts, is pointer only (licence: NONE) · get_code("7a8ab4bf37f8fa41")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (Apache-2.0), but get_code serves the stored copy, first harvested from XsChen524/mode-mamba-ts, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. No invocation recorded.

load_state_dict_hf Not yet run
unverified (harvested, no recorded run)
itsdaniele/speculative_mamba/specmamba/utils/hf.py
code served (permissive licence) · get_code("7eb0983c186cde2e")
How it ran

no invocation recorded.

selective_state_update_multi_cached_ref Not yet run
unverified (harvested, no recorded run)
itsdaniele/speculative_mamba/specmamba/ops/triton/selective_state_update_multi_cached_fused.py
code served (permissive licence) · get_code("e2788fa7d179ea77")
How it ran

no invocation recorded.

Also present in other papers' code

Of 14 samples lifted from this paper's linked repositories, 14 carry a function identity and 0 do not. Of the 14 distinct functions with an identity, 10 are also present in other papers whose code we hold (7 with at least one paper dated earlier, 2 the same month, 10 later) and 4 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
repeat_kv 243 other papers
105 dated earlier, 8 the same month, 126 later, 2 same year, order not determinable, 2 undated · 22 only as an assembly brick
1901.02860 (2019-01)
Transformer-XL: Attentive Language Models Beyond a Fixed-Length Context
2203.08913 (2022-03)
Memorizing Transformers
2305.17888 (2023-05)
LLM-QAT: Data-Free Quantization Aware Training for Large Language Models
and 240 more not named here
selective_scan_ref 13 other papers
9 dated earlier, 4 later
2101.03961 (2021-01)
Switch Transformers: Scaling to Trillion Parameter Models with Simple and Efficient Sparsity
2402.05608 (2024-02)
Scalable Diffusion Models with State Space Backbone
2403.16899 (2024-03)
State Space Models as Foundation Models: A Control Theoretic Overview
and 10 more not named here
layer_norm_ref 8 other papers
4 dated earlier, 4 later
2403.16899 (2024-03)
State Space Models as Foundation Models: A Control Theoretic Overview
2406.02528 (2024-06)
Scalable MatMul-free Language Modeling
2406.03344 (2024-06)
Audio Mamba: Bidirectional State Space Model for Audio Representation Learning
and 5 more not named here
rms_norm_ref 8 other papers
4 dated earlier, 4 later
2403.16899 (2024-03)
State Space Models as Foundation Models: A Control Theoretic Overview
2406.02528 (2024-06)
Scalable MatMul-free Language Modeling
2406.03344 (2024-06)
Audio Mamba: Bidirectional State Space Model for Audio Representation Learning
and 5 more not named here
modify_logit_for_repetition_penalty 6 other papers
4 dated earlier, 1 the same month, 1 later
2403.16899 (2024-03)
State Space Models as Foundation Models: A Control Theoretic Overview
2406.03344 (2024-06)
Audio Mamba: Bidirectional State Space Model for Audio Representation Learning
2406.10700 (2024-06)
Voxel Mamba: Group-Free State Space Models for Point Cloud based 3D Object Detection
and 3 more not named here
load_config_hf 5 other papers
4 dated earlier, 1 later
2403.16899 (2024-03)
State Space Models as Foundation Models: A Control Theoretic Overview
2406.03344 (2024-06)
Audio Mamba: Bidirectional State Space Model for Audio Representation Learning
2406.10700 (2024-06)
Voxel Mamba: Group-Free State Space Models for Point Cloud based 3D Object Detection
and 2 more not named here
sample 4 other papers
3 dated earlier, 1 later
2403.16899 (2024-03)
State Space Models as Foundation Models: A Control Theoretic Overview
2406.10700 (2024-06)
Voxel Mamba: Group-Free State Space Models for Point Cloud based 3D Object Detection
2407.06136 (2024-07)
Mamba-FSCIL: Dynamic Adaptation with Selective State Space Model for Few-Shot Class-Incremental Learning
and 1 more not named here
construct_layer_dict 1 other paper
1 later
2503.13440 (2025-03)
MaTVLM: Hybrid Mamba-Transformer for Efficient Vision-Language Modeling
load_safetensors_to_dict 1 other paper
1 later
2503.13440 (2025-03)
MaTVLM: Hybrid Mamba-Transformer for Efficient Vision-Language Modeling
selective_state_update_ref 1 other paper
1 later
2601.00920 (2026-01)
MODE: Efficient Time Series Prediction with Mamba Enhanced by Low-Rank Neural ODEs

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

Linear RNN architectures, like Mamba, can be competitive with Transformer models in language modeling while having advantageous deployment characteristics. Given the focus on training large-scale Transformer models, we consider the challenge of converting these pretrained models for deployment. We demonstrate that it is feasible to distill large Transformers into linear RNNs by reusing the linear projection weights from attention layers with academic GPU resources. The resulting hybrid model, which incorporates a quarter of the attention layers, achieves performance comparable to the original Transformer in chat benchmarks and outperforms open-source hybrid Mamba models trained from scratch with trillions of tokens in both chat benchmarks and general benchmarks. Moreover, we introduce a hardware-aware speculative decoding algorithm that accelerates the inference speed of Mamba and hybrid models. Overall we show how, with limited computation resources, we can remove many of the original attention layers and generate from the resulting model more efficiently. Our top-performing model, distilled from Llama3-8B-Instruct, achieves a 29.61 length-controlled win rate on AlpacaEval 2 against GPT-4 and 7.35 on MT-Bench, surpassing the best 8B scale instruction-tuned linear RNN model. We also find that the distilled model has natural length extrapolation, showing almost perfect accuracy in the needle-in-a-haystack test at 20x the distillation length. Code and pre-trained checkpoints are open-sourced at

For agents

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

get_harvested_code_for_paper("2408.15237")
get_code_for_paper("2408.15237")
have("2408.15237")

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

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

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

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

Connect an agent — have() is free.