SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2201.08821 · NeurIPS · 2021

Representing Long-Range Context for Graph Neural Networks with Global Attention

Zhanghao Wu, Ion Stoica, Paras Jain, Azalia Mirhoseini, Joseph E. Gonzalez, Matthew A. Wright

arXiv · PDF · Open in the Atlas

Code that ran

7 of 14 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (5 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 6 have no contract verdict; 1 failure of our instrument; 7 no recorded run), measured 2026-11-22; 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/2201.08821.json · badge: /api/ran/2201.08821.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
ucbrise/graphtrans canonical (classifier label)
classifier basis: classifier_2025
7 ran · 7 no recorded run
FunctionStatusWhere it lives
Block Ran
ran on a synthesized input · constructed an object; no result was computed
ucbrise/graphtrans/models/gnn_transformer.py
code served (permissive licence) · get_code("5e621bc325bada93")
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 an instance of its own class, Block: the run constructed the object and did not call it, so no result was computed. 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 math

torch.manual_seed(0)

# Define ARGS dict with all parameters for Block.__init__
ARGS = {
    "n_embd": 4,
    "n_ff": 8,
    "n_head": 2,
    "attn_pdrop": 0.1,
    "resid_pdrop": 0.1,
    "prenorm": True,
}
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 Block — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a Block 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
CausalSelfAttention Ran
ran on a synthesized input
ucbrise/graphtrans/models/gnn_transformer.py
code served (permissive licence) · get_code("54f4034695672c97")
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; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim 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 math
import torch.nn.functional as F

class CausalSelfAttention(nn.Module):
    """
    A vanilla multi-head masked self-attention layer with a projection at the end.
    It is possible to use torch.nn.MultiheadAttention here but I am including an
    explicit implementation here to show that there is nothing too scary here.
    """

    def __init__(self, n_embd, n_head, attn_pdrop, resid_pdrop):
        super().__init__()
        assert n_embd % n_head == 0
        self.key = nn.Linear(n_embd, n_embd)
        self.query = nn.Linear(n_embd, n_embd)
        self.value = nn.Linear(n_embd, n_embd)
        self.attn_drop = nn.Dropout(attn_pdrop)
        self.resid_drop = nn.Dropout(resid_pdrop)
        self.proj = nn.Linear(n_embd, n_embd)
        self.n_head = n_head

    def forward(self, x, attn_mask: torch.Tensor=None, valid_input_mask: torch.Tensor=None, mask_value=-1000000.0):
        """mask should be a 3D tensor of shape (B, T, T)"""
        B, T, C = x.size()
        k = self.key(x).view(B, T, self.n_head, C // self.n_head).transpose(1, 2)
        q = self.query(x).view(B, T, self.n_head, C // self.n_head).transpose(1, 2)
        v = self.value(x).view(B, T, self.n_head, C // self.n_head).transpose(1, 2)
        att = q @ k.transpose(-2, -1) * (1.0 / math.sqrt(k.size(-1)))
        if attn_mask is not None:
            att = att.masked_fill(attn_mask.unsqueeze(1) == 0, mask_value)
        if valid_input_mask is not None:
            att = att.masked_fill(valid_input_mask.unsqueeze(1).unsqueeze(2) == 0, mask_value)
        att = F.softmax(att, dim=-1)
        att = self.attn_drop(att)
        y = att @ v
        y = y.transpose(1, 2).contiguous().view(B, T, C)
        y = self.resid_drop(self.proj(y))
        return y

INIT_ARGS = {
    'n_embd': 8,
    'n_head': 2,
    'attn_pdrop': 0.1,
    'resid_pdrop': 0.1
}

ARGS = {
    'x': torch.randn(2, 5, 8),
    'attn_mask': torch.tril(torch.ones(2, 5, 5)),
    'valid_input_mask': torch.ones(2, 5),
    'mask_value': -1000000.0
}
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 — no output shape is stated: observe_signature.py observed this class with its constructor sizes canonicalised where it could, which the node does not record, so its shape is not stated as this setup block's
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)
MaskedOnlyTransformerEncoder Ran
ran on a synthesized input · constructed an object; no result was computed
ucbrise/graphtrans/models/gnn_transformer.py
code served (permissive licence) · get_code("47a9110e2ff3cb6d")
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 an instance of its own class, MaskedOnlyTransformerEncoder: the run constructed the object and did not call it, so no result was computed. 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
from argparse import Namespace

torch.manual_seed(0)

# Create a minimal args object with all required attributes
ARGS = {
    'args': Namespace(
        max_input_len=10,
        num_encoder_layers_masked=2,
        d_model=4,
        dim_feedforward=8,
        nhead=2,
        transformer_dropout=0.1,
        transformer_prenorm=False
    )
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
loguru, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type MaskedOnlyTransformerEncoder — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a MaskedOnlyTransformerEncoder 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
MaskedTransformerBlock Ran
ran on a synthesized input · constructed an object; no result was computed
ucbrise/graphtrans/models/gnn_transformer.py
code served (permissive licence) · get_code("a24d2e60a5f1edb0")
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 an instance of its own class, MaskedTransformerBlock: the run constructed the object and did not call it, so no result was computed. 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 math
import torch.nn.functional as F

torch.manual_seed(0)

# Define the classes needed
class CausalSelfAttention(nn.Module):
    def __init__(self, n_embd, n_head, attn_pdrop, resid_pdrop):
        super().__init__()
        assert n_embd % n_head == 0
        self.key = nn.Linear(n_embd, n_embd)
        self.query = nn.Linear(n_embd, n_embd)
        self.value = nn.Linear(n_embd, n_embd)
        self.attn_drop = nn.Dropout(attn_pdrop)
        self.resid_drop = nn.Dropout(resid_pdrop)
        self.proj = nn.Linear(n_embd, n_embd)
        self.n_head = n_head

    def forward(self, x, attn_mask: torch.Tensor=None, valid_input_mask: torch.Tensor=None, mask_value=-1000000.0):
        B, T, C = x.size()
        k = self.key(x).view(B, T, self.n_head, C // self.n_head).transpose(1, 2)
        q = self.query(x).view(B, T, self.n_head, C // self.n_head).transpose(1, 2)
        v = self.value(x).view(B, T, self.n_head, C // self.n_head).transpose(1, 2)
        att = q @ k.transpose(-2, -1) * (1.0 / math.sqrt(k.size(-1)))
        if attn_mask is not None:
            att = att.masked_fill(attn_mask.unsqueeze(1) == 0, mask_value)
        if valid_input_mask is not None:
            att = att.masked_fill(valid_input_mask.unsqueeze(1).unsqueeze(2) == 0, mask_value)
        att = F.softmax(att, dim=-1)
        att = self.attn_drop(att)
        y = att @ v
        y = y.transpose(1, 2).contiguous().view(B, T, C)
        y = self.resid_drop(self.proj(y))
        return y

class Block(nn.Module):
    def __init__(self, n_embd, n_ff, n_head, attn_pdrop, resid_pdrop, prenorm=True):
        super().__init__()
        self.prenorm = prenorm
        self.ln1 = nn.LayerNorm(n_embd)
        self.ln2 = nn.LayerNorm(n_embd)
        self.attn = CausalSelfAttention(n_embd, n_head, attn_pdrop, resid_pdrop)
        self.mlp = nn.Sequential(nn.Linear(n_embd, n_ff), nn.GELU(), nn.Linear(n_ff, n_embd), nn.Dropout(resid_pdrop))

    def forward(self, x, attn_mask=None, valid_input_mask=None):
        if self.prenorm:
            x = x + self.attn(self.ln1(x), attn_mask, valid_input_mask)
            x = x + self.mlp(self.ln2(x))
        else:
            x = self.ln1(x + self.attn(x, attn_mask, valid_input_mask))
            x = self.ln2(x + self.mlp(x))
        return x

class MaskedTransformerBlock(nn.Module):
    def __init__(self, n_layer, n_embd, n_ff, n_head, attn_pdrop, resid_pdrop, prenorm=True):
        super().__init__()
        self.blocks = nn.ModuleList([Block(n_embd, n_ff, n_head, attn_pdrop, resid_pdrop, prenorm) for _ in range(n_layer)])

    def forward(self, x, attn_mask=None, valid_input_mask=None):
        for block in self.blocks:
            x = block(x, attn_mask, valid_input_mask)
        return x

# Create test input tensors
batch_size = 2
seq_length = 3
n_embd = 4
n_ff = 8
n_head = 2
n_layer = 1
attn_pdrop = 0.1
resid_pdrop = 0.1
prenorm = True

# Input tensor: (batch, sequence, embedding)
x = torch.randn(batch_size, seq_length, n_embd)

# Optional attention mask: (batch, seq_length, seq_length) with values 0 or 1
attn_mask = torch.ones(batch_size, seq_length, seq_length)

# Optional valid input mask: (batch, seq_length) with values 0 or 1
valid_input_mask = torch.ones(batch_size, seq_length)

ARGS = {
    "n_layer": n_layer,
    "n_embd": n_embd,
    "n_ff": n_ff,
    "n_head": n_head,
    "attn_pdrop": attn_pdrop,
    "resid_pdrop": resid_pdrop,
    "prenorm": prenorm,
}
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 MaskedTransformerBlock — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a MaskedTransformerBlock 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
PositionalEncoding Ran
ran on a synthesized input · constructed an object; no result was computed
ucbrise/graphtrans/models/gnn_transformer.py
code served (permissive licence) · get_code("44450c1a1d39195f")
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 an instance of its own class, PositionalEncoding: the run constructed the object and did not call it, so no result was computed. 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 math

torch.manual_seed(0)

ARGS = {
    'd_model': 4,
    'dropout': 0.1,
    'max_len': 5000
}
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 PositionalEncoding — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a PositionalEncoding 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
TransformerNodeEncoder Ran
ran on a synthesized input · constructed an object; no result was computed
ucbrise/graphtrans/models/gnn_transformer.py
code served (permissive licence) · get_code("a4bc443f49dd810c")
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 an instance of its own class, TransformerNodeEncoder: the run constructed the object and did not call it, so no result was computed. 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)

class Args:
    def __init__(self):
        self.d_model = 8
        self.nhead = 2
        self.dim_feedforward = 16
        self.transformer_dropout = 0.1
        self.transformer_activation = 'relu'
        self.num_encoder_layers = 2
        self.max_input_len = 100
        self.transformer_norm_input = True
        self.graph_pooling = 'cls'

ARGS = {
    'args': Args()
}
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 TransformerNodeEncoder — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a TransformerNodeEncoder 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
pad_batch Ran
ran; our contract draft was wrong, not the code
ucbrise/graphtrans/models/gnn_transformer.py
code served (permissive licence) · get_code("cec619dc729ca927")
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)

# h_node: a tensor of shape (total_nodes, feature_dim)
# The function uses h_node.data, h_node.size(-1), and indexing with masks
h_node = torch.randn(8, 4)  # 8 nodes total, 4 feature dimensions

# batch: a tensor containing batch indices for each node
# The function uses batch[-1] to get max batch index, batch.eq(i) for masks
# We have 8 nodes distributed across 2 batches
batch = torch.tensor([0, 0, 0, 1, 1, 1, 1, 0], dtype=torch.long)

# max_input_len: integer limiting the maximum number of nodes per batch
max_input_len = 5

# get_mask: boolean flag determining return value
get_mask = True

ARGS = {
    "h_node": h_node,
    "batch": batch,
    "max_input_len": max_input_len,
    "get_mask": get_mask
}
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
BaseModel Not yet run
unverified (harvested, no recorded run)
ucbrise/graphtrans/models/gnn_transformer.py
code served (permissive licence) · get_code("dff37bf121adcf54")
How it ran

no invocation recorded.

GCNConv Not yet run
unverified (harvested, no recorded run)
ucbrise/graphtrans/models/gnn_transformer.py
code served (permissive licence) · get_code("de1fa9d2896a253e")
How it ran

no invocation recorded.

GINConv Not yet run
unverified (harvested, no recorded run)
ucbrise/graphtrans/models/gnn_transformer.py
code served (permissive licence) · get_code("ca2f5cd1f82b9713")
How it ran

no invocation recorded.

GNNNodeEmbedding Not yet run
unverified (harvested, no recorded run)
ucbrise/graphtrans/models/gnn_transformer.py
code served (permissive licence) · get_code("4ac493315fba009f")
How it ran

no invocation recorded.

GNNTransformer Not yet run
unverified (harvested, no recorded run)
ucbrise/graphtrans/models/gnn_transformer.py
code served (permissive licence) · get_code("58d376fe82ba1dc2")
How it ran

no invocation recorded.

GNN_node Not yet run
unverified (harvested, no recorded run)
ucbrise/graphtrans/models/gnn_transformer.py
code served (permissive licence) · get_code("e6ce121697c42f5e")
How it ran

no invocation recorded.

GNN_node_Virtualnode Not yet run
unverified (harvested, no recorded run)
ucbrise/graphtrans/models/gnn_transformer.py
code served (permissive licence) · get_code("e4c5152d3248ee46")
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, 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 14 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

Graph neural networks are powerful architectures for structured datasets. However, current methods struggle to represent long-range dependencies. Scaling the depth or width of GNNs is insufficient to broaden receptive fields as larger GNNs encounter optimization instabilities such as vanishing gradients and representation oversmoothing, while pooling-based approaches have yet to become as universally useful as in computer vision. In this work, we propose the use of Transformer-based self-attention to learn long-range pairwise relationships, with a novel "readout" mechanism to obtain a global graph embedding. Inspired by recent computer vision results that find position-invariant attention performant in learning long-range relationships, our method, which we call GraphTrans, applies a permutation-invariant Transformer module after a standard GNN module. This simple architecture leads to state-of-the-art results on several graph classification tasks, outperforming methods that explicitly encode graph structure. Our results suggest that purely-learning-based approaches without graph structure may be suitable for learning high-level, long-range relationships on graphs. Code for GraphTrans is available at https://github.com/ucbrise/graphtrans.

For agents

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

get_harvested_code_for_paper("2201.08821")
get_code_for_paper("2201.08821")
have("2201.08821")

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

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

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

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

Connect an agent — have() is free.