
SLDR: Defending Against Malicious Fine-tuning via Selective Layers Recovery and Dynamic Routing
SLDR is a post-fine-tuning defense that protects aligned LLMs from malicious fine-tuning-as-a-service attacks, which can quietly erode refusal behavior while keeping task performance intact. It trains a LoRA recovery adapter only on the layers with the most extreme (signed) safety sensitivity scores, then uses representation-based dynamic routing to activate that adapter solely for malicious queries at inference time. Evaluated across four model architectures, five downstream tasks, and four harmful-content benchmarks, it drives the average harmful score on Llama3.1/SST2 from 11.54 down to 0.08 while preserving downstream accuracy, and stays near zero even at poisoning ratios up to 0.9.
What it claims
SLDR repairs a model that a user has compromised through a fine-tuning service. It retrains just two transformer layers with LoRA, then routes only prompts that look malicious through that repair. The motivating finding is that layer-wise safety sensitivity has a sign. Scaling some layers up increases refusal. Scaling others up suppresses it. Most layers do little either way. Prior layer-localization work (Safety Layers, LARF) found where safety lives but not which direction each layer pushes.
How it works
- Signed probe, run on the aligned model before any fine-tuning. - For each layer l, scale its attention and FFN weights by (1+α) and by (1−α). - Count refusals on an over-refusal dataset: benign prompts containing safety terms such as "kill time". - The layer's score is κ_l = max over α ∈ {0.1, 0.2} of (c⁺ − c⁻)/α.
- Layer selection. Take only l_max (the most refusal-enhancing layer) and l_min (the most refusal-suppressing layer). All other layers stay frozen.
- Recovery. Start from the attacked LoRA-fine-tuned model. Train a LoRA adapter on those two layers only, using an alignment set of harmful prompts paired with safe responses (from BDS, an extended BeaverTails).
- Routing. - Take the last-token hidden state at l_max and L2-normalize it. - Compute the mean cosine-similarity gap between the prompt and N harmful reference prompts versus N benign reference prompts. - If the score is above τ (default τ = 0), use the recovered model. Otherwise use the attacked task model unchanged.
flowchart LR P[User prompt] --> H[Hidden state at l_max] RU[Harmful refs] --> S[Malicious score] RS[Benign refs] --> S H --> S S -->|"> tau"| R[Attacked model + recovery LoRA] S -->|"<= tau"| A[Attacked model, no adapter]
Evidence
Default setting: Llama3.1-8B-Instruct, SST2, |D_train| = 1000, LoRA attack. Results are harmful score (HS, lower is better) / fine-tune accuracy (FA), averaged over poison ratios ρ ∈ {clean, 0.05, 0.1, 0.15, 0.2}:
| Method | HS | FA |
|---|---|---|
| SFT, no defense | 11.54 | 92.39 |
| Antidote | 1.50 | 84.86 |
| STAR-DSS | 1.52 | 85.48 |
| BDS | 1.68 | 91.79 |
| Lisa | 1.70 | 74.17 |
| One-shot FT | 4.14 | 90.55 |
| Panacea | 5.20 | 89.29 |
| SLDR | 0.08 | 92.32 |
The point is that the other defenses trade task accuracy for safety: Lisa loses about 18 points of FA and Antidote about 7. SLDR stays essentially at SFT accuracy.
Across architectures (SST2, ρ = 0.1, HS / FA):
| Model | SFT | SLDR | Best baseline |
|---|---|---|---|
| Mistral-7B-Instruct-v0.2 | 49.40 / 95.18 | 0.10 / 95.07 | Antidote, 7.10 HS |
| Qwen2.5-7B-Instruct | — | 0.20 / 94.61 | — |
| Llama3-8B-Instruct | — | 0.20 / 92.78 | — |
Across tasks (Llama3.1):
- SLDR's HS is ≤ 0.20 on all four tasks shown: SST2, AGNEWS, GSM8K and AlpacaEval.
- FA is never above plain SFT, because benign traffic uses the attacked model as-is.
- On GSM8K, SLDR's 72.10 FA is below several baselines; Lisa reaches 76.70 there.
How to use it
Code: https://github.com/Stardust457/SLDR.
What you need:
- Access to the aligned base model, to run the probe.
- An over-refusal probe set.
- A safety alignment set.
- Harmful and benign reference prompt sets. The paper takes these from LARF and from another cited source.
Serving cost: you must host the task model both with and without the recovery adapter. Every request pays for one hidden-state extraction at l_max before routing.
Limits
- Routing is the critical point. A harmful prompt that scores at or below τ is answered by the compromised model with no repair. The visible text does not report router false-negative rates or adaptive attacks against the router. A τ sensitivity study is referenced in Section 5.2 but is not in the fetched text.
- The fetched page is truncated in the experiments section. The fetched text:
- does not contain the ρ up to 0.9 result;
- does not contain the both-layers ablation;
- lists Magicoder as a downstream task but shows no Magicoder results;
- does not define the harmful-score metric.
- Attack scope: only LoRA-based malicious fine-tuning is evaluated, on 7–8B instruct models.
- The probe is scored by counting refusals. The IsRefusal classifier is only described in an appendix.
Organisations named here
- SST2
Technologies named here
- Llama-3.1
- LoRA
- Llama
Techniques named here
- SLDR
- Selective Layers Recovery
- Dynamic Routing
- Layer-wise safety sensitivity diagnostics
- LoRA recovery adapter
Related in ai-safety

