SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2405.15589 · 2024

Efficient Adversarial Training in LLMs with Continuous Attacks

arXiv · PDF · Open in the Atlas

Code that ran

8 of 10 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; 1 honoured the contract we drafted, 0 violated it and 0 have no contract verdict; 7 failures of our instrument; 2 no recorded run), measured 2026-11-24; 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.15589.json · badge: /api/ran/2405.15589.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
sophie-xhonneux/continuous-advtrain canonical (classifier label)
classifier basis: census
8 ran · 2 no recorded run
FunctionStatusWhere it lives
acquireLock Ran
ran; our contract draft was wrong, not the code
sophie-xhonneux/continuous-advtrain/src/run_experiments.py
pointer only (licence: MIT); the stored copy get_code serves, from insait-institute/mixat, is pointer only (licence: NONE) · get_code("dfef7ce9fc6e4f99")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from insait-institute/mixat, and GitHub detected no licence in that repository 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.

flatten_dict Ran
ran; our contract draft was wrong, not the code
sophie-xhonneux/continuous-advtrain/src/database_handling.py
code served (permissive licence) · get_code("15be2e56e073a228")
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

torch.manual_seed(0)

# Construct a nested dictionary with various types of values
nested_dict = {
    'layer1': {
        'weight': 0.5,
        'bias': 0.1,
        'config': {
            'learning_rate': 0.001,
            'momentum': 0.9
        }
    },
    'layer2': {
        'activation': 'relu',
        'dropout': 0.2
    },
    'model_name': 'test_model',
    'version': 1
}

ARGS = {
    'd': nested_dict,
    'parent_key': '',
    'sep': '_'
}
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
get_chat_template Ran
ran; our contract draft was wrong, not the code
sophie-xhonneux/continuous-advtrain/src/model_utils.py
code served (permissive licence) · get_code("780c913ff9f68d7b")
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

ARGS = {
    'model_name': 'gemma'
}
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_dataset_id Ran
ran, honoured the contract we drafted
sophie-xhonneux/continuous-advtrain/src/data.py
code served (permissive licence) · get_code("afa643eee62ab913")
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

torch.manual_seed(0)

ARGS = {
    'key': 'away'
}
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
get_dpo_loss Ran
ran; our contract draft was wrong, not the code
sophie-xhonneux/continuous-advtrain/src/adversarial_training.py
code served (permissive licence) · get_code("68d78c403eece7f7")
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 as nn

torch.manual_seed(0)

# Create a minimal trainer object with required attributes
class MinimalAccelerator:
    def __init__(self):
        self.device = "cpu"

class MinimalTrainer:
    def __init__(self):
        self.accelerator = MinimalAccelerator()
        self.reference_free = False
        self.dpo_loss_type = "sigmoid"
        self.beta = 0.5
        self.label_smoothing = 0.1

# Create batch tensors
batch_size = 2
policy_chosen_logps = torch.randn(batch_size, dtype=torch.float32)
policy_rejected_logps = torch.randn(batch_size, dtype=torch.float32)
reference_chosen_logps = torch.randn(batch_size, dtype=torch.float32)
reference_rejected_logps = torch.randn(batch_size, dtype=torch.float32)

trainer = MinimalTrainer()

ARGS = {
    "trainer": trainer,
    "policy_chosen_logps": policy_chosen_logps,
    "policy_rejected_logps": policy_rejected_logps,
    "reference_chosen_logps": reference_chosen_logps,
    "reference_rejected_logps": reference_rejected_logps,
}
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
load_checkpoint Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
sophie-xhonneux/continuous-advtrain/src/model_utils.py
code served (permissive licence) · get_code("711d5028382d4919")
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 SimpleModel. 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 unittest.mock import Mock, MagicMock
from peft import PeftModel

torch.manual_seed(0)

# Create a minimal base model
class SimpleModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 3)
    
    def forward(self, x):
        return self.linear(x)

# Create a small base model instance
base_model = SimpleModel()

# Create a mock checkpoint path and config
# Since we can't actually load from a checkpoint, we'll mock PeftModel.from_pretrained
path_config = {
    'load_checkpoint_path': '/fake/checkpoint/path'
}

# Mock the PeftModel.from_pretrained to return a model-like object
# This avoids actual file I/O and network calls
original_from_pretrained = PeftModel.from_pretrained
PeftModel.from_pretrained = MagicMock(return_value=base_model)

ARGS = {
    'model': base_model,
    'path_config': path_config
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
peft, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type SimpleModel — a SimpleModel output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a SimpleModel 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
load_specific_dataset Ran
ran; our contract draft was wrong, not the code
sophie-xhonneux/continuous-advtrain/src/data.py
code served (permissive licence) · get_code("e92c968a55357248")
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 Dataset. 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 pandas as pd
from datasets import Dataset

# Create temporary directory structure for the function to work
temp_dir = tempfile.mkdtemp()
data_path = temp_dir + '/'

# Create necessary directory structure
os.makedirs(data_path + 'behavior_datasets/extra_behavior_datasets', exist_ok=True)
os.makedirs(data_path + 'optimizer_targets/extra_targets', exist_ok=True)
os.makedirs(data_path + 'utility/ultrachat', exist_ok=True)

# Create dummy behavior CSV file
behavior_df = pd.DataFrame({
    'Behavior': ['test behavior 1', 'test behavior 2'],
    'BehaviorID': [1, 2]
})
behavior_path = data_path + 'behavior_datasets/extra_behavior_datasets/adv_training_behaviors.csv'
behavior_df.to_csv(behavior_path, index=False, encoding='utf-8')

# Create dummy target JSON file
target_data = {1: 'target response 1', 2: 'target response 2'}
import json
target_path = data_path + 'optimizer_targets/extra_targets/adv_training_targets.json'
with open(target_path, 'w') as f:
    json.dump(target_data, f)

# Create a simple dataset and save it
simple_dataset = Dataset.from_dict({
    'data': [
        ['user msg 1', 'model msg 1', 'user msg 2', 'model msg 2'],
        ['user msg 3', 'model msg 3', 'user msg 4', 'model msg 4']
    ]
})
simple_dataset.save_to_disk(data_path + 'utility/ultrachat')

ARGS = {
    'data_path': data_path,
    'dataset_name': 'adv_training_behaviors',
    'split': None,
    'multiple_targets': False
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
datasets, pandas — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Dataset — a Dataset output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a Dataset output the recorded ndim 1 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
log_1_minus_p_loss Ran
ran; our contract draft was wrong, not the code
sophie-xhonneux/continuous-advtrain/src/adversarial_training.py
code served (permissive licence) · get_code("b5c7e326ac7ad2ed")
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 the function
batch_size = 2
num_classes = 4

# logits: shape (batch_size, num_classes) - raw model outputs
logits = torch.randn(batch_size, num_classes)

# labels: shape (batch_size,) - class indices, can contain -100 for ignored tokens
labels = torch.tensor([1, -100], dtype=torch.long)

# threshold: float 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
init_experiment Not yet run
unverified (harvested, no recorded run)
sophie-xhonneux/continuous-advtrain/src/database_handling.py
code served (permissive licence) · get_code("61ad493f36ea49b1")
How it ran

no invocation recorded.

load_model_and_tokenizer Not yet run
unverified (harvested, no recorded run)
sophie-xhonneux/continuous-advtrain/src/model_utils.py
code served (permissive licence) · get_code("06cd66993d331abf")
How it ran

no invocation recorded.

Also present in other papers' code

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

FunctionAlso present inEarliest-datedOthers named
flatten_dict 5 other papers
5 later
2410.15221 (2024-10)
IntersectionZoo: Eco-driving for Benchmarking Multi-Agent Contextual Reinforcement Learning
2412.09764 (2024-12)
Memory Layers at Scale
2503.18866 (2025-03)
Reasoning to Learn from Latent Thoughts
and 2 more not named here
acquireLock 1 other paper
1 later
2505.16947 (2025-05)
MIXAT: Combining Continuous and Discrete Adversarial Training for LLMs

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-24.

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) are vulnerable to adversarial attacks that can bypass their safety guardrails. In many domains, adversarial training has proven to be one of the most promising methods to reliably improve robustness against such attacks. Yet, in the context of LLMs, current methods for adversarial training are hindered by the high computational costs required to perform discrete adversarial attacks at each training iteration. We address this problem by instead calculating adversarial attacks in the continuous embedding space of the LLM, which is orders of magnitudes more efficient. We propose a fast adversarial training algorithm (C-AdvUL) composed of two losses: the first makes the model robust on continuous embedding attacks computed on an adversarial behaviour dataset; the second ensures the usefulness of the final model by fine-tuning on utility data. Moreover, we introduce C-AdvIPO, an adversarial variant of IPO that does not require utility data for adversarially robust alignment. Our empirical evaluation on five models from different families (Gemma, Phi3, Mistral, Zephyr, Llama2) and at different scales (2B, 3.8B, 7B) shows that both algorithms substantially enhance LLM robustness against discrete attacks (GCG, AutoDAN, PAIR), while maintaining utility. Our results demonstrate that robustness to continuous perturbations can extrapolate to discrete threat models. Thereby, we present a path toward scalable adversarial training algorithms for robustly aligning LLMs.

For agents

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

get_harvested_code_for_paper("2405.15589")
get_code_for_paper("2405.15589")
have("2405.15589")

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

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

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

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

Connect an agent — have() is free.