SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2405.14577 · NeurIPS · 2024

Representation Noising: A Defence Mechanism Against Harmful Finetuning

Frank Rudzicz, Subhabrata Majumdar, Hassan Sajjad, Domenic Rosati, Jan Wehner, Kai Williams, Łukasz Bartoszcze, David Atanasov, Robie Gonzales, Carsten Maple

arXiv · PDF · Open in the Atlas

Code that ran

5 of 7 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (1 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 1 has no contract verdict; 4 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/2405.14577.json · badge: /api/ran/2405.14577.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
domenicrosati/representation-noising canonical (classifier label)
classifier basis: classifier_2025
4 ran · 2 no recorded run
ai-law-society-lab/evaluating-durable-safeguards community
Papers with Code archive
1 ran · 0 no recorded run
FunctionStatusWhere it lives
CustomDataCollator Ran
ran on a synthesized input · constructed an object; no result was computed
ai-law-society-lab/evaluating-durable-safeguards/finetuning_buckets/models/model_families/llama2_repnoise.py
pointer only (licence: NONE) · get_code("d68dd3d2ccc175da")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, ai-law-society-lab/evaluating-durable-safeguards when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

masked_token_ce_loss Ran
ran; our contract draft was wrong, not the code
domenicrosati/representation-noising/representation_noising/loss.py
code served (permissive licence) · get_code("1a8b0e68c69b0aa5")
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 0, dtype family float, shape () as a later run recorded it. The image it ran in was not recorded. The code mentions cuda, and the harness aliases cuda to the CPU for every sample; whether this run needed that is 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
from torch import nn

torch.manual_seed(0)

DEVICE = torch.device('cuda' if torch.cuda.is_available() else 'cpu')

# Create small tensors with distinct dimensions
batch_size = 2
seq_length = 5
vocab_size = 4

# logits: shape (batch_size, seq_length, vocab_size)
logits = torch.randn(batch_size, seq_length, vocab_size, device=DEVICE)

# labels: shape (batch_size, seq_length)
labels = torch.randint(0, vocab_size, (batch_size, seq_length), device=DEVICE)

# mask: shape (batch_size, seq_length) - binary mask
mask = torch.ones(batch_size, seq_length, dtype=torch.float32, device=DEVICE)
mask[0, -1] = 0  # mask out last token in first sequence

ARGS = {
    "logits": logits,
    "labels": labels,
    "mask": mask,
}
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 0, dtype family float, 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
masked_token_ce_loss Ran
ran; our contract draft was wrong, not the code
domenicrosati/representation-noising/representation_noising/loss.py
code served (permissive licence) · get_code("a7b09c044eea09ba")
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 0, dtype family float, shape () as a later run recorded it. The image it ran in was not recorded. The code mentions cuda, and the harness aliases cuda to the CPU for every sample; whether this run needed that is 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)

# Construct arguments for masked_token_ce_loss
# The function expects:
# - logits: shape (batch, seq_len, vocab_size) - model output logits
# - labels: shape (batch, seq_len) - token ids
# - mask: shape (batch, seq_len) - binary mask for valid tokens

batch_size = 2
seq_len = 5
vocab_size = 4

# logits: (batch_size, seq_len, vocab_size)
logits = torch.randn(batch_size, seq_len, vocab_size)

# labels: (batch_size, seq_len) - token indices
labels = torch.randint(0, vocab_size, (batch_size, seq_len))

# mask: (batch_size, seq_len) - binary mask where 1 = valid, 0 = padding
mask = torch.ones(batch_size, seq_len)
mask[0, 3:] = 0  # mask out last 2 positions in first sequence
mask[1, 4] = 0   # mask out last position in second sequence

ARGS = {
    'logits': logits,
    'labels': labels,
    'mask': mask
}
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 0, dtype family float, 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
register_activation_hook Ran
ran; our contract draft was wrong, not the code
domenicrosati/representation-noising/representation_noising/loss.py
code served (permissive licence) · get_code("f37096f0537d4a9d")
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
from torch import nn

torch.manual_seed(0)

# Build a small model that will be used with register_activation_hook
class SimpleModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear1 = nn.Linear(4, 3)
        self.relu = nn.ReLU()
        self.linear2 = nn.Linear(3, 2)
    
    def forward(self, x):
        x = self.linear1(x)
        x = self.relu(x)
        x = self.linear2(x)
        return x

model = SimpleModel()

ARGS = {
    "model": model
}
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
register_activation_hook Ran
ran; our contract draft was wrong, not the code
domenicrosati/representation-noising/representation_noising/loss.py
code served (permissive licence) · get_code("4d976747a4df66ec")
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 torch.nn as nn

torch.manual_seed(0)

class SimpleModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear1 = nn.Linear(4, 3)
        self.relu = nn.ReLU()
        self.linear2 = nn.Linear(3, 2)
    
    def forward(self, x):
        x = self.linear1(x)
        x = self.relu(x)
        x = self.linear2(x)
        return x

model = SimpleModel()

ARGS = {
    "model": model
}
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
rep_noise_loss Not yet run
unverified (harvested, no recorded run)
domenicrosati/representation-noising/representation_noising/loss.py
code served (permissive licence) · get_code("0bb768e0eb2cec98")
How it ran

no invocation recorded.

rep_noise_loss Not yet run
unverified (harvested, no recorded run)
domenicrosati/representation-noising/representation_noising/loss.py
code served (permissive licence) · get_code("15df43c8e9555bc9")
How it ran

no invocation recorded.

Also present in other papers' code

Of 7 samples lifted from this paper's linked repositories, 7 carry a function identity and 0 do not. Of the 4 distinct functions with an identity, 1 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 1 later) and 3 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
masked_token_ce_loss
brick of this paper's assembly: loss
4 other papers
4 later
2409.18169 (2024-09)
Harmful Fine-tuning Attacks and Defenses for Large Language Models: A Survey
2410.09760 (2024-10)
Targeted Vaccine: Safety Alignment for Large Language Models against Harmful Fine-Tuning via Layer-wise Perturbation
2501.17433 (2025-01)
Virus: Harmful Fine-tuning Attack for Large Language Models Bypassing Guardrail Moderation
and 1 more not named here

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

Releasing open-source large language models (LLMs) presents a dual-use risk since bad actors can easily fine-tune these models for harmful purposes. Even without the open release of weights, weight stealing and fine-tuning APIs make closed models vulnerable to harmful fine-tuning attacks (HFAs). While safety measures like preventing jailbreaks and improving safety guardrails are important, such measures can easily be reversed through fine-tuning. In this work, we propose Representation Noising (RepNoise), a defence mechanism that operates even when attackers have access to the weights. RepNoise works by removing information about harmful representations such that it is difficult to recover them during finetuning. Importantly, our defence is also able to generalize across different subsets of harm that have not been seen during the defence process as long as they are drawn from the same distribution of the attack set. Our method does not degrade the general capability of LLMs and retains the ability to train the model on harmless tasks. We provide empirical evidence that the efficacy of our defence lies in its "depth": the degree to which information about harmful representations is removed across all layers of the LLM. We also find areas where RepNoise still remains ineffective and highlight how those limitations can inform future research.

For agents

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

get_harvested_code_for_paper("2405.14577")
get_code_for_paper("2405.14577")
have("2405.14577")

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

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

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

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

Connect an agent — have() is free.