SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2509.19633 · NeurIPS · 2025

Mamba Modulation On the Length Generalization of Mamba

Yufei Cui, Boxing Chen, Philippe Langlais, Xinyu Wang, Qiuhao Zeng, Jerry Huang, Peng Lu

arXiv · PDF · Open in the Atlas

Code that ran

11 of 12 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; 2 honoured the contract we drafted, 1 violated it and 0 have no contract verdict; 8 failures of our instrument; 1 no recorded run), measured 2026-11-23; 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/2509.19633.json · badge: /api/ran/2509.19633.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
gnepul-ace/mamba_modulation canonical (classifier label)
classifier basis: census
11 ran · 1 no recorded run
FunctionStatusWhere it lives
build_chat Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
gnepul-ace/mamba_modulation/Mamba/LongBench/pred.py
code served (permissive licence) · get_code("324506640e971548")
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 str. 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

# Create mock tokenizers for different model types
class ChatGLM3Tokenizer:
    def build_chat_input(self, prompt):
        return f"chatglm3_processed: {prompt}"

class ChatGLMTokenizer:
    def build_prompt(self, prompt):
        return f"chatglm_processed: {prompt}"

class DefaultTokenizer:
    pass

# Test with chatglm3 model
tokenizer_chatglm3 = ChatGLM3Tokenizer()
prompt_text = "Hello, how are you?"
model_name_chatglm3 = "chatglm3-6b"

ARGS = {
    "tokenizer": tokenizer_chatglm3,
    "prompt": prompt_text,
    "model_name": model_name_chatglm3
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
fastchat, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str 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
calc_grad_norm Ran
ran, honoured the contract we drafted
gnepul-ace/mamba_modulation/Mamba/PasskeyRetrieval/utils.py
code served (permissive licence) · get_code("46f8dfafbbb8c9b2")
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 0, dtype family float, shape () 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

torch.manual_seed(0)

class SimpleModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear1 = nn.Linear(4, 3)
        self.linear2 = nn.Linear(3, 2)
    
    def forward(self, x):
        x = self.linear1(x)
        x = self.linear2(x)
        return x

model = SimpleModel()

# Create a dummy forward pass and compute loss to generate gradients
x = torch.randn(2, 4)
y = torch.randn(2, 2)
output = model(x)
loss = torch.nn.functional.mse_loss(output, y)
loss.backward()

ARGS = {
    "model": model
}
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 0, dtype family float, shape () — shape () 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
calc_mean_entropy Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
gnepul-ace/mamba_modulation/Mamba/PasskeyRetrieval/utils.py
code served (permissive licence) · get_code("91336ac6a4247b60")
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 0, dtype family float, shape () 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)

# The function expects predicted_logits to be a 3D tensor
# It reshapes to (-1, vocab_size), so shape should be (batch, seq_len, vocab_size)
# Using batch=2, seq_len=3, vocab_size=4 for distinct dimensions
predicted_logits = torch.randn(2, 3, 4)

ARGS = {
    "predicted_logits": predicted_logits
}
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 0, dtype family float, shape () — shape () 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
count_score Ran
ran, honoured the contract we drafted
gnepul-ace/mamba_modulation/Mamba/LongBench/metrics.py
pointer only (licence: MIT); the stored copy get_code serves, from borealisai/radar-decoding, is pointer only (licence: LGPL-3.0) · get_code("b349b79d9cc2934b")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from borealisai/radar-decoding, and LGPL-3.0, as GitHub detects it on that repository, is not in the permissive set Syntology serves inline. 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.

init_t Ran
ran; our contract draft was wrong, not the code
gnepul-ace/mamba_modulation/Mamba/PasskeyRetrieval/finetune_ssm.py
code served (permissive licence) · get_code("c28f8a171756d1ea")
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

torch.manual_seed(0)

# Build a minimal model that has parameters with 'dt_ptoj.weight' in the name
class MinimalModel(nn.Module):
    def __init__(self):
        super().__init__()
        # Create a parameter with 'dt_ptoj.weight' in its name
        self.dt_ptoj = nn.Linear(4, 3)
        # Add another one to test the counter increment
        self.other_dt_ptoj = nn.Linear(3, 2)
    
    def forward(self, x):
        return x

model = MinimalModel()

# Create a dictionary to store the parameters
# The function expects a dict-like object where it can assign parameters by index
t = {}

ARGS = {
    'model': model,
    't': t
}
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 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
load_config Ran
ran; our contract draft was wrong, not the code
gnepul-ace/mamba_modulation/Mamba/PasskeyRetrieval/utils.py
code served (permissive licence) · get_code("7c9375e7379c1087")
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 json
import tempfile
import os

# Create temporary directory and config files
temp_dir = tempfile.mkdtemp()
configs_dir = os.path.join(temp_dir, 'configs')
os.makedirs(configs_dir, exist_ok=True)

# Create eval config files
for i in range(3):
    eval_config = {
        'model_device': 'cpu',
        'model_name': f'eval_model_{i}',
        'learning_rate': 0.001
    }
    with open(os.path.join(configs_dir, f'eval_ssm_config_{i}.json'), 'w') as f:
        json.dump(eval_config, f)

# Create finetune config file
finetune_config = {
    'model_device': 'cpu',
    'model_name': 'finetune_model',
    'learning_rate': 0.0001
}
with open(os.path.join(configs_dir, 'finetune_ssm_config.json'), 'w') as f:
    json.dump(finetune_config, f)

# Change to temp directory so relative paths work
original_dir = os.getcwd()
os.chdir(temp_dir)

# Create a simple args class
class Args:
    def __init__(self, eval=-1, device='None'):
        self.eval = eval
        self.device = device

# Define ARGS for eval mode (eval != -1)
ARGS = {'args': Args(eval=0, device='None')}
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 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
normalize_answer Ran
ran; our contract draft was wrong, not the code
gnepul-ace/mamba_modulation/Mamba/LongBench/metrics.py
pointer only (licence: MIT); the stored copy get_code serves, from borealisai/radar-decoding, is pointer only (licence: LGPL-3.0) · get_code("e7e75981cb464788")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from borealisai/radar-decoding, and LGPL-3.0, as GitHub detects it on that repository, is not in the permissive set Syntology serves inline. 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.

normalize_zh_answer Ran
ran; our contract draft was wrong, not the code
gnepul-ace/mamba_modulation/Mamba/LongBench/metrics.py
pointer only (licence: MIT); the stored copy get_code serves, from borealisai/radar-decoding, is pointer only (licence: LGPL-3.0) · get_code("8c5c581f9264c810")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from borealisai/radar-decoding, and LGPL-3.0, as GitHub detects it on that repository, is not in the permissive set Syntology serves inline. 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.

parse_args Ran
ran; our contract draft was wrong, not the code
gnepul-ace/mamba_modulation/Mamba/LongBench/pred.py
code served (permissive licence) · get_code("51a46c0ad37271aa")
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 Namespace. 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 argparse

# Create a minimal valid arguments configuration
ARGS = {
    'args': [
        '--model', 'test_model',
        '--task', 'qasper'
    ]
}

# Alternative: return None to use all defaults
# ARGS = {
#     'args': None
# }

# Or with boolean flags
# ARGS = {
#     'args': [
#         '--model', 'test_model',
#         '--e',
#         '--mambaextend',
#         '--task', 'hotpotqa'
#     ]
# }
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
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 Namespace — a Namespace output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a Namespace 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
post_process Ran
ran, violated the contract we drafted
gnepul-ace/mamba_modulation/Mamba/LongBench/pred.py
code served (permissive licence) · get_code("4489113b536ca6eb")
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 str. 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)

# The function post_process takes two parameters:
# 1. response: a string that gets processed based on model_name
# 2. model_name: a string used to determine which processing branch to take

# Test case 1: xgen model
response_xgen = "Some response text\nAssistant: This is the assistant response"
model_name_xgen = "xgen-7b"

# Test case 2: internlm model
response_internlm = "Some response<eoa>This should be removed"
model_name_internlm = "internlm-chat"

# Test case 3: other model (no special processing)
response_other = "Just a regular response"
model_name_other = "gpt2"

# We'll use the xgen case as the primary test
ARGS = {
    "response": "Some response text\nAssistant: This is the assistant response",
    "model_name": "xgen-7b"
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str 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
set_min Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
gnepul-ace/mamba_modulation/Mamba/PasskeyRetrieval/finetune_ssm.py
code served (permissive licence) · get_code("4f66b16871415955")
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 ndarray, ndim 1, dtype family float, shape (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 numpy as np

torch.manual_seed(0)

# The function set_min takes an array and modifies it in-place,
# setting any values below val1 to val1.
# It iterates through the array with enumerate and checks if x < val1.
# The array parameter should be something that supports indexing and iteration.

# Create a simple numpy array as the array parameter
array = np.array([0.001, 0.5, 0.02, 2.0, 0.005])

# val1 is the threshold value (default 0.01)
val1 = 0.01

# val2 is defined but never used in the function body
val2 = 1.0

ARGS = {
    "array": array,
    "val1": val1,
    "val2": val2
}
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 ndarray, ndim 1, dtype family float, shape (5,) — shape (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
function_ Not yet run
unverified (harvested, no recorded run)
gnepul-ace/mamba_modulation/Mamba/PasskeyRetrieval/modeling/mamba_module.py
code served (permissive licence) · get_code("b0cb65c5d1c5516c")
How it ran

no invocation recorded.

Also present in other papers' code

Of 12 samples lifted from this paper's linked repositories, 12 carry a function identity and 0 do not. Of the 12 distinct functions with an identity, 7 are also present in other papers whose code we hold (7 with at least one paper dated earlier, 0 the same month, 5 later) and 5 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
normalize_answer 133 other papers
108 dated earlier, 18 later, 6 same year, order not determinable, 1 undated · 1 only as an assembly brick
1508.06615 (2015-08)
Character-Aware Neural Language Models
1606.05250 (2016-06)
SQuAD: 100,000+ Questions for Machine Comprehension of Text
1608.07905 (2016-08)
Machine Comprehension Using Match-LSTM and Answer Pointer
and 130 more not named here
normalize_zh_answer 28 other papers
23 dated earlier, 2 later, 2 same year, order not determinable, 1 undated
2311.04934 (2023-11)
Prompt Cache: Modular Attention Reuse for Low-Latency Inference
2311.09198 (2023-11)
Never Lost in the Middle: Mastering Long-Context Question Answering with Position-Agnostic Decompositional Training
2024.findings-emnlp.230 (2024 (year only))
CLongEval: A Chinese Benchmark for Evaluating Long-Context Large Language Models
and 25 more not named here
count_score 24 other papers
19 dated earlier, 2 later, 2 same year, order not determinable, 1 undated
2311.04934 (2023-11)
Prompt Cache: Modular Attention Reuse for Low-Latency Inference
2311.09198 (2023-11)
Never Lost in the Middle: Mastering Long-Context Question Answering with Position-Agnostic Decompositional Training
2402.02750 (2024-02)
KIVI: A Tuning-Free Asymmetric 2bit Quantization for KV Cache
and 21 more not named here
post_process 14 other papers
10 dated earlier, 2 later, 2 same year, order not determinable
2311.09198 (2023-11)
Never Lost in the Middle: Mastering Long-Context Question Answering with Position-Agnostic Decompositional Training
2402.02750 (2024-02)
KIVI: A Tuning-Free Asymmetric 2bit Quantization for KV Cache
2404.14469 (2024-04)
SnapKV: LLM Knows What You are Looking for Before Generation
and 11 more not named here
build_chat 4 other papers
2 dated earlier, 1 later, 1 same year, order not determinable
2406.10774 (2024-06)
Quest: Query-Aware Sparsity for Efficient Long-Context LLM Inference
2410.13846 (2024-10)
LightTransfer: Your Long-Context LLM is Secretly a Hybrid Model with Effortless Adaptation
2025.emnlp-main.443 (2025 (year only))
A Training-Free Length Extrapolation Approach for LLMs: Greedy Attention Logit Interpolation
and 1 more not named here
calc_grad_norm 1 other paper
1 dated earlier
2312.03631 (2023-12)
Mitigating Open-Vocabulary Caption Hallucinations
calc_mean_entropy 1 other paper
1 dated earlier
2312.03631 (2023-12)
Mitigating Open-Vocabulary Caption Hallucinations

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

The quadratic complexity of the attention mechanism in Transformer models has motivated the development of alternative architectures with sub-quadratic scaling, such as state-space models. Among these, Mamba has emerged as a leading architecture, achieving state-of-the-art results across a range of language modeling tasks. However, Mamba's performance significantly deteriorates when applied to contexts longer than those seen during pre-training, revealing a sharp sensitivity to context length extension. Through detailed analysis, we attribute this limitation to the out-of-distribution behavior of its state-space dynamics, particularly within the parameterization of the state transition matrix A. Unlike recent works which attribute this sensitivity to the vanished accumulation of discretization time steps, exp(-N t=1 ∆ t ), we establish a connection between state convergence behavior as the input length approaches infinity and the spectrum of the transition matrix A, offering a well-founded explanation of its role in length extension. Next, to overcome this challenge, we propose an approach that applies spectrum scaling to pre-trained Mamba models to enable robust long-context generalization by selectively modulating the spectrum of A matrices in each layer. We show that this can significantly improve performance in settings where simply modulating ∆ t fails, validating our insights and providing avenues for better length generalization of state-space models with structured transition matrices. Our code is available at https://github.com/gnepul-ace/mamba_modulation.

For agents

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

get_harvested_code_for_paper("2509.19633")
get_code_for_paper("2509.19633")
have("2509.19633")

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

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

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

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

Connect an agent — have() is free.