SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2402.09154 · 2024

Attacking Large Language Models with Projected Gradient Descent

arXiv · PDF · Open in the Atlas

Code that ran

7 of 12 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 6 have no contract verdict; 0 failures of our instrument; 5 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/2402.09154.json · badge: /api/ran/2402.09154.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
sigeisler/reinforce-attacks-llms community (classifier label)
classifier basis not recorded on the link
7 ran · 5 no recorded run
FunctionStatusWhere it lives
get_nonascii_toks Ran
ran, honoured the contract we drafted
sigeisler/reinforce-attacks-llms/baselines/reinforce/gcg_utils.py
code served (permissive licence) · get_code("400ada600d105b0a")
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 int, shape (44,) 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
from unittest.mock import Mock

torch.manual_seed(0)

class MockTokenizer:
    def __init__(self):
        self.vocab_size = 50
        self.bos_token_id = 1
        self.eos_token_id = 2
        self.pad_token_id = 0
        self.unk_token_id = 3
        self.name_or_path = "test_model"
    
    def decode(self, token_ids):
        # Return ASCII for low indices, non-ASCII for higher indices
        if token_ids[0] < 10:
            return chr(65 + token_ids[0])  # A, B, C, ...
        else:
            return chr(0x4E00 + token_ids[0])  # Chinese characters (non-ASCII)

tokenizer = MockTokenizer()

ARGS = {
    "tokenizer": tokenizer,
    "device": "cpu"
}
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 int, shape (44,) — shape (44,) 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
interleave_lists Ran
ran on a synthesized input
sigeisler/reinforce-attacks-llms/baselines/reinforce/gcg_utils.py
code served (permissive licence) · get_code("6961f9be2052b450")
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 int; 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

torch.manual_seed(0)

# Create two lists where len(longer) is a multiple of len(shorter)
shorter = [1, 2, 3]
longer = [10, 20, 30, 40, 50, 60]

ARGS = {
    "shorter": shorter,
    "longer": longer,
}
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 list, ndim 1, dtype family int — 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
one_hot_tensor Ran
ran on a synthesized input
sigeisler/reinforce-attacks-llms/baselines/reinforce/pgd_utils.py
code served (permissive licence) · get_code("9e6e90391070da80")
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 3, dtype family float, shape (2, 4, 5) 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)

# Construct input_ids tensor - shape (2, 4) with values in range [0, n_dims-1]
input_ids = torch.tensor([[0, 1, 2, 3], [1, 2, 0, 1]], dtype=torch.long)

# n_dims: number of dimensions for one-hot encoding
n_dims = 5

# device: CPU only
device = 'cpu'

# dtype: output dtype
dtype = torch.float32

ARGS = {
    'input_ids': input_ids,
    'n_dims': n_dims,
    'device': device,
    'dtype': dtype
}
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 3, dtype family float, shape (2, 4, 5) — shape (2, 4, 5) 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
pos_mean_p_norm Ran
ran on a synthesized input
sigeisler/reinforce-attacks-llms/baselines/reinforce/pgd_loss.py
code served (permissive licence) · get_code("42f77d6aa1b4277c")
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 (2,) 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 test tensors with distinct sizes for different dimensions
values = torch.randn(2, 4) + 5.0  # batch_size=2, N=4, make positive for p=1 tests
weights = torch.ones(2, 4)

ARGS = {
    "values": values,
    "p": 2,
    "weights": weights,
    "all_values_positive": True,
    "dim": -1,
}
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 (2,) — shape (2,) 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
sample Ran
ran on a synthesized input
sigeisler/reinforce-attacks-llms/baselines/reinforce/generate_utils.py
code served (permissive licence) · get_code("a52ae554101a8045")
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 2, dtype family int, shape (2, 1) 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: Basic case with float temperature and no top_k
logits_1 = torch.randn(2, 4)
temperature_1 = 1.0
top_k_1 = None

# Test case 2: With top_k parameter
logits_2 = torch.randn(2, 4)
temperature_2 = 0.5
top_k_2 = 2

# Test case 3: With tensor temperature
logits_3 = torch.randn(2, 4)
temperature_3 = torch.tensor([1.0, 0.0])
top_k_3 = None

# Test case 4: Edge case with temperature=0 (deterministic)
logits_4 = torch.randn(2, 4)
temperature_4 = 0.0
top_k_4 = None

# Use the first test case for ARGS
ARGS = {
    "logits": logits_1,
    "temperature": temperature_1,
    "top_k": top_k_1
}
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 Tensor, ndim 2, dtype family int, shape (2, 1) — shape (2, 1) 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
split_into_chunks Ran
ran on a synthesized input
sigeisler/reinforce-attacks-llms/baselines/reinforce/pgd_adapter.py
code served (permissive licence) · get_code("6b3bb30734078091")
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 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 numpy as np

# Create a sample list of behaviors
behaviors = [
    {"action": 1, "reward": 0.5},
    {"action": 2, "reward": 1.0},
    {"action": 3, "reward": -0.5},
    {"action": 4, "reward": 0.2},
    {"action": 5, "reward": 0.8},
    {"action": 6, "reward": 0.3},
]

bs = 2

ARGS = {
    "behaviors": behaviors,
    "bs": bs,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type list, ndim 2, 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
tsallis Ran
ran on a synthesized input
sigeisler/reinforce-attacks-llms/baselines/reinforce/pgd_utils.py
code served (permissive licence) · get_code("58f9a2c4596dfdf1")
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 (2,) 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 a valid probability tensor of shape (batch=2, categories=4)
# Probabilities must sum to 1 along the last dimension
ps = torch.tensor([
    [0.1, 0.2, 0.3, 0.4],
    [0.25, 0.25, 0.25, 0.25]
], dtype=torch.float32)

# Tsallis entropy parameter q (must be > 0)
q = 0.5

# Boltzmann constant k
k = 1.0

ARGS = {
    "ps": ps,
    "q": q,
    "k": k
}
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 (2,) — shape (2,) 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
generate Not yet run
unverified (harvested, no recorded run)
sigeisler/reinforce-attacks-llms/baselines/reinforce/generate_utils.py
code served (permissive licence) · get_code("eb149efd17214bc3")
How it ran

no invocation recorded.

load_model_and_tokenizer Not yet run
unverified (harvested, no recorded run)
sigeisler/reinforce-attacks-llms/baselines/model_utils.py
code served (permissive licence) · get_code("0313a63291b892b7")
How it ran

no invocation recorded.

multinomial_num_samples_1 Not yet run
unverified (harvested, no recorded run)
sigeisler/reinforce-attacks-llms/baselines/reinforce/generate_utils.py
code served (permissive licence) · get_code("d66e02fe1262afdb")
How it ran

no invocation recorded.

sample_control Not yet run
unverified (harvested, no recorded run)
sigeisler/reinforce-attacks-llms/baselines/reinforce/gcg_utils.py
code served (permissive licence) · get_code("2dcbffb713bbdbf4")
How it ran

no invocation recorded.

x_bounded_sigmoid Not yet run
unverified (harvested, no recorded run)
sigeisler/reinforce-attacks-llms/baselines/reinforce/pgd_utils.py
code served (permissive licence) · get_code("8ae92478b9151299")
How it ran

no invocation recorded.

Also present in other papers' code

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

FunctionAlso present inEarliest-datedOthers named
get_nonascii_toks 1 other paper
1 later
2408.14866 (2024-08)
Advancing Adversarial Suffix Transfer Learning on Aligned Large Language Models

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

Current LLM alignment methods are readily broken through specifically crafted adversarial prompts. While crafting adversarial prompts using discrete optimization is highly effective, such attacks typically use more than 100,000 LLM calls. This high computational cost makes them unsuitable for, e.g., quantitative analyses and adversarial training. To remedy this, we revisit Projected Gradient Descent (PGD) on the continuously relaxed input prompt. Although previous attempts with ordinary gradient-based attacks largely failed, we show that carefully controlling the error introduced by the continuous relaxation tremendously boosts their efficacy. Our PGD for LLMs is up to one order of magnitude faster than state-of-the-art discrete optimization to achieve the same devastating attack results.

For agents

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

get_harvested_code_for_paper("2402.09154")
get_code_for_paper("2402.09154")
have("2402.09154")

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

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

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

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

Connect an agent — have() is free.