Abstract
With the rapid development of large language models (LLMs), they are not only used as general-purpose AI assistants but are also customized through further fine-tuning to meet the requirements of different applications. A pivotal factor in the success of current LLMs is the alignment process. Current alignment methods, such as supervised fine-tuning (SFT) and reinforcement learning from human feedback (RLHF), focus on training-time alignment and are often complex and cumbersome to implement. Therefore, we develop InferAligner, a novel inference-time alignment method that utilizes cross-model guidance for harmlessness alignment. InferAligner utilizes safety steering vectors extracted from safety-aligned model to modify the activations of the target model when responding to harmful inputs, thereby guiding the target model to provide harmless responses. Experimental results show that our method can be very effectively applied to domain-specific models in finance, medicine, and mathematics, as well as to multimodal large language models (MLLMs) such as LLaVA. It significantly diminishes the Attack Success Rate (ASR) of both harmful instructions and jailbreak attacks, while maintaining almost unchanged performance in downstream tasks.
Introduction
Aligning Large Language Models (LLMs) to be "harmless" is a critical step in their deployment. Traditionally, this is achieved during training via Supervised Fine-Tuning (SFT) or Reinforcement Learning from Human Feedback (RLHF). However, these processes are computationally expensive and often lead to an "alignment tax," where safety training inadvertently degrades the model's performance on specialized tasks like mathematics or medical reasoning. Furthermore, when developers fine-tune a safe base model for specific domains, the model frequently "forgets" its safety training, becoming vulnerable to harmful instructions or jailbreak attacks. InferAligner addresses these issues by providing a "plug-and-play" safety layer that operates during inference.
Methodology: Cross-Model Guidance
The core of InferAligner is Activation Engineering through cross-model guidance. The process involves three key steps:
- Extracting Safety Related Vectors (SRVs): The method identifies the "direction" of safety in a model's latent space by calculating the mean difference in activations between harmful and harmless prompts.
- Cross-Model Steering: Instead of using vectors from the unaligned target model, InferAligner utilizes Safety Steering Vectors (SSVs) extracted from a robustly aligned source model (e.g., LLaMA2-CHAT).
- The Guidance Gate: To avoid the alignment tax, a "gate" mechanism is employed. During inference, the system first assesses the input intent. If the intent is harmless, the model functions normally. If harmful intent is detected, the SSV is applied to the model's activations, shifting the output distribution toward a refusal.
Experimental Setup
The authors evaluated InferAligner across several domains and modalities:
- Safety: Evaluated using AdvBench and a custom jailbreak test set of 500 prompts.
- Utility: Tested on specialized tasks in Finance (FPB, FiQA SA), Medicine (MedQA), and Mathematics (GSM8K).
- Multimodal Safety: Introduction of MM-Harmful Bench, a dataset of 100 instructions requiring joint image-text reasoning for safety evaluation.
Key Results and Insights
InferAligner demonstrates a massive reduction in Attack Success Rate (ASR). In the finance domain, ASR dropped from 38.4% to 0.0%, and against jailbreak attacks, it fell from 48.2% to 0.2%.
A key finding is that safety concepts are transferable across different models; a "refusal direction" from LLaMA2-CHAT can guide a fine-tuned domain model or even a multimodal model like LLaVA. Importantly, InferAligner maintains "zero utility loss." Unlike SFT-based methods that often see a 1-3% accuracy drop in specialized tasks, InferAligner preserves the exact performance of the base model for benign queries because the intervention is conditional.
Conclusion
InferAligner offers a robust and efficient alternative to traditional training-time alignment. By leveraging cross-model guidance and a conditional activation shift, it secures specialized and multimodal models against harmful inputs without sacrificing performance on downstream tasks. Future work will explore automating hyperparameter selection and testing transferability across diverse architectural families.
Summary updated