Papers › Targeted Vaccine: Safety Alignment for Large Language Models against Harmful...

Targeted Vaccine: Safety Alignment for Large Language Models against Harmful Fine-Tuning via Layer-wise Perturbation

13 Oct 2024arXiv:2410.09760archive 2025-07-28

Guozhi Liu, Weiwei Lin, Tiansheng Huang, Ruichao Mo, Qi Mu, Li Shen

Harmful fine-tuning attack poses a serious threat to the online fine-tuning service. Vaccine, a recent alignment-stage defense, applies uniform perturbation to all layers of embedding to make the model robust to the simulated embedding drift. However, applying layer-wise uniform perturbation may lead to excess perturbations for some particular safety-irrelevant layers, resulting in defense performance degradation and unnecessary memory consumption. To address this limitation, we propose Targeted Vaccine (T-Vaccine), a memory-efficient safety alignment method that applies perturbation to only selected layers of the model. T-Vaccine follows two core steps: First, it uses gradient norm as a statistical metric to identify the safety-critical layers. Second, instead of applying uniform perturbation across all layers, T-Vaccine only applies perturbation to the safety-critical layers while keeping other layers frozen during training. Results show that T-Vaccine outperforms Vaccine in terms of both defense effectiveness and resource efficiency. Comparison with other defense baselines, e.g., RepNoise and TAR also demonstrate the superiority of T-Vaccine. Notably, T-Vaccine is the first defense that can address harmful fine-tuning issues for a 7B pre-trained models trained on consumer GPUs with limited memory (e.g., RTX 4090). Our code is available at https://github.com/Lslland/T-Vaccine.

PaperPDFCodeCode Syntology ran

In Syntology Open this paper in Syntology's Atlas, the map of the papers in Syntology's graph and their citations.

For agents, Syntology's MCP tool lists every function and class Syntology harvested from this paper and whether it ran (how to connect): get_harvested_code_for_paper(arxiv_id="2410.09760")

Code

Syntology Ran 12 of 12 code samples harvested from 1 repository linked to this paper; 0 have no recorded run. Of those that ran: 1 ran · honoured contract; 5 ran · our draft was wrong; 3 ran · fixture could not drive it; 3 ran with no contract checked.

By repository: official repository: 12 samples from 1 repository, 12 ran. The run record, sample by sample. “Ran” means executed on a synthesized input, not that the code is correct or reproduces the paper.

lslland/t-vaccine officialmentioned in paperpytorchApache-2.0 report

Repository list and official/mentioned flags are the archive's, frozen 2025-07-28. Reachability, where shown, is from one Syntology probe window (2026-09-16 to 2026-09-18); repositories not probed show nothing. GitHub stars are not tracked.

Code Syntology ran Syntology

12 samples harvested; 12 ran; 1 honoured the contract we drafted; 0 have no recorded run. Read from Syntology's graph 2026-09-24; that is when this build read the record, not when the samples ran.

1ran · honoured contract
5ran · our draft was wrong
3ran · fixture could not drive it
3ran

Licence: 0 of the 12 samples are pointer only, meaning Syntology does not serve that copy's text. This page shows no code text for any sample; each one links to its file in the repository.

Harvested from lslland/t-vaccine. “Ran” means the sample executed on a synthesized input. It does not mean the output is correct, and nothing here reproduces the paper's results. “Honoured” and “violated” refer to a contract Syntology drafted from the code itself; “our draft was wrong” and “fixture could not drive it” are failures of Syntology's instrument, not of the code.

Each sample ends with its code_sha256, Syntology's identity for that exact code. An agent fetches the stored sample with Syntology's MCP tool get_code(code_sha256="…") (how to connect); click an identity to copy that call.

Repository labels, per sample. official repository: The archive marks this repository official for the paper. named in the paper: The archive records that the paper mentions this repository; it is not marked official. community (archive-listed): In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper. found in paper text by Syntology: Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted. community: Not in the archive's code links for this paper; a community repository Syntology harvested. Samples from a repository marked official are listed first. Licence labels name the repository's licence as recorded at harvest. “Pointer only” means Syntology does not serve that copy's text, for one of four reasons: no licence file was found; the licence was not identified; the licence is recorded as permissive but that copy's record is not marked cleared; or the licence is outside the permissive list Syntology serves text under (MIT, Apache-2.0, BSD and similar). Some licences outside that list permit redistribution, such as WTFPL, and GPL-3.0 under its conditions; they are simply not on the list. Hover a licence label for the reason. File links open the file on GitHub at the default branch, which may have changed since the harvest.

repeat_kv lslland/t-vaccine/models/modeling_gemma_my.py official repository ran · fixture could not drive it fingerprinted Apache-2.0 (permissive) · 30d7eec482ebf6b1 · report
adapt_dimension_b2a lslland/t-vaccine/loss_func/repnoise_loss.py official repository ran · honoured contract fingerprinted Apache-2.0 (permissive) · 175778f00233af46 · report
apply_rotary_pos_emb lslland/t-vaccine/models/modeling_qwen2_my.py official repository ran · fixture could not drive it Apache-2.0 (permissive) · d61c483a3c2b3156 · report
apply_rotary_pos_emb lslland/t-vaccine/models/modeling_gemma_my.py official repository ran · our draft was wrong Apache-2.0 (permissive) · bac65c3dafaec040 · report
apply_rotary_pos_emb lslland/t-vaccine/models/modeling_llama_my.py official repository ran · fixture could not drive it Apache-2.0 (permissive) · f725bc2d76076485 · report
apply_rotary_pos_emb lslland/t-vaccine/models/modeling_gemma2_my.py official repository ran Apache-2.0 (permissive) · 134eef3e8182bf6f · report
get_leaf_modules_with_grad lslland/t-vaccine/trainer.py official repository ran Apache-2.0 (permissive) · 582b8f13a818c0e2 · report
jload lslland/t-vaccine/utils.py official repository ran · our draft was wrong Apache-2.0 (permissive) · d07d04439cd1d44f · report
masked_token_ce_loss lslland/t-vaccine/loss_func/repnoise_loss.py official repository ran · our draft was wrong fingerprinted Apache-2.0 (permissive) · dbc0448520ee9257 · report
register_activation_hook lslland/t-vaccine/loss_func/repnoise_loss.py official repository ran · our draft was wrong Apache-2.0 (permissive) · c605efc9460b6c33 · report
repeat_kv lslland/t-vaccine/models/modeling_gemma2_my.py official repository ran fingerprinted Apache-2.0 (permissive) · ca6c6aa5c8b23b27 · report
rotate_half lslland/t-vaccine/models/modeling_gemma2_my.py official repository ran · our draft was wrong fingerprinted Apache-2.0 (permissive) · b99eea6376d1e212 · report

Tasks

Safety AlignmentTAR

Results from the paper archive 2025-07-28

No leaderboard rows for this paper in the archive.

Report a problem or propose a change · a person checks every report against the paper or source before anything changes; decisions are listed on /corrections