SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2501.17433 · 2025

Virus: Harmful Fine-tuning Attack for Large Language Models Bypassing Guardrail Moderation

arXiv · PDF · Open in the Atlas

Code that ran

8 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; 2 honoured the contract we drafted, 0 violated it and 3 have no contract verdict; 3 failures of our instrument; 3 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/2501.17433.json · badge: /api/ran/2501.17433.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
git-disl/virus canonical (classifier label)
classifier basis not recorded on the link
8 ran · 3 no recorded run
FunctionStatusWhere it lives
adapt_dimension_b2a Ran
ran, honoured the contract we drafted
git-disl/virus/loss_func/repnoise_loss.py
pointer only (licence: Apache-2.0); the stored copy get_code serves, from ChanLiang/VAA, is pointer only (licence: NONE) · get_code("175778f00233af46")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (Apache-2.0), but get_code serves the stored copy, first harvested from ChanLiang/VAA, 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.

extract_answer_number Ran
ran, honoured the contract we drafted
git-disl/virus/gsm8k/pred_eval.py
code served (permissive licence) · get_code("c9b7e712eaf8afe1")
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 float, 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.

ANSWER_PROMPT = 'The final answer is: '

def extract_answer_number(sentence: str) -> float:
    import re
    sentence = sentence.replace(',', '')
    pred = [s for s in re.findall('-?\\d+\\.?\\d*', sentence)]
    if not pred:
        return float('inf')
    segment = sentence.split(ANSWER_PROMPT)
    if len(segment) > 1:
        pred_answer = segment[1]
        pred_answer = [s for s in re.findall('-?\\d+\\.?\\d*', pred_answer)]
        if len(pred_answer) > 0:
            pred_answer = pred_answer[0]
        else:
            pred_answer = float(pred[-1])
    else:
        pred_answer = float(pred[-1])
    if isinstance(pred_answer, str):
        try:
            pred_answer = float(pred_answer)
        except ValueError as e:
            pred_answer = float('inf')
    return pred_answer


ARGS = {
    'sentence': 'The final answer is: 42.5'
}
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 float, 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
find_source_len Ran
ran on a synthesized input
git-disl/virus/trainer.py
code served (permissive licence) · get_code("f44037b3edbce98a")
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 numpy as np

torch.manual_seed(0)

class MockTokenizer:
    def __init__(self):
        self.vocab = {
            "### Response:": [100, 101],
            "input": [50],
            "This is input": [50, 51, 52],
            "Some text\n\n### Response:": [1, 2, 3, 4, 5, 100, 101]
        }
    
    def decode(self, token_list, skip_special_tokens=True):
        # Return a simple string with the marker
        return "This is input\n\n### Response: some response"
    
    def encode(self, text, add_special_tokens=False):
        # Return a list of token ids
        if "### Response:" in text:
            return [100, 101]
        elif "input" in text.lower():
            return [50, 51, 52]
        else:
            return [1, 2, 3]

# Create input_ids tensor
input_ids = torch.tensor([[50, 51, 100, 101, 2, 3, 4, 5]], dtype=torch.long)

# Create tokenizer
tokenizer = MockTokenizer()

ARGS = {
    "input_ids": input_ids,
    "tokenizer": tokenizer
}
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 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
jload Ran
ran; our contract draft was wrong, not the code
git-disl/virus/datasets_visualizer.py
code served (permissive licence) · get_code("d07d04439cd1d44f")
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 io
import json
import tempfile
import os

# Create a temporary JSON file with test data
temp_dir = tempfile.mkdtemp()
temp_file = os.path.join(temp_dir, "test.json")

test_data = {
    "key1": "value1",
    "key2": [1, 2, 3],
    "key3": {"nested": "dict"}
}

with open(temp_file, 'w') as f:
    json.dump(test_data, f)

# Define ARGS with the file path
ARGS = {
    "f": temp_file,
    "mode": "r"
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
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 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
list_to_dataset Ran
ran on a synthesized input
git-disl/virus/datasets_visualizer.py
code served (permissive licence) · get_code("fbff253d3f3e0ded")
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.

from datasets import Dataset, DatasetDict

# Create sample list data with dictionaries
# The function expects a list of dicts where all dicts have the same keys
list_data = [
    {"text": "hello", "label": 0, "score": 0.5},
    {"text": "world", "label": 1, "score": 0.8},
    {"text": "test", "label": 0, "score": 0.3}
]

ARGS = {
    "list_data": list_data
}
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 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
load_suffix Ran
ran on a synthesized input
git-disl/virus/datasets_visualizer.py
code served (permissive licence) · get_code("d4de99126314df09")
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 torch
import os
import tempfile

# Create a temporary directory structure for the test
temp_dir = tempfile.mkdtemp()
ckpt_dir = os.path.join(temp_dir, 'ckpt', 'suffix', 'gsm8k')
os.makedirs(ckpt_dir, exist_ok=True)

# Create a sample checkpoint file with some content
poison_data_start = 42
lamb = 0.5
filename = f'virus_llama3_topk_64_bs_128_lamb_{lamb}_data_index_{poison_data_start}.ckpt'
filepath = os.path.join(ckpt_dir, filename)

with open(filepath, 'w', encoding='utf-8') as f:
    f.write('sample_suffix_content_here\n')

# Monkey-patch the path to use our temp directory
import sys
original_cwd = os.getcwd()
os.chdir(temp_dir)

ARGS = {
    'poison_data_start': 42,
    'lamb': 0.5,
}
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 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
masked_token_ce_loss Ran
ran; our contract draft was wrong, not the code
git-disl/virus/loss_func/repnoise_loss.py
pointer only (licence: Apache-2.0); the stored copy get_code serves, from ChanLiang/VAA, is pointer only (licence: NONE) · get_code("dbc0448520ee9257")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (Apache-2.0), but get_code serves the stored copy, first harvested from ChanLiang/VAA, 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.

register_activation_hook Ran
ran; our contract draft was wrong, not the code
git-disl/virus/loss_func/repnoise_loss.py
pointer only (licence: Apache-2.0); the stored copy get_code serves, from ChanLiang/VAA, is pointer only (licence: NONE) · get_code("c605efc9460b6c33")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (Apache-2.0), but get_code serves the stored copy, first harvested from ChanLiang/VAA, 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.

calculate_drift2first_embedding Not yet run
unverified (harvested, no recorded run)
git-disl/virus/utils.py
code served (permissive licence) · get_code("5f4323e1e87dc83b")
How it ran

no invocation recorded.

get_leaf_modules_with_grad Not yet run
unverified (harvested, no recorded run)
git-disl/virus/trainer.py
code served (permissive licence) · get_code("88c8a24923c625a1")
How it ran

no invocation recorded.

track_embedding Not yet run
unverified (harvested, no recorded run)
git-disl/virus/utils.py
code served (permissive licence) · get_code("bda772180d04ada3")
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, 8 are also present in other papers whose code we hold (8 with at least one paper dated earlier, 0 the same month, 5 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
jload 46 other papers
42 dated earlier, 3 later, 1 same year, order not determinable
2302.13971 (2023-02)
LLaMA: Open and Efficient Foundation Language Models
2305.12870 (2023-05)
Lion: Adversarial Distillation of Proprietary Large Language Models
2305.13068 (2023-05)
Making Language Models Better Tool Learners with Execution Feedback
and 43 more not named here
masked_token_ce_loss 4 other papers
3 dated earlier, 1 later
2405.14577 (2024-05)
Representation Noising: A Defence Mechanism Against Harmful Finetuning
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
and 1 more not named here
adapt_dimension_b2a 3 other papers
2 dated earlier, 1 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
2506.03850 (2025-06)
Vulnerability-Aware Alignment: Mitigating Uneven Forgetting in Harmful Fine-Tuning
register_activation_hook 3 other papers
2 dated earlier, 1 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
2506.03850 (2025-06)
Vulnerability-Aware Alignment: Mitigating Uneven Forgetting in Harmful Fine-Tuning
extract_answer_number 2 other papers
2 dated earlier
2408.09600 (2024-08)
Antidote: Post-fine-tuning Safety Alignment for Large Language Models against Harmful Fine-tuning
2409.18169 (2024-09)
Harmful Fine-tuning Attacks and Defenses for Large Language Models: A Survey
get_leaf_modules_with_grad 2 other papers
1 dated earlier, 1 later
2409.18169 (2024-09)
Harmful Fine-tuning Attacks and Defenses for Large Language Models: A Survey
2503.00555 (2025-03)
Safety Tax: Safety Alignment Makes Your Large Reasoning Models Less Reasonable
calculate_drift2first_embedding 1 other paper
1 dated earlier
2409.18169 (2024-09)
Harmful Fine-tuning Attacks and Defenses for Large Language Models: A Survey
track_embedding 1 other paper
1 dated earlier
2409.18169 (2024-09)
Harmful Fine-tuning Attacks and Defenses for Large Language Models: A Survey

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

Recent research shows that Large Language Models (LLMs) are vulnerable to harmful fine-tuning attacks -- models lose their safety alignment ability after fine-tuning on a few harmful samples. For risk mitigation, a guardrail is typically used to filter out harmful samples before fine-tuning. By designing a new red-teaming method, we in this paper show that purely relying on the moderation guardrail for data filtration is not reliable. Our proposed attack method, dubbed Virus, easily bypasses the guardrail moderation by slightly modifying the harmful data. Experimental results show that the harmful data optimized by Virus is not detectable by the guardrail with up to 100\% leakage ratio, and can simultaneously achieve superior attack performance. Finally, the key message we want to convey through this paper is that: \textbf{it is reckless to consider guardrail moderation as a clutch at straws towards harmful fine-tuning attack}, as it cannot solve the inherent safety issue of the pre-trained LLMs. Our code is available at https://github.com/git-disl/Virus

For agents

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

get_harvested_code_for_paper("2501.17433")
get_code_for_paper("2501.17433")
have("2501.17433")

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

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

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

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

Connect an agent — have() is free.