SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2310.07096 · EMNLP · 2023

Sparse Universal Transformer

Chuang Gan, Aaron Courville, Zhenfang Chen, Yikang Shen, Shawn Tan

arXiv · PDF · Open in the Atlas

Code that ran

3 of 5 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, 1 violated it and 2 have no contract verdict; 0 failures of our instrument; 2 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/2310.07096.json · badge: /api/ran/2310.07096.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
willGuimont/transformers community
Papers with Code archive
3 ran · 2 no recorded run
FunctionStatusWhere it lives
FeedForward Ran
ran on a synthesized input
willGuimont/transformers/nnet/transformers.py
code served (permissive licence) · get_code("b477c79d55a4468d")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) and returned Tensor, ndim 2, dtype family float, shape (2, 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
import torch.nn as nn

class FeedForward(nn.Module):

    def __init__(self, in_channel: int, mid_channels: int, out_channels: int, dropout: float):
        """
        Simple feed forward network
        :param in_channel: input channel
        :param mid_channels: number of hidden channels
        :param out_channels: output channel
        :param dropout: dropout rate
        """
        super().__init__()
        self.ffn = nn.Sequential(nn.Linear(in_channel, mid_channels), nn.GELU(), nn.Linear(mid_channels, out_channels), nn.Dropout(dropout))

    def forward(self, x):
        return self.ffn(x)


INIT_ARGS = {
    'in_channel': 4,
    'mid_channels': 8,
    'out_channels': 3,
    'dropout': 0.1
}

ARGS = {
    'x': torch.randn(2, 4)
}

if __name__ == '__main__':
    model = FeedForward(**INIT_ARGS)
    output = model(**ARGS)
    print(f"Output shape: {output.shape}")
    print(f"Expected shape: (2, 3)")
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
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 (2, 3) — shape (2, 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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
TransformerEncoderLayer Ran
ran on a synthesized input
willGuimont/transformers/nnet/transformers.py
code served (permissive licence) · get_code("8b47279d7dccc00f")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) 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
import torch.nn as nn

# Define initialization arguments for TransformerEncoderLayer
INIT_ARGS = {
    'd_model': 4,
    'n_head': 2,
    'dropout': 0.1,
    'multihead_bias': True,
    'norm_layer': nn.LayerNorm,
}

# Define forward pass arguments
ARGS = {
    'q': torch.randn(2, 3, 4),  # batch_size=2, seq_len=3, d_model=4
    'k': torch.randn(2, 3, 4),  # batch_size=2, seq_len=3, d_model=4
    'v': torch.randn(2, 3, 4),  # batch_size=2, seq_len=3, d_model=4
    'mask': None,
    'is_causal': False,
}

# Construct and call the class
if __name__ == '__main__':
    from typing import Callable, Optional
    
    class FeedForward(nn.Module):
        def __init__(self, in_channel: int, mid_channels: int, out_channels: int, dropout: float):
            super().__init__()
            self.ffn = nn.Sequential(
                nn.Linear(in_channel, mid_channels),
                nn.GELU(),
                nn.Linear(mid_channels, out_channels),
                nn.Dropout(dropout)
            )

        def forward(self, x):
            return self.ffn(x)

    def generate_causal_mask(size: int, device: torch.device):
        return torch.triu(torch.full((size, size), float('-inf'), device=device), diagonal=1)

    class TransformerEncoderLayer(nn.Module):
        def __init__(self, d_model: int, n_head: int, dropout: float, multihead_bias: bool, norm_layer: Callable = nn.LayerNorm):
            super().__init__()
            self.attention = nn.MultiheadAttention(d_model, n_head, dropout, batch_first=True, bias=multihead_bias)
            self.ffn = FeedForward(d_model, d_model * 4, d_model, dropout)
            self.norm1_q = norm_layer(d_model)
            self.norm1_k = norm_layer(d_model)
            self.norm1_v = norm_layer(d_model)
            self.norm2 = norm_layer(d_model)

        def forward(self, q, k, v, *, mask=None, is_causal=False):
            q, k, v = (self.norm1_q(q), self.norm1_k(k), self.norm1_v(v))
            if mask is None and is_causal:
                mask = generate_causal_mask(q.size(1), q.device)
            q = q + self.attention(q, k, v, attn_mask=mask, is_causal=is_causal)[0]
            q = q + self.ffn(self.norm2(q))
            return q

    model = TransformerEncoderLayer(**INIT_ARGS)
    output = model(**ARGS)
    print(f"Output shape: {output.shape}")
    print(f"Expected shape: {ARGS['q'].shape}")
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
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, 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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
generate_causal_mask Ran
ran, violated the contract we drafted
willGuimont/transformers/nnet/transformers.py
code served (permissive licence) · get_code("2b689c925fabd814")
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 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

torch.manual_seed(0)

ARGS = {
    "size": 4,
    "device": torch.device("cpu"),
}
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 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
TransformerEncoder Not yet run
unverified (harvested, no recorded run)
willGuimont/transformers/nnet/transformers.py
code served (permissive licence) · get_code("e53c6cf4b84b6095")
How it ran

no invocation recorded.

_init_transformer_weights Not yet run
unverified (harvested, no recorded run)
willGuimont/transformers/nnet/transformers.py
code served (permissive licence) · get_code("3707bec4aaa1f2b7")
How it ran

no invocation recorded.

Also present in other papers' code

Of 5 samples lifted from this paper's linked repositories, 5 carry a function identity and 0 do not. Of the 5 distinct functions with an identity, 0 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 0 later) and 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.

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

The Universal Transformer (UT) is a variant of the Transformer that shares parameters across its layers. Empirical evidence shows that UTs have better compositional generalization than Vanilla Transformers (VTs) in formal language tasks. The parameter-sharing also affords it better parameter efficiency than VTs. Despite its many advantages, scaling UT parameters is much more compute and memory intensive than scaling up a VT. This paper proposes the Sparse Universal Transformer (SUT), which leverages Sparse Mixture of Experts (SMoE) and a new stick-breaking-based dynamic halting mechanism to reduce UT's computation complexity while retaining its parameter efficiency and generalization ability. Experiments show that SUT achieves the same performance as strong baseline models while only using half computation and parameters on WMT'14 and strong generalization results on formal language tasks (Logical inference and CFQ). The new halting mechanism also enables around 50% reduction in computation during inference with very little performance decrease on formal language tasks.

For agents

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

get_harvested_code_for_paper("2310.07096")
get_code_for_paper("2310.07096")
have("2310.07096")

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

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

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

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

Connect an agent — have() is free.