SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2407.15549 · 2024

Latent Adversarial Training Improves Robustness to Persistent Harmful Behaviors in LLMs

arXiv · PDF · Open in the Atlas

Code that ran

5 of 11 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 0 have no contract verdict; 5 failures of our instrument; 6 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/2407.15549.json · badge: /api/ran/2407.15549.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
aengusl/latent-adversarial-training canonical (classifier label)
classifier basis: census
4 ran · 6 no recorded run
thestephencasper/latent_adversarial_training canonical (classifier label)
classifier basis: census
1 ran · 0 no recorded run
FunctionStatusWhere it lives
apply_chat_formatting Ran
ran; our contract draft was wrong, not the code
aengusl/latent-adversarial-training/latent_at/lat_datasets.py
code served (permissive licence) · get_code("84d77a5d33d24e78")
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
from transformers import AutoTokenizer

# Create a minimal tokenizer stand-in with apply_chat_template method
class MockTokenizer:
    def apply_chat_template(self, messages, tokenize=False):
        # Simple mock implementation that formats messages
        result = ""
        for msg in messages:
            result += f"[{msg['role']}]: {msg['content']}\n"
        return result.strip()

# Create mock tokenizer instance
tokenizer = MockTokenizer()

# Define arguments
ARGS = {
    'tokenizer': tokenizer,
    'prompt': "What is the capital of France?",
    'def_completion': "The capital of France is Paris.",
    'adv_completion': "The capital of France is London.",
    'use_tokenizer_template': True,
    'system_prompt': "You are a helpful assistant.",
    'custom_prompt_template': "[SYSTEM]\n{system_prompt}\n[USER]\n{prompt}",
    'custom_completion_template': "[COMPLETION]\n{completion}"
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch, transformers — 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
cross_entropy_loss Ran
ran; our contract draft was wrong, not the code
aengusl/latent-adversarial-training/latent_at/utils.py
code served (permissive licence) · get_code("2d4f7e1c015733a4")
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 0, dtype family float, 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.functional as F

torch.manual_seed(0)

# Create logits: shape (batch_size=2, num_classes=4)
logits = torch.randn(2, 4)

# Create labels: shape (batch_size=2,) with class indices
# Use values in range [0, 3] for valid classes, and -100 for ignore_index
labels = torch.tensor([0, 1], dtype=torch.long)

ARGS = {
    "logits": logits,
    "labels": labels,
}
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 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
log_1_minus_p_loss Ran
ran; our contract draft was wrong, not the code
aengusl/latent-adversarial-training/latent_at/utils.py
code served (permissive licence) · get_code("822c31ecffc70a9b")
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 0, dtype family float, 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)

# Create small tensors for testing
batch_size = 2
num_classes = 4

# logits: shape (batch_size, num_classes)
logits = torch.randn(batch_size, num_classes)

# labels: shape (batch_size,) with values in range [0, num_classes) or -100 for ignored
labels = torch.tensor([1, 2], dtype=torch.long)

# threshold parameter
threshold = -5.0

ARGS = {
    "logits": logits,
    "labels": labels,
    "threshold": threshold,
}
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 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
normalize_dict Ran
ran; our contract draft was wrong, not the code
aengusl/latent-adversarial-training/latent_at/utils.py
code served (permissive licence) · get_code("6d31f46f949e6c6a")
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 numpy as np

# The function normalize_dict takes a dict and normalizes its values
# by dividing each value by the sum of all values.
# It iterates through dict.values() and dict.items(), so we need a dict
# with numeric values that sum to a non-zero number.

ARGS = {
    "dict": {
        "a": 10,
        "b": 20,
        "c": 30
    }
}
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 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
parse_examples Ran
ran; our contract draft was wrong, not the code
thestephencasper/latent_adversarial_training/lat.py
code served (permissive licence) · get_code("b6f2b3a5ad34cd8a")
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 torch
from tqdm import tqdm

# Construct valid arguments for parse_examples function

# The function takes 'examples' parameter which should be a list of strings
# Each string contains conversations with PROMPT_INDICATOR and RESPONSE_INDICATOR markers
# The function processes these strings through tqdm

# Create sample example strings that match the expected format
example1 = "Human: Hello, how are you?Assistant: I'm doing well, thank you!Human: What's your name?Assistant: I'm an AI assistant."
example2 = "Human: Tell me a joke.Assistant: Why did the chicken cross the road? To get to the other side!Human: That's funny.Assistant: Glad you enjoyed it!"

examples = [example1, example2]

ARGS = {
    'examples': examples
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch, tqdm — 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
compute_dpo_loss Not yet run
unverified (harvested, no recorded run)
aengusl/latent-adversarial-training/latent_at/lat_helpers.py
code served (permissive licence) · get_code("a4c4e8ad30f33821")
How it ran

no invocation recorded.

compute_rmu_retain_loss Not yet run
unverified (harvested, no recorded run)
aengusl/latent-adversarial-training/latent_at/lat_helpers.py
code served (permissive licence) · get_code("eb85f7046a514389")
How it ran

no invocation recorded.

compute_toward_away_loss Not yet run
unverified (harvested, no recorded run)
aengusl/latent-adversarial-training/latent_at/lat_helpers.py
code served (permissive licence) · get_code("8c37b18faae1ff32")
How it ran

no invocation recorded.

is_deepspeed_model Not yet run
unverified (harvested, no recorded run)
aengusl/latent-adversarial-training/latent_at/lat_methods.py
code served (permissive licence) · get_code("704a4cba7e1ccc0e")
How it ran

no invocation recorded.

process_generic_chat_dataset Not yet run
unverified (harvested, no recorded run)
aengusl/latent-adversarial-training/latent_at/lat_datasets.py
code served (permissive licence) · get_code("8e9e1eb297f625e0")
How it ran

no invocation recorded.

process_generic_sft_dataset Not yet run
unverified (harvested, no recorded run)
aengusl/latent-adversarial-training/latent_at/lat_datasets.py
code served (permissive licence) · get_code("302ed1253a5c501c")
How it ran

no invocation recorded.

Also present in other papers' code

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

Large language models (LLMs) can often be made to behave in undesirable ways that they are explicitly fine-tuned not to. For example, the LLM red-teaming literature has produced a wide variety of 'jailbreaking' techniques to elicit harmful text from models that were fine-tuned to be harmless. Recent work on red-teaming, model editing, and interpretability suggests that this challenge stems from how (adversarial) fine-tuning largely serves to suppress rather than remove undesirable capabilities from LLMs. Prior work has introduced latent adversarial training (LAT) as a way to improve robustness to broad classes of failures. These prior works have considered untargeted latent space attacks where the adversary perturbs latent activations to maximize loss on examples of desirable behavior. Untargeted LAT can provide a generic type of robustness but does not leverage information about specific failure modes. Here, we experiment with targeted LAT where the adversary seeks to minimize loss on a specific competing task. We find that it can augment a wide variety of state-of-the-art methods. First, we use targeted LAT to improve robustness to jailbreaks, outperforming a strong R2D2 baseline with orders of magnitude less compute. Second, we use it to more effectively remove backdoors with no knowledge of the trigger. Finally, we use it to more effectively unlearn knowledge for specific undesirable tasks in a way that is also more robust to re-learning. Overall, our results suggest that targeted LAT can be an effective tool for defending against harmful behaviors from LLMs.

For agents

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

get_harvested_code_for_paper("2407.15549")
get_code_for_paper("2407.15549")
have("2407.15549")

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

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

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

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

Connect an agent — have() is free.