SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2406.16778 · NeurIPS · 2024

Finding Transformer Circuits with Edge Pruning

Danqi Chen, Alexander Wettig, Dan Friedman, Adithya Bhaskar

arXiv · PDF · Open in the Atlas

Code that ran

8 of 8 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; 3 honoured the contract we drafted, 0 violated it and 0 have no contract verdict; 5 failures of our instrument; 0 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/2406.16778.json · badge: /api/ran/2406.16778.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
princeton-nlp/Edge-Pruning canonical (classifier label)
classifier basis: classifier_2025
6 ran · 0 no recorded run
princeton-nlp/edge-pruning marked official in Papers with Code
Papers with Code archive
2 ran · 0 no recorded run
FunctionStatusWhere it lives
find_template Ran
ran; our contract draft was wrong, not the code
princeton-nlp/Edge-Pruning/src/eval/ioi.py
code served (permissive licence) · get_code("ac94bbb65658849e")
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.

# Analyzing the function find_template
# It takes a single parameter: string
# The function tries to match the string against templates and returns a mapping dict or None

# The function uses:
# - string.strip() and string.split()
# - Iterates through baba_templates and abba_templates
# - Calls try_fit_template(string, template) for each template
# - Returns a dict with keys: 'a', 'b', 'place', 'object', 'template', 'order'

# We need to construct a valid string that will match one of the templates

# Let's create a string that matches the first baba_template:
# 'Then, {B} and {A} went to the {PLACE}. {B} gave a {OBJECT} to {A}'
# We need to substitute: B=some_name, A=some_name, PLACE=some_place, OBJECT=some_object

test_string = "Then, John and Mary went to the park. John gave a book to Mary"

ARGS = {
    'string': test_string
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
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 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
format_instance Ran
ran; our contract draft was wrong, not the code
princeton-nlp/Edge-Pruning/src/prune/fpt2_ioi.py
code served (permissive licence) · get_code("65258336cdb05cba")
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)

# Test case 1: instance is a dict with 'min_steps'
instance_with_min_steps = {
    'tokens': torch.tensor([[1, 2, 3, 4], [5, 6, 7, 8]]),
    'min_steps': 10
}

# Test case 2: instance is just tokens (not a dict with 'min_steps')
instance_without_min_steps = torch.tensor([[9, 10, 11, 12], [13, 14, 15, 16]])

split = "train"

ARGS = {
    'instance': instance_with_min_steps,
    'split': split
}
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
n_readers Ran
ran, honoured the contract we drafted
princeton-nlp/edge-pruning/src/modeling/modeling_erazr.py
code served (permissive licence) · get_code("d4e547744737a080")
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 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 torch.nn as nn

class Config:
    def __init__(self, num_layers, num_heads):
        self.num_layers = num_layers
        self.num_heads = num_heads

config = Config(num_layers=2, num_heads=3)

ARGS = {
    "config": config
}
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 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
n_total_edges Ran
ran, honoured the contract we drafted
princeton-nlp/edge-pruning/src/modeling/modeling_erazr.py
code served (permissive licence) · get_code("d4f39f78881244a5")
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 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

class Config:
    def __init__(self, num_layers, num_heads):
        self.num_layers = num_layers
        self.num_heads = num_heads

config = Config(num_layers=3, num_heads=2)

ARGS = {
    "config": config
}
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 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
reader_idx_to_name Ran
ran; our contract draft was wrong, not the code
princeton-nlp/Edge-Pruning/src/modeling/modeling_fpt2.py
code served (permissive licence) · get_code("e29fd15d44a01690")
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)

# Analyze the function:
# - reader_idx: integer index
# - num_layers: integer, number of layers
# - num_heads: integer, number of attention heads
# The function uses these to compute layer and head indices and return strings

ARGS = {
    "reader_idx": 5,
    "num_layers": 2,
    "num_heads": 3,
}
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
try_fit_template Ran
ran; our contract draft was wrong, not the code
princeton-nlp/Edge-Pruning/src/prune/fpt2_ioi.py
code served (permissive licence) · get_code("09edbe6bc59ee172")
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)

# Analyze the function: try_fit_template takes two string parameters
# It processes them by stripping, splitting on whitespace, and matching tokens
# It builds a mapping dictionary from template placeholders to string pieces
# The function returns None or a mapping dict

# Test case 1: Simple matching with template placeholders
string1 = "the cat sat"
template1 = "{OBJECT} {A} {PLACE}"

# Test case 2: String with punctuation
string2 = "the dog runs."
template2 = "{OBJECT} {B} runs."

# Test case 3: Matching strings (no placeholders needed)
string3 = "hello world test"
template3 = "hello world test"

# Test case 4: Complex case with multiple placeholders
string4 = "a bird flew away"
template4 = "{A} {OBJECT} {B} away"

ARGS = {
    "string": string1,
    "template": template1
}
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
writer_idx_to_name Ran
ran; our contract draft was wrong, not the code
princeton-nlp/Edge-Pruning/src/modeling/modeling_fpt2.py
code served (permissive licence) · get_code("149ae20dadcb3e8f")
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

torch.manual_seed(0)

ARGS = {
    'writer_idx': 5,
    'num_layers': 3,
    'num_heads': 4,
    'with_embedding_nodes': False,
}
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 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
writer_name_to_idx Ran
ran, honoured the contract we drafted
princeton-nlp/Edge-Pruning/src/modeling/modeling_fpt2.py
code served (permissive licence) · get_code("a8e155123b432821")
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 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

torch.manual_seed(0)

# Test case 1: with_embedding_nodes=False, name starting with 'm'
ARGS = {
    'name': 'm2',
    'num_layers': 5,
    'num_heads': 8,
    'with_embedding_nodes': False
}
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 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

Also present in other papers' code

Of 8 samples lifted from this paper's linked repositories, 8 carry a function identity and 0 do not. Of the 8 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 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.

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 path to interpreting a language model often proceeds via analysis of circuitssparse computational subgraphs of the model that capture specific aspects of its behavior. Recent work has automated the task of discovering circuits. Yet, these methods have practical limitations, as they rely either on inefficient search algorithms or inaccurate approximations. In this paper, we frame automated circuit discovery as an optimization problem and propose Edge Pruning as an effective and scalable solution. Edge Pruning leverages gradient-based pruning techniques, but instead of removing neurons or components, it prunes the edges between components. Our method finds circuits in GPT-2 that use less than half the number of edges compared to circuits found by previous methods while being equally faithful to the full model predictions on standard circuit-finding tasks. Edge Pruning is efficient even with as many as 100K examples, outperforming previous methods in speed and producing substantially better circuits. It also perfectly recovers the ground-truth circuits in two models compiled with Tracr. Thanks to its efficiency, we scale Edge Pruning to CodeLlama-13B, a model over 100× the scale that prior methods operate on. We use this setting for a case study comparing the mechanisms behind instruction prompting and in-context learning. We find two circuits with more than 99.96% sparsity that match the performance of the full model and reveal that the mechanisms in the two settings overlap substantially. Our case study shows that Edge Pruning is a practical and scalable tool for interpretability and sheds light on behaviors that only emerge in large models. 1

For agents

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

get_harvested_code_for_paper("2406.16778")
get_code_for_paper("2406.16778")
have("2406.16778")

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

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

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

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

Connect an agent — have() is free.