SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2411.06424 · 2024

How Does DPO Reduce Toxicity? A Mechanistic Neuron-Level Analysis

arXiv · PDF · Open in the Atlas

Code that ran

13 of 15 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; 10 failures of our instrument; 2 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/2411.06424.json · badge: /api/ran/2411.06424.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
yushi-y/dpo-toxic-neurons canonical (classifier label)
classifier basis: census
13 ran · 2 no recorded run
FunctionStatusWhere it lives
dpo_loss Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
yushi-y/dpo-toxic-neurons/train_dpo/trainers.py
code served (permissive licence) · get_code("6e420696373414b1")
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, ndim 2, 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.functional as F

torch.manual_seed(0)

# Create small batch tensors for DPO loss computation
batch_size = 2

# Policy model log probabilities for positive responses (batch_size,)
policy_pos_logps = torch.randn(batch_size, dtype=torch.float32)

# Policy model log probabilities for negative responses (batch_size,)
policy_neg_logps = torch.randn(batch_size, dtype=torch.float32)

# Reference model log probabilities for positive responses (batch_size,)
ref_pos_logps = torch.randn(batch_size, dtype=torch.float32)

# Reference model log probabilities for negative responses (batch_size,)
ref_neg_logps = torch.randn(batch_size, dtype=torch.float32)

# Beta temperature parameter
beta = 0.1

# Reference free flag
reference_free = False

ARGS = {
    "policy_pos_logps": policy_pos_logps,
    "policy_neg_logps": policy_neg_logps,
    "ref_pos_logps": ref_pos_logps,
    "ref_neg_logps": ref_neg_logps,
    "beta": beta,
    "reference_free": reference_free,
}
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, ndim 2, dtype family float — a tuple output has no array shape of its own; none is stated
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
get_gold Ran
ran; our contract draft was wrong, not the code
yushi-y/dpo-toxic-neurons/evaluation/generate_funcs.py
code served (permissive licence) · get_code("813d811b5f586d21")
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
import torch.nn as nn

torch.manual_seed(0)

# Create a minimal model (not actually used in the function, but required)
class DummyModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 3)
    
    def forward(self, x):
        return self.linear(x)

model = DummyModel()

# Create data dict with required keys based on function body
data = {
    'gold_input_ids': torch.tensor([[101, 2054, 2003, 1045], [102, 2054, 2003, 2054]]),
    'gold': ['What is I', 'What is what']
}

# Create config (not used in function body, but required parameter)
config = {}

ARGS = {
    'model': model,
    'data': data,
    'config': config
}
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
get_intervene_vector Ran
ran, honoured the contract we drafted
yushi-y/dpo-toxic-neurons/activation_patching/hook_utils.py
code served (permissive licence) · get_code("9df69409dc0ffe78")
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 1, dtype family float, shape (8,) 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

torch.manual_seed(0)

# Build a minimal model that matches the expected structure
class MLPModule(nn.Module):
    def __init__(self, d_model=4, d_ff=8):
        super().__init__()
        self.c_fc = nn.Linear(d_model, d_ff)
        self.c_proj = nn.Linear(d_ff, d_model)
    
    def forward(self, x):
        return self.c_proj(self.c_fc(x))

class TransformerBlock(nn.Module):
    def __init__(self, d_model=4, d_ff=8):
        super().__init__()
        self.mlp = MLPModule(d_model, d_ff)
    
    def forward(self, x):
        return self.mlp(x)

class Transformer(nn.Module):
    def __init__(self, n_layer=2, d_model=4, d_ff=8):
        super().__init__()
        self.h = nn.ModuleList([TransformerBlock(d_model, d_ff) for _ in range(n_layer)])
    
    def forward(self, x):
        for block in self.h:
            x = block(x)
        return x

class MinimalModel(nn.Module):
    def __init__(self, n_layer=2, d_model=4, d_ff=8):
        super().__init__()
        self.config = type('Config', (), {'n_layer': n_layer})()
        self.transformer = type('Transformer', (), {
            'h': nn.ModuleList([TransformerBlock(d_model, d_ff) for _ in range(n_layer)])
        })()
        self.device = torch.device('cpu')
    
    def to(self, device):
        return super().to(device)

model = MinimalModel(n_layer=2, d_model=4, d_ff=8)

# Create a minimal config for the 'random' type
config = {
    'type': 'random'
}

ARGS = {
    'model': model,
    'config': config
}
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 1, dtype family float, shape (8,) — shape (8,) 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
get_kl_div Ran
ran; our contract draft was wrong, not the code
yushi-y/dpo-toxic-neurons/train_dpo/trainers.py
code served (permissive licence) · get_code("573680795434164c")
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, ndim 1, 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
from torch.nn import KLDivLoss

torch.manual_seed(0)

# Create KLDivLoss criterion
kl_criterion = KLDivLoss(reduction='none')

# Create small logit tensors
# Shape: (batch_size, vocab_dim)
batch_size = 2
vocab_dim = 4

pos_pi_logits = torch.randn(batch_size, vocab_dim)
neg_pi_logits = torch.randn(batch_size, vocab_dim)
pos_ref_logits = torch.randn(batch_size, vocab_dim)
neg_ref_logits = torch.randn(batch_size, vocab_dim)

ARGS = {
    'kl_criterion': kl_criterion,
    'pos_pi_logits': pos_pi_logits,
    'neg_pi_logits': neg_pi_logits,
    'pos_ref_logits': pos_ref_logits,
    'neg_ref_logits': neg_ref_logits,
}
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, ndim 1, dtype family float — a tuple output has no array shape of its own; none is stated
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
get_local_dir Ran
ran; our contract draft was wrong, not the code
yushi-y/dpo-toxic-neurons/train_dpo/dpo_utils.py
code served (permissive licence) · get_code("8ab43db002bf984d")
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 os
import tempfile
import getpass

# Create a temporary directory that exists for testing
temp_dir = tempfile.mkdtemp()

# Create the ARGS dictionary with valid arguments for get_local_dir
ARGS = {
    'prefixes_to_resolve': [temp_dir, '/tmp', '/var/tmp']
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
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 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
get_local_run_dir Ran
ran; our contract draft was wrong, not the code
yushi-y/dpo-toxic-neurons/train_dpo/dpo_utils.py
code served (permissive licence) · get_code("1df5ede8f8950a70")
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 os
import tempfile
from typing import List

# Create a temporary directory to use as a base for local_dirs
temp_base = tempfile.gettempdir()

# Define arguments for get_local_run_dir
ARGS = {
    'exp_name': 'test_experiment_001',
    'local_dirs': [temp_base]
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
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 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
get_prompts Ran
ran; our contract draft was wrong, not the code
yushi-y/dpo-toxic-neurons/evaluation/generate_funcs.py
code served (permissive licence) · get_code("d635938df605fbd3")
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
import torch.nn as nn

torch.manual_seed(0)

# Build a minimal model (the function doesn't actually use the model)
class DummyModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 3)
    
    def forward(self, x):
        return self.linear(x)

model = DummyModel()

# Build data dict with required keys
data = {
    'prompt_input_ids': torch.randint(0, 100, (2, 4)),  # batch=2, seq_len=4
    'prompts': ['This is prompt one', 'This is prompt two']
}

# Build a minimal config (the function doesn't use it)
config = {
    'model_name': 'dummy',
    'hidden_size': 768
}

ARGS = {
    'model': model,
    'data': data,
    'config': config
}
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
get_remote_file Ran
ran; our contract draft was wrong, not the code
yushi-y/dpo-toxic-neurons/train_dpo/dpo_utils.py
code served (permissive licence) · get_code("e7ce4c19888c6df6")
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 os
import socket
import tempfile

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

# Get the current hostname
current_hostname = socket.gethostname()

# Create a test local path
test_local_path = os.path.join(temp_dir, "test_file.txt")

# Create a remote path string - using local hostname to avoid actual SCP calls
# Format is "hostname:path"
remote_path = f"{current_hostname}:/tmp/test_remote_file.txt"

ARGS = {
    "remote_path": remote_path,
    "local_path": test_local_path,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
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 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
hook_subtract Ran
ran; our contract draft was wrong, not the code
yushi-y/dpo-toxic-neurons/activation_patching/hook_utils.py
code served (permissive licence) · get_code("b4e9abfc1b4387cd")
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 as nn

torch.manual_seed(0)

# Build a minimal GPT-2-like model with the required structure
class MLP(nn.Module):
    def __init__(self, d_model, d_ff):
        super().__init__()
        self.c_fc = nn.Linear(d_model, d_ff)
        self.c_proj = nn.Linear(d_ff, d_model)
    
    def forward(self, x):
        x = self.c_fc(x)
        x = self.c_proj(x)
        return x

class TransformerBlock(nn.Module):
    def __init__(self, d_model, d_ff):
        super().__init__()
        self.mlp = MLP(d_model, d_ff)
    
    def forward(self, x):
        return self.mlp(x)

class Transformer(nn.Module):
    def __init__(self, n_layer, d_model, d_ff):
        super().__init__()
        self.h = nn.ModuleList([TransformerBlock(d_model, d_ff) for _ in range(n_layer)])
    
    def forward(self, x):
        for block in self.h:
            x = block(x)
        return x

class GPT2Model(nn.Module):
    def __init__(self, n_layer=2, d_model=4, d_ff=8):
        super().__init__()
        self.config = type('Config', (), {'n_layer': n_layer})()
        self.transformer = Transformer(n_layer, d_model, d_ff)
        self.device = torch.device('cpu')
    
    def forward(self, x):
        return self.transformer(x)

# Create model
model = GPT2Model(n_layer=2, d_model=4, d_ff=8)

# Create a simple intervene_vector config that uses 'random' type
config = {
    'type': 'random',
    'scale': 0.5,
    'subtract_from': [0, 1],
    'hook_timesteps': -1
}

ARGS = {
    'model': model,
    'config': config
}
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
load_data Ran
ran; our contract draft was wrong, not the code
yushi-y/dpo-toxic-neurons/evaluation/eval_utils.py
code served (permissive licence) · get_code("cba91edd374a3e28")
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 list, ndim 1, 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 json
import tempfile
import os

# Create a temporary .jsonl file
temp_dir = tempfile.mkdtemp()
jsonl_path = os.path.join(temp_dir, "test_data.jsonl")

# Write some test data to the .jsonl file
test_data = [
    {"text": "Hello world", "label": 1},
    {"text": "Goodbye world", "label": 0}
]

with open(jsonl_path, 'w') as f:
    for item in test_data:
        f.write(json.dumps(item) + '\n')

# Define the data_config dictionary
data_config = {
    'datapath': jsonl_path
}

ARGS = {
    'data_config': data_config
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
datasets — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type list, ndim 1, dtype family float — a list output has no array shape of its own; none is stated
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
run_dummy Ran
ran, honoured the contract we drafted
yushi-y/dpo-toxic-neurons/evaluation/metric_funcs.py
code served (permissive licence) · get_code("f5813daae4f9b8f5")
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 torch.nn as nn

torch.manual_seed(0)

class DummyModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 3)
    
    def forward(self, x):
        return self.linear(x)

model = DummyModel()

data = [
    (torch.randn(2, 4), torch.randint(0, 3, (2,))),
    (torch.randn(2, 4), torch.randint(0, 3, (2,)))
]

intervene_results = {
    "intervention_1": torch.randn(2, 3),
    "intervention_2": torch.randn(2, 3)
}

config = {
    "learning_rate": 0.001,
    "batch_size": 2,
    "epochs": 10
}

ARGS = {
    "model": model,
    "data": data,
    "intervene_results": intervene_results,
    "config": config
}
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 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
run_f1 Ran
ran, honoured the contract we drafted
yushi-y/dpo-toxic-neurons/evaluation/metric_funcs.py
code served (permissive licence) · get_code("044b24804e21d67d")
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 float64, ndim 0, 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 numpy as np

torch.manual_seed(0)

# Stand-in tokenizer with pad_token_id
class StandInTokenizer:
    def __init__(self):
        self.pad_token_id = 0

# Stand-in model with tokenizer
class StandInModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.tokenizer = StandInTokenizer()

# Create model
model = StandInModel()

# Create data dict with gold_input_ids
# Shape: (batch_size=2, seq_len=4)
# Using pad_token_id=0 for some positions
data = {
    'gold_input_ids': torch.tensor([
        [1, 2, 3, 0],
        [2, 3, 4, 5]
    ], dtype=torch.long)
}

# Create intervene_results dict with pred_tokens
# Same shape as gold_input_ids
intervene_results = {
    'pred_tokens': torch.tensor([
        [1, 2, 3, 0],
        [2, 3, 5, 0]
    ], dtype=torch.long)
}

# Create config (can be empty or minimal)
config = {}

ARGS = {
    'model': model,
    'data': data,
    'intervene_results': intervene_results,
    'config': config
}
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 float64, ndim 0, dtype family float — no output shape is stated: observe_signature.py recorded float ndim 0, which disagrees with the fixture run
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
tokenize Ran
ran; our contract draft was wrong, not the code
yushi-y/dpo-toxic-neurons/evaluation/eval_utils.py
code served (permissive licence) · get_code("1a98f49d7c56acc9")
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
import torch.nn as nn

torch.manual_seed(0)

class MockTokenizer:
    def __init__(self):
        self.padding_side = 'left'
    
    def __call__(self, texts, max_length=None, padding=False, truncation=False, 
                 return_tensors=None, return_attention_mask=False):
        batch_size = len(texts) if isinstance(texts, list) else 1
        seq_len = 5
        
        input_ids = torch.randint(0, 1000, (batch_size, seq_len))
        result = {'input_ids': input_ids}
        
        if return_attention_mask:
            attention_mask = torch.ones((batch_size, seq_len), dtype=torch.long)
            result['attention_mask'] = attention_mask
        
        return result


tokenizer = MockTokenizer()

data = [
    {'prompt': 'What is machine learning?', 'gold': 'Machine learning is a subset of AI.'},
    {'prompt': 'Explain neural networks.', 'gold': 'Neural networks are computational models.'}
]

config = {
    'max_prompt_size': 10,
    'max_new_tokens': 5
}

ARGS = {
    'tokenizer': tokenizer,
    'data': data,
    'config': config
}
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
get_svd_u_vec Not yet run
unverified (harvested, no recorded run)
yushi-y/dpo-toxic-neurons/activation_patching/hook_utils.py
code served (permissive licence) · get_code("527be56c58313107")
How it ran

no invocation recorded.

load_model Not yet run
unverified (harvested, no recorded run)
yushi-y/dpo-toxic-neurons/evaluation/eval_utils.py
code served (permissive licence) · get_code("89200b27db47f6ea")
How it ran

no invocation recorded.

Also present in other papers' code

Of 15 samples lifted from this paper's linked repositories, 15 carry a function identity and 0 do not. Of the 15 distinct functions with an identity, 10 are also present in other papers whose code we hold (10 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.

FunctionAlso present inEarliest-datedOthers named
get_remote_file 15 other papers
15 dated earlier
2309.16240 (2023-09)
Beyond Reverse KL: Generalizing Direct Preference Optimization with Diverse Divergence Constraints
2312.00267 (2023-12)
Sample Efficient Preference Alignment in LLMs via Active Exploration
2401.01967 (2024-01)
A Mechanistic Understanding of Alignment Algorithms: A Case Study on DPO and Toxicity
and 12 more not named here
get_local_dir 10 other papers
10 dated earlier
2309.16240 (2023-09)
Beyond Reverse KL: Generalizing Direct Preference Optimization with Diverse Divergence Constraints
2401.01967 (2024-01)
A Mechanistic Understanding of Alignment Algorithms: A Case Study on DPO and Toxicity
2401.13275 (2024-01)
Can AI Assistants Know What They Don't Know?
and 7 more not named here
dpo_loss 1 other paper
1 dated earlier
2401.01967 (2024-01)
A Mechanistic Understanding of Alignment Algorithms: A Case Study on DPO and Toxicity
get_gold 1 other paper
1 dated earlier
2401.01967 (2024-01)
A Mechanistic Understanding of Alignment Algorithms: A Case Study on DPO and Toxicity
get_intervene_vector 1 other paper
1 dated earlier
2401.01967 (2024-01)
A Mechanistic Understanding of Alignment Algorithms: A Case Study on DPO and Toxicity
get_local_run_dir 1 other paper
1 dated earlier
2401.01967 (2024-01)
A Mechanistic Understanding of Alignment Algorithms: A Case Study on DPO and Toxicity
get_prompts 1 other paper
1 dated earlier
2401.01967 (2024-01)
A Mechanistic Understanding of Alignment Algorithms: A Case Study on DPO and Toxicity
load_data 1 other paper
1 dated earlier
2401.01967 (2024-01)
A Mechanistic Understanding of Alignment Algorithms: A Case Study on DPO and Toxicity
run_dummy 1 other paper
1 dated earlier
2401.01967 (2024-01)
A Mechanistic Understanding of Alignment Algorithms: A Case Study on DPO and Toxicity
run_f1 1 other paper
1 dated earlier
2401.01967 (2024-01)
A Mechanistic Understanding of Alignment Algorithms: A Case Study on DPO and Toxicity

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

Safety fine-tuning algorithms reduce harmful outputs in language models, yet their mechanisms remain under-explored. Direct Preference Optimization (DPO) is a popular choice of algorithm, but prior explanations, attributing its effects solely to dampened toxic neurons in the MLP layers, are incomplete. In this study, we analyse four language models (Llama-3.1-8B, Gemma-2-2B, Mistral-7B, GPT-2-Medium) and show that toxic neurons only account for 2.5% to 24% of DPO's effects across models. Instead, DPO balances distributed activation shifts across all MLP neurons to create a net toxicity reduction. We attribute this reduction to four neuron groups, two aligned with reducing toxicity and two promoting anti-toxicity, whose combined effects replicate DPO across models. To further validate this understanding, we develop an activation editing method mimicking DPO through distributed shifts along a toxicity representation. This method outperforms DPO in reducing toxicity while preserving perplexity, without requiring any weight updates. Our work provides a mechanistic understanding of DPO and introduces an efficient, tuning-free alternative for safety fine-tuning.

For agents

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

get_harvested_code_for_paper("2411.06424")
get_code_for_paper("2411.06424")
have("2411.06424")

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

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

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

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

Connect an agent — have() is free.