SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2407.09941 · 2024

Hydra: Bidirectional State Space Models Through Generalized Matrix Mixers

arXiv · PDF · Open in the Atlas

Code that ran

9 of 10 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; 1 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/2407.09941.json · badge: /api/ran/2407.09941.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
goombalab/hydra canonical (classifier label)
classifier basis: census
9 ran · 1 no recorded run
FunctionStatusWhere it lives
build_dataloader Ran
ran; our contract draft was wrong, not the code
goombalab/hydra/hydra/bert/src/convert_dataset.py
code served (permissive licence) · get_code("eb04bca046263ad3")
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 DataLoader. 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 platform
from torch.utils.data import DataLoader, IterableDataset

torch.manual_seed(0)

# Create a minimal dataset class with the required hf_dataset attribute
class MockHFDataset:
    def __init__(self, n_shards=4):
        self.n_shards = n_shards

class MockDataset(IterableDataset):
    def __init__(self):
        self.hf_dataset = MockHFDataset(n_shards=4)
        self.data = [(torch.randn(4), torch.randint(0, 2, (1,))) for _ in range(8)]
    
    def __iter__(self):
        return iter(self.data)
    
    def __len__(self):
        return len(self.data)

# Create instances
dataset = MockDataset()
batch_size = 2

ARGS = {
    "dataset": dataset,
    "batch_size": batch_size,
}
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 DataLoader — a DataLoader output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a DataLoader 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
build_hf_dataset Ran
ran; our contract draft was wrong, not the code
goombalab/hydra/hydra/bert/src/convert_dataset.py
code served (permissive licence) · get_code("926142a87d625531")
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 ConcatTokensDataset. 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
from enum import Enum
from unittest.mock import Mock, MagicMock
from transformers import AutoTokenizer

# Create a minimal mock tokenizer
class MockTokenizer:
    def __call__(self, text, truncation=False, padding=False, add_special_tokens=False):
        # Return mock token ids based on text length
        token_count = max(1, len(text) // 5) if text else 1
        return {'input_ids': list(range(token_count))}

# Create a mock HuggingFace dataset
class MockHFDataset:
    def __init__(self):
        self.data = [
            {'text': 'Sample text one'},
            {'text': 'Sample text two'},
            {'text': 'Sample text three'},
        ]
        self.index = 0
    
    def __iter__(self):
        return iter(self.data)

# Mock the datasets.load_dataset function
import datasets as hf_datasets
original_load_dataset = hf_datasets.load_dataset

def mock_load_dataset(path, name=None, split=None, streaming=False):
    return MockHFDataset()

hf_datasets.load_dataset = mock_load_dataset

# Define ConcatMode enum
class ConcatMode(Enum):
    NO_CONCAT = 'NO_CONCAT'
    CONCAT_TOKENS = 'CONCAT_TOKENS'

ARGS = {
    'dataset_name': 'wikitext',
    'split': 'train',
    'mode': ConcatMode.CONCAT_TOKENS,
    'max_length': 512,
    'bos_text': '<|endoftext|>',
    'eos_text': '<|endoftext|>',
    'no_wrap': False,
    'tokenizer': MockTokenizer(),
    'data_subset': None,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
datasets, numpy, torch, transformers — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type ConcatTokensDataset — a ConcatTokensDataset output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a ConcatTokensDataset 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
build_tokenizer Ran
ran; our contract draft was wrong, not the code
goombalab/hydra/hydra/bert/src/text_data.py
code served (permissive licence) · get_code("9d30f2c46fd5058c")
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 MagicMock. 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
from omegaconf import DictConfig, OmegaConf
from unittest.mock import MagicMock, patch

# Create a mock tokenizer that mimics PreTrainedTokenizer behavior
mock_tokenizer = MagicMock()
mock_tokenizer.model_max_length = 512

# Patch AutoTokenizer.from_pretrained to return our mock tokenizer
def mock_from_pretrained(name, **kwargs):
    return mock_tokenizer

om_tokenizer_config = OmegaConf.create({
    'name': 'bert-base-uncased',
    'kwargs': {
        'model_max_length': 1024
    }
})

ARGS = {
    'om_tokenizer_config': om_tokenizer_config
}

# Apply patch for the actual execution
import transformers
transformers.AutoTokenizer.from_pretrained = mock_from_pretrained
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, omegaconf, torch, transformers — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type MagicMock — a MagicMock output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a MagicMock output the recorded ndim 1 and dtype family None 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
chunk_flip_join Ran
ran; our contract draft was wrong, not the code
goombalab/hydra/hydra/modules/ops.py
code served (permissive licence) · get_code("cf5a3cf27216350f")
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 3, dtype family float, shape (2, 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

torch.manual_seed(0)

# Create a small tensor with distinct dimensions
# Shape: (2, 4, 3) - batch size 2, will be chunked along dim 1, last dim 3
input_tensor = torch.randn(2, 8, 3)

# Test with 'sum' operation
ARGS = {
    'input': input_tensor,
    'dim': 1,
    'op': 'sum'
}
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 3, dtype family float, shape (2, 4, 3) — shape (2, 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
flip Ran
ran; our contract draft was wrong, not the code
goombalab/hydra/hydra/modules/ops.py
code served (permissive licence) · get_code("0f0e92d1bd67e314")
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 3, dtype family float, shape (2, 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

torch.manual_seed(0)

# The function takes a single parameter 'input' which should be a tensor
# It calls torch.flip on dims=(1,), so input needs at least 2 dimensions
# Keep it small: batch size 2, some other dimensions
input_tensor = torch.randn(2, 4, 3)

ARGS = {
    "input": input_tensor
}
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 3, dtype family float, shape (2, 4, 3) — shape (2, 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
init_to_zero Ran
ran; our contract draft was wrong, not the code
goombalab/hydra/hydra/bert/src/flash_attn_triton.py
pointer only (licence: MIT); the stored copy get_code serves, from amazon-science/dualkv-flash-attn-for-rl, is pointer only (licence: NOASSERTION) · get_code("1586b639a5abd0b0")
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 amazon-science/dualkv-flash-attn-for-rl, and GitHub could not classify the licence of that repository (NOASSERTION). 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.

pad_input Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
goombalab/hydra/hydra/bert/src/bert_padding.py
code served (permissive licence) · get_code("b166dc11d0f54137")
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 3, dtype family float, shape (2, 3, 4) as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
from einops import rearrange

torch.manual_seed(0)

# Parameters for pad_input function
batch = 2
seqlen = 3
hidden_dim = 4

# Create total_nnz (total number of non-zero/selected tokens)
# Let's say we select 4 tokens across the batch
total_nnz = 4

# hidden_states: (total_nnz, hidden_dim)
# This represents flattened selected tokens from attention mask
hidden_states = torch.randn(total_nnz, hidden_dim)

# indices: (total_nnz,)
# These map the flattened tokens back to their positions in the padded (batch*seqlen) output
# Valid indices should be in range [0, batch*seqlen)
indices = torch.tensor([0, 2, 3, 5], dtype=torch.long)

ARGS = {
    "hidden_states": hidden_states,
    "indices": indices,
    "batch": batch,
    "seqlen": seqlen,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
einops, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type 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: none by the harness; any seed is in the setup block
unpad_input Ran
ran; our contract draft was wrong, not the code
goombalab/hydra/hydra/bert/src/bert_padding.py
code served (permissive licence) · get_code("ee341a843ab02d5f")
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 torch.nn.functional as F
from einops import rearrange, repeat

torch.manual_seed(0)

# Create small tensors for testing
batch_size = 2
seq_len = 3
hidden_dim = 4

# Create hidden_states: (batch, seqlen, hidden_dim)
hidden_states = torch.randn(batch_size, seq_len, hidden_dim)

# Create attention_mask: (batch, seqlen)
# Using 1 for valid tokens and 0 for padding
attention_mask = torch.tensor([
    [1, 1, 0],  # batch 0: 2 valid tokens
    [1, 0, 0]   # batch 1: 1 valid token
], dtype=torch.bool)

ARGS = {
    "hidden_states": hidden_states,
    "attention_mask": attention_mask
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
einops, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type 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
unpad_input_only Ran
ran; our contract draft was wrong, not the code
goombalab/hydra/hydra/bert/src/bert_padding.py
code served (permissive licence) · get_code("e7df9e4a71a03583")
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 2, dtype family float, shape (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
from einops import rearrange, repeat

torch.manual_seed(0)

# Create small tensors for testing
batch_size = 2
seq_len = 3
hidden_dim = 4

# hidden_states: (batch, seqlen, hidden_dim)
hidden_states = torch.randn(batch_size, seq_len, hidden_dim)

# attention_mask: (batch, seqlen), bool / int, 1 means valid and 0 means not valid
# Create a mask where some tokens are valid (1) and some are not (0)
attention_mask = torch.tensor([
    [1, 0, 1],
    [1, 1, 0]
], dtype=torch.long)

ARGS = {
    "hidden_states": hidden_states,
    "attention_mask": attention_mask
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
einops, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 2, dtype family float, shape (4, 4) — shape (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: none by the harness; any seed is in the setup block
dwconv Not yet run
unverified (harvested, no recorded run)
goombalab/hydra/hydra/modules/ops.py
code served (permissive licence) · get_code("835f9b2b7b3d246e")
How it ran

no invocation recorded.

Also present in other papers' code

Of 10 samples lifted from this paper's linked repositories, 10 carry a function identity and 0 do not. Of the 10 distinct functions with an identity, 6 are also present in other papers whose code we hold (4 with at least one paper dated earlier, 1 the same month, 6 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
init_to_zero 12 other papers
7 dated earlier, 2 the same month, 3 later
2304.11277 (2023-04)
PyTorch FSDP: Experiences on Scaling Fully Sharded Data Parallel
2309.06180 (2023-09)
Efficient Memory Management for Large Language Model Serving with PagedAttention
2310.05869 (2023-10)
HyperAttention: Long-context Attention in Near-Linear Time
and 9 more not named here
pad_input 6 other papers
4 dated earlier, 2 later
2108.12409 (2021-08)
Train Short, Test Long: Attention with Linear Biases Enables Input Length Extrapolation
2306.15006 (2023-06)
DNABERT-2: EFFICIENT FOUNDATION MODEL AND BENCHMARK FOR MULTI-SPECIES GENOMES
2311.12570 (2023-11)
BEND: Benchmarking DNA Language Models on biologically meaningful tasks
and 3 more not named here
unpad_input 5 other papers
3 dated earlier, 2 later
2306.15006 (2023-06)
DNABERT-2: EFFICIENT FOUNDATION MODEL AND BENCHMARK FOR MULTI-SPECIES GENOMES
2311.12570 (2023-11)
BEND: Benchmarking DNA Language Models on biologically meaningful tasks
2402.08777 (2024-02)
DNABERT-S: Pioneering Species Differentiation with Species-Aware DNA Embeddings
and 2 more not named here
unpad_input_only 2 other papers
1 dated earlier, 1 later
2108.12409 (2021-08)
Train Short, Test Long: Attention with Linear Biases Enables Input Length Extrapolation
2601.05776 (2026-01)
One Script Instead of Hundreds? On Pretraining Romanized Encoder Language Models
build_dataloader 1 other paper
1 later
2601.05776 (2026-01)
One Script Instead of Hundreds? On Pretraining Romanized Encoder Language Models
build_hf_dataset 1 other paper
1 later
2601.05776 (2026-01)
One Script Instead of Hundreds? On Pretraining Romanized Encoder Language Models

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

A wide array of sequence models are built on a framework modeled after Transformers, comprising alternating sequence mixer and channel mixer layers. This paper studies a unifying matrix mixer view of sequence mixers that can be conceptualized as a linear map on the input sequence. This framework encompasses a broad range of well-known sequence models, including the self-attention of Transformers as well as recent strong alternatives such as structured state space models (SSMs), and allows understanding downstream characteristics such as efficiency and expressivity through properties of their structured matrix class. We identify a key axis of matrix parameterizations termed sequence alignment, which increases the flexibility and performance of matrix mixers, providing insights into the strong performance of Transformers and recent SSMs such as Mamba. Furthermore, the matrix mixer framework offers a systematic approach to developing sequence mixers with desired properties, allowing us to develop several new sub-quadratic sequence models. In particular, we propose a natural bidirectional extension of the Mamba model (Hydra), parameterized as a quasiseparable matrix mixer, which demonstrates superior performance over other sequence models including Transformers on non-causal tasks. As a drop-in replacement for attention layers, Hydra outperforms BERT by 0.8 points on the GLUE benchmark and ViT by 2% Top-1 accuracy on ImageNet.

For agents

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

get_harvested_code_for_paper("2407.09941")
get_code_for_paper("2407.09941")
have("2407.09941")

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

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

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

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

Connect an agent — have() is free.