NeurIPS 2026QuestionsPapersAreasAboutMarkdown

Tcell: Mitigating Harmful Fine-tuning for Large Language Models via Gradient Alignment

Tiansheng Huang, Virat Vishnu Shejwalkar, Oscar Chang, Ling Liu

NeurIPS page · OpenReview · Open on the map

Category: AI Safety, Security & Alignment › Alignment Collapse and Mitigation in Fine-Tuning · Type: new method · Keywords: harmful fine-tuning defense, gradient alignment, LLM safety, fine-tuning-as-a-service, gradient-based attacks

Areas: Safety & Security › Safe Alignment › Fine-Tuning Safety Alignment

Summary

Tcell is a gradient alignment defense that mitigates harmful fine-tuning attacks on large language models by aligning harmful and safety gradients during safety alignment.

Explained to a 5-year-old

When you teach a big robot brain new things, someone could give it bad lessons that make it say mean things. We want to stop that. We found that if we make the new lessons look similar to the good lessons, the robot won't learn the bad ones. So we added a rule to help the lessons match. This helps keep the robot safe.

Explained to a 5-year-old, longer

When you let a big computer learn new things by showing it lots of examples, you might accidentally teach it something bad. This can happen when the learning is done through an online service that anyone can use. The bad teaching can make the computer say mean or unsafe things, which is dangerous. To stop this, we look at how the computer changes its internal rules when it learns. We discovered that if the changes caused by bad examples look similar to the changes caused by good safety rules, the bad learning is weakened. This similarity is measured by how close two directions are in a special math space. We created a new rule that pushes the bad learning direction to point more like the safety direction. This rule is added during the safety training stage, before the harmful fine-tuning happens. By doing this, the harmful updates become aligned with the safety updates, making them less effective. We tested this idea on several tasks and showed it works better than other methods. The idea is backed up by both experiments and a simple mathematical proof. This helps keep large language models safe when they are fine-tuned through APIs.

For a technical reader

The paper addresses a safety vulnerability in fine-tuning-as-a-service platforms where malicious users can inject harmful data to degrade model safety. It shows that aligning the gradient of harmful updates with the safety gradient-measured by cosine similarity-reduces the impact of such attacks. The proposed defense, called Tcell, introduces a regularizer that enforces this alignment during the safety alignment stage, ensuring that fine-tuning steps point in directions similar to the safety-preserving updates. Empirical results and a theoretical analysis demonstrate that the aligned updates significantly mitigate harmful fine-tuning compared to alternative designs. The implementation is open-sourced, offering a practical tool for developers to harden their models against gradient-based poisoning attacks.

Problem

Fine-tuning-as-a-service providers are vulnerable to harmful fine-tuning attacks where attackers can inject malicious data to compromise model safety alignment.

Method

The approach introduces a regularizer that aligns the harmful gradient with the safety gradient during the safety alignment stage, encouraging fine-tuning updates to have high cosine similarity with the safety gradient. This gradient alignment is derived from an empirical and theoretical analysis and is compared against alternative designs without alignment.

Contributions

The paper identifies a key property that higher cosine similarity between fine-tuning updates and safety gradients mitigates harmful fine-tuning, and proposes a regularizer that enforces this alignment, providing both empirical and theoretical validation against alternative defenses.

Practical relevance

The work addresses a critical safety risk for fine-tuning-as-a-service providers, helping ensure that API-based fine-tuning does not compromise model safety.

This page was written by language models from the title and abstract of each paper, and the answers were checked by two other models. It can be wrong: check the paper itself. Suggest a correction