SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2405.08553 · ICML · 2024

Improving Transformers with Dynamically Composable Multi-Head Attention

Da Xiao, Qingye Meng, Shengping Li, Xingyuan Yuan

arXiv · PDF · Open in the Atlas

Code that ran

9 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; 1 honoured the contract we drafted, 1 violated it and 0 have no contract verdict; 7 failures of our instrument; 3 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/2405.08553.json · badge: /api/ran/2405.08553.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
caiyun-ai/dcformer canonical (classifier label)
classifier basis: census
6 ran · 3 no recorded run
Caiyun-AI/DCFormer canonical (classifier label)
classifier basis: classifier_2025
3 ran · 0 no recorded run
FunctionStatusWhere it lives
accuracy Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
Caiyun-AI/DCFormer/pytorch/dcformer/run_clm_pt_dcformer.py
code served (permissive licence) · get_code("8a38d7c525fad8f1")
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 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 numpy as np
from sklearn.metrics import accuracy_score

torch.manual_seed(0)

# Create small sample predictions and references
# These should be class labels (integers or strings)
predictions = np.array([0, 1, 1, 0, 1, 2])
references = np.array([0, 1, 0, 0, 1, 2])

# Create sample weights (optional parameter)
sample_weight = np.array([1.0, 1.0, 1.0, 1.0, 1.0, 1.0])

ARGS = {
    'predictions': predictions,
    'references': references,
    'normalize': True,
    'sample_weight': sample_weight
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
numpy, sklearn, 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
compute_metrics Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
Caiyun-AI/DCFormer/pytorch/dcformer/run_clm_pt_dcformer.py
code served (permissive licence) · get_code("6b376a0abe58a427")
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 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 numpy as np

torch.manual_seed(0)

# The function compute_metrics expects eval_preds which is a tuple of (preds, labels)
# Looking at the function body:
# - labels has shape [..., sequence_length] and we take [:, 1:] then reshape to 1D
# - preds has shape [..., sequence_length] and we take [:, :-1] then reshape to 1D
# Both need to be reshaped to 1D arrays for accuracy_score

# Create batch_size=2, sequence_length=4
batch_size = 2
sequence_length = 4

# preds: shape (2, 4) - logits or predictions
# After [:, :-1] -> (2, 3) -> reshape(-1) -> (6,)
preds = np.random.randint(0, 2, size=(batch_size, sequence_length))

# labels: shape (2, 4) - ground truth labels
# After [:, 1:] -> (2, 3) -> reshape(-1) -> (6,)
labels = np.random.randint(0, 2, size=(batch_size, sequence_length))

# eval_preds is a tuple of (preds, labels)
eval_preds = (preds, labels)

ARGS = {
    'eval_preds': eval_preds
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
numpy, sklearn, 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
extract_dtype_callable Ran
ran; our contract draft was wrong, not the code
caiyun-ai/dcformer/pytorch/dcformer/modeling_dcformer.py
code served (permissive licence) · get_code("d5a3e6a05d912f0a")
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

torch.manual_seed(0)

# The function takes a single parameter: dtype
# Looking at the function body:
# - It checks if dtype is a string (note: there's a bug in the code - it checks `type` instead of `dtype`)
# - It returns the dtype as-is if not a string
# - If it's a string, it parses it and returns the corresponding torch dtype

# Test case 1: passing a string that contains 'bfloat16'
dtype_string = 'bfloat16'

ARGS = {
    'dtype': dtype_string
}
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 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
find_multiple Ran
ran, honoured the contract we drafted
caiyun-ai/dcformer/pytorch/dcformer/modeling_dcformer.py
code served (permissive licence) · get_code("aba86ffbed27ba65")
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 int, ndim 0, dtype family int, 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 numpy as np

torch.manual_seed(0)

def find_multiple(n: int, k: int) -> int:
    if n % k == 0:
        return n
    return n + k - n % k

# The function takes two integers and returns an integer
# It finds the next multiple of k that is >= n
ARGS = {
    "n": 17,
    "k": 5
}
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 int, ndim 0, dtype family int, 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
load_model Ran
ran; our contract draft was wrong, not the code
caiyun-ai/dcformer/pytorch/dcformer/maxtext2torch.py
code served (permissive licence) · get_code("f313d5feb241ec85")
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 tempfile
import shutil
import os
import jax
import jax.numpy as jnp
from flax import linen as nn
from flax.core import freeze, unfreeze
import orbax.checkpoint

# Create a temporary directory for checkpoint storage
temp_dir = tempfile.mkdtemp()

# Create a minimal model state structure
def create_test_state():
    params = {
        'layer1': {
            'kernel': jnp.ones((4, 3), dtype=jnp.float32),
            'bias': jnp.zeros((3,), dtype=jnp.float32),
        },
        'layer2': {
            'kernel': jnp.ones((3, 2), dtype=jnp.float32),
            'bias': jnp.zeros((2,), dtype=jnp.float32),
        }
    }
    return {'params': params}

# Create and save a checkpoint
state = create_test_state()
checkpointer = orbax.checkpoint.Checkpointer(
    orbax.checkpoint.PyTreeCheckpointHandler(use_ocdbt=False)
)
options = orbax.checkpoint.CheckpointManagerOptions()
mngr = orbax.checkpoint.CheckpointManager(
    temp_dir,
    {'state': checkpointer},
    options
)

# Save checkpoint at step 0
mngr.save(0, {'state': state})

# Define ARGS
ARGS = {
    'read_dir': temp_dir,
    'load_step': None,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
flax, jax, orbax — 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
make_window_mask Ran
ran, violated the contract we drafted
caiyun-ai/dcformer/pytorch/dcformer/modeling_dcformer.py
code served (permissive licence) · get_code("dccbfeb9dc59e07a")
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 (5, 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

torch.manual_seed(0)

ARGS = {
    "t": 5,
    "window_size": 2
}
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 2, dtype family float, shape (5, 5) — shape (5, 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
rename_columns Ran
ran; our contract draft was wrong, not the code
Caiyun-AI/DCFormer/pytorch/dcformer/run_clm_pt_dcformer.py
code served (permissive licence) · get_code("d478a1bd852b034a")
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 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

torch.manual_seed(0)

def rename_columns(example):
    example['idx'] = example.pop('input_ids')
    example.pop('token_type_ids')
    example.pop('attention_mask')
    return example

example = {
    'input_ids': torch.tensor([[101, 2054, 2003, 102]]),
    'token_type_ids': torch.tensor([[0, 0, 0, 0]]),
    'attention_mask': torch.tensor([[1, 1, 1, 1]]),
}

ARGS = {
    'example': example
}
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 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
rename_columns Ran
ran; our contract draft was wrong, not the code
caiyun-ai/dcformer/pytorch/dcformer/run_clm_sft_dcformer.py
code served (permissive licence) · get_code("6cd8ea4949f52b54")
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

def rename_columns(example):
    example['idx'] = example.pop('input_ids')
    return example

# Construct a minimal valid example dict
# The function expects a dict with 'input_ids' key
example = {
    'input_ids': torch.tensor([1, 2, 3, 4]),
    'other_field': 'some_value'
}

ARGS = {
    'example': example
}
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
slice_dw Ran
ran; our contract draft was wrong, not the code
caiyun-ai/dcformer/pytorch/dcpythia/modeling_dcpythia.py
code served (permissive licence) · get_code("590e68066c00cb10")
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

torch.manual_seed(0)

# Create small tensors for slicing operations
# The function slices along dimension 1 using start:stop for q tensors
# and kv_start:stop for k tensors

batch_size = 2
feature_dim = 4
seq_len = 6

sw = torch.randn(batch_size, feature_dim)
qw1 = torch.randn(batch_size, seq_len)
qw2 = torch.randn(batch_size, seq_len)
kw1 = torch.randn(batch_size, seq_len)
kw2 = torch.randn(batch_size, seq_len)
qdd = torch.randn(batch_size, seq_len)
kdd = torch.randn(batch_size, seq_len)

start = 1
stop = 4
kv_start = 2

ARGS = {
    "sw": sw,
    "qw1": qw1,
    "qw2": qw2,
    "kw1": kw1,
    "kw2": kw2,
    "qdd": qdd,
    "kdd": kdd,
    "start": start,
    "stop": stop,
    "kv_start": kv_start,
}
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 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
build_instruction_dataset Not yet run
unverified (harvested, no recorded run)
caiyun-ai/dcformer/pytorch/dcformer/build_dataset.py
code served (permissive licence) · get_code("bb033a34d8b49b9d")
How it ran

no invocation recorded.

get_system_characteristics Not yet run
unverified (harvested, no recorded run)
caiyun-ai/dcformer/jax/MaxText/accelerator_to_spec_map.py
code served (permissive licence) · get_code("87c57735e68651cc")
How it ran

no invocation recorded.

update_weight_from_maxtext Not yet run
unverified (harvested, no recorded run)
caiyun-ai/dcformer/pytorch/dcformer/maxtext2torch.py
code served (permissive licence) · get_code("19e80053090641bd")
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, 4 are also present in other papers whose code we hold (4 with at least one paper dated earlier, 0 the same month, 3 later) and 8 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
find_multiple 9 other papers
4 dated earlier, 5 later
2302.13971 (2023-02)
LLaMA: Open and Efficient Foundation Language Models
2310.06434 (2023-10)
Whispering LLaMA: A Cross-Modal Generative Error Correction Framework for Speech Recognition
2310.08278 (2023-10)
Lag-Llama: Towards Foundation Models for Probabilistic Time Series Forecasting
and 6 more not named here
accuracy 5 other papers
4 dated earlier, 1 later
2304.08177 (2023-04)
Efficient and Effective Text Encoding for Chinese LLaMA and Alpaca
2310.09089 (2023-10)
Qilin-Med: Multi-stage Knowledge Injection Advanced Medical Large Language Model
2402.16445 (2024-02)
ProLLaMA: A Protein Large Language Model for Multi-Task Protein Language Processing
and 2 more not named here
compute_metrics 3 other papers
3 dated earlier
2304.08177 (2023-04)
Efficient and Effective Text Encoding for Chinese LLaMA and Alpaca
2310.09089 (2023-10)
Qilin-Med: Multi-stage Knowledge Injection Advanced Medical Large Language Model
2402.16445 (2024-02)
ProLLaMA: A Protein Large Language Model for Multi-Task Protein Language Processing
get_system_characteristics 2 other papers
1 dated earlier, 1 later
2309.16588 (2023-09)
Vision Transformers Need Registers
2410.23168 (2024-10)
TokenFormer: Rethinking Transformer Scaling with Tokenized Model Parameters

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

Multi-Head Attention (MHA) is a key component of Transformer. In MHA, attention heads work independently, causing problems such as low-rank bottleneck of attention score matrices and head redundancy. We propose Dynamically Composable Multi-Head Attention (DCMHA), a parameter and computation efficient attention architecture that tackles the shortcomings of MHA and increases the expressive power of the model by dynamically composing attention heads. At the core of DCMHA is a Compose function that transforms the attention score and weight matrices in an input-dependent way. DCMHA can be used as a drop-in replacement of MHA in any transformer architecture to obtain the corresponding DCFormer. DCFormer significantly outperforms Transformer on different architectures and model scales in language modeling, matching the performance of models with 1.7×-2.0× compute. For example, DCPythia-6.9B outperforms open source Pythia-12B on both pretraining perplexity and downstream task evaluation. The code and models are available at https: //github.com/Caiyun-AI/DCFormer.

For agents

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

get_harvested_code_for_paper("2405.08553")
get_code_for_paper("2405.08553")
have("2405.08553")

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

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

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

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

Connect an agent — have() is free.