MergeAlign: Combining domain and alignment vectors for a better knowledge-safety trade-off in LLMsCombining Domain and Alignment Vectors to Achieve Better Knowledge-Safety Trade-offs in LLMs
The authors propose the model merging method MergeAlign, which adds the domain vector and the alignment vector, giving Llama-3-8B medical/financial expert models safety rates of 99.67%/99.70% on BeaverTails, close to the aligned model while domain performance is largely maintained.
- Domain-expert LLMs in medicine, finance, and other fields often lack safety alignment or lose domain capability during alignment (alignment tax); how to make expert models safe at low cost while preserving domain capability is the problem the authors aim to solve.
- Propose MergeAlign: starting from the same pretrained base, separately compute the domain vector of the domain-expert model and the alignment vector of the aligned model, and add the two back to the base to obtain an aligned domain-expert model, with no additional training.
- On the Llama-3-8B medicine/finance expert models, MergeAlign reaches 99.67/99.70 on BeaverTails, close to the aligned model, and the domain average score differs from the expert model by less than 0.5 points; it outperforms ORPO/DPO and Slerp. It is effective for Qwen-2.5-Coder, but both safety and math capability decrease for Qwen-2.5-Math.
- The authors note: the evaluation uses only Llama-3-Instruct as the aligned model, and its safety score is near perfect; only 7B/8B models are tested; the preference-alignment comparison is based on LoRA; the method assumes the existence of a general instruction model with high alignment; and the scope of generalization on code/math is limited.
- Evaluated models
- medicine-Llama-3-8Bfinance-Llama-3-8BQwen-2.5-Coder-7BQwen-2.5-Math-7B
- Benchmarks
- BeaverTailsHH-RLHF red team subsetPubMedQARCTUSMLEChemProtMQPFPBFiQA_SAHeadlineConvFinQANERMBPPMATHGSM8K
- Metrics
- safe/unsafe 分类准确率(安全率)领域基准准确率L2 distance
The researchers propose a merging-based alignment method, MergeAlign, which interpolates domain vectors with alignment vectors to make domain expert models safer while maintaining utility. Applied to Llama3 expert models in the medical and financial domains, the method significantly improves alignment levels with little to no degradation in domain benchmark performance. The study also analyzes the effects of model merging through model similarity metrics and the contribution of each merged model.
Paper analysis
What problem does this paper attempt to solve?
How to add safety alignment to domain-expert LLMs at low cost without losing domain capability (the alignment tax problem).
Core problem: domain-expert LLMs (such as medical and financial models) often lack safety alignment and can generate harmful content, while explicit safety training harms domain capability.
- Problem scenario: the authors point out that domain-expert models, obtained through pretraining from scratch, continued pretraining, or domain instruction tuning, either lack explicit safety training or have their safety capability damaged during domain fine-tuning (citing Bhardwaj et al., 2024), and thus may generate harmful content.
- Shortcomings of existing approaches: explicit alignment training requires resources, training data, and alignment expertise, and may harm domain utility due to over-alignment, i.e., alignment tax (citing Lin et al., 2024).
- Core observation: the authors observe that simple interpolation between the domain vector and the alignment vector yields a model that is safer while retaining domain utility.
- The paper proposes: MergeAlign, an alignment method based on model merging that treats model merging as a cheap proxy for explicit alignment training; it is evaluated on Llama3 medicine/finance expert models and Qwen-2.5 code/math models, and also uses model similarity metrics to analyze the merging effect.
- Nature note: this is an alignment/training method, not an attack or defense; the paper does not involve a threat model, and its goal is to make existing expert models refuse harmful prompts on safety benchmarks without training.
What related research exists?
Related work is divided into four groups: domain-expert models, model merging and task vectors, preference alignment methods, and safety evaluation benchmarks and judge models.
Domain-expert LLMs
- Wu et al. (2023) (BloombergGPT) — pretrained a domain model from scratch on financial data; Sankarasubbu and Pal (2024) (OpenBioLLMs) — continued pretraining in the medical domain; Yue et al. (2023) (Mammoth) — domain instruction tuning. The paper uses these works to illustrate three construction routes for domain-expert models.
- Cheng et al. (2024) (Instruction Pre-training) — the medicine-Llama-3-8B and finance-Llama-3-8B used in this paper come from this work, and the domain benchmarks also follow its setup.
Model merging and task vectors
- Wortsman et al. (2022) (Model Soups) — averages the weights of multiple fine-tuned models; Ilharco et al. (2023) (Task Arithmetic) — proposed task vectors and vector arithmetic, and is the direct basis of MergeAlign.
- Yadav et al. (2023) (TIES-Merging) — addresses parameter interference during merging; Yu et al. (2024) (DARE) — randomly drops delta parameters to reduce interference, and this paper uses it in the appendix as pre-merge pruning.
- Bhardwaj et al. (2024) — uses task arithmetic to perform safety re-alignment on fine-tuned models, and is closest to this paper's approach; the paper cites it only in the introduction to explain that domain fine-tuning harms safety, without an explicit comparison.
Preference alignment and alignment tax
- Rafailov et al. (2024) (DPO), Hong et al. (2024) (ORPO) — preference optimization methods; this paper uses LoRA to train DPO/ORPO on HH-RLHF for domain-expert models as comparison baselines.
- Lin et al. (2024) — proposed the concept of alignment tax, which the paper uses to explain the phenomenon that safety training harms domain utility.
Safety evaluation and judges
- Ji et al. (2023) (BeaverTails), Ganguli et al. (2022) (HH-RLHF red-team subset) — safety evaluation data; Llama-Guard-3 and MD-Judge-v0.1 (Li et al., 2024) — serve as the judges that output safe/unsafe classifications for the two benchmarks, respectively.
Baselines and benchmarks: the comparison methods are Slerp (Shoemake, 1985, full-parameter interpolation), ORPO, and DPO (both using LoRA, trained for 3 epochs on a 7000-example subset of HH-RLHF); the safety benchmarks are BeaverTails and the HH-RLHF red-team subset, and the domain benchmarks follow Cheng et al. (2024).
The authors position this paper as: generalizing task vectors from "tasks" to "domains" and "alignment," and using model merging as an efficient, low-cost proxy for explicit alignment training.
How does the paper address this problem?
MergeAlign: adds the domain vector and the alignment vector back to the pretrained base, obtaining an aligned domain-expert model without training.
Overall idea: generalize task arithmetic from task vectors to domain vectors and alignment vectors; MergeAlign uses vector addition to "transplant" the safety capability of a general instruction model onto domain-expert models, with no training throughout, and can be completed on CPU.
Problem setup and formalization
- Let the base pretrained model be θ; it yields a domain-expert model θd through continued pretraining/fine-tuning on domain data, and an aligned model θa through general instruction tuning and preference alignment.
- Domain vector τd = θd − θ, alignment vector τa = θa − θ.
- Merge formula: θ̂ = θ + τd + τa, i.e., adding the two delta vectors back to the base to obtain an aligned domain-expert model (Figure 1).
Weighted interpolation variant
- Appendix B proposes the weighted form θ̂ = θ + ατd + βτa.
- The authors report that α and β set to 1 works best, and values less than 1 harm performance (Figure 5); the authors speculate this is related to parameter interference, and believe DARE-style random parameter dropping may alleviate it, leaving it for future work.
Comparison methods
- Slerp: performs spherical interpolation on all parameters of θd and θa (rather than interpolating only the delta vectors); Appendix C uses gradient slerp, with the per-layer weight gradients of the domain expert being [0, 0.5, 1, 0.5, 0] and those of the aligned model being [1, 0.5, 0, 0.5, 1].
- ORPO/DPO: uses LoRA (rank 16, alpha 32, dropout 0.05), trained for 3 epochs on a 7000-example subset of HH-RLHF, batch size 12, learning rate 8e-06 (Appendix A); the authors state that LoRA was chosen due to resource constraints.
Evaluation method
- Safety: 3021 prompts from the BeaverTails test set, with outputs judged as safe/unsafe by Llama-Guard-3; 659 prompts from the HH-RLHF red-team subset, with outputs judged by MD-Judge-v0.1.
- Domains: medicine uses PubMedQA, RCT, USMLE, ChemProt, MQP; finance uses FPB, FiQA_SA, Headline, ConvFinQA, NER; code uses MBPP, and math uses MATH (Appendix D additionally has GSM8K).
- Analysis: computes the L2 distance between the parameters of the merged model and those of each source model to examine model similarity.
What experiments did the paper conduct?
Compare the safety-domain trade-off of MergeAlign with Slerp, ORPO, and DPO on Llama-3-8B medical/financial and Qwen-2.5 code/math models.
Experimental setup
- Models tested: medicine-Llama-3-8B and finance-Llama-3-8B from the Llama-3-8B series (domain experts, θd) and Llama-3-8B-Instruct (aligned model, θa); Qwen-2.5-Coder-7B and Qwen-2.5-Math-7B from the Qwen-2.5 series (θd) and Qwen-2.5-Instruct-7B (θa).
- Safety benchmarks: 3021 prompts from the BeaverTails test set (judged by Llama-Guard-3); 659 prompts from the HH-RLHF red-team subset (judged by MD-Judge-v0.1), with the metric being the proportion judged safe.
- Domain benchmarks: 5 medical and 5 financial datasets (see Question 3), code MBPP, math MATH/GSM8K.
- Baselines: Slerp (full-parameter interpolation), ORPO and DPO (LoRA, trained on 7000 HH-RLHF examples); the appendix additionally has full-parameter ORPO and a Safe-RLHF dataset variant.
- Infrastructure: a single A100 80GB GPU; one model merge takes about 3-4 minutes (Appendix E).
- The paper does not report the number of repeated experiments or variance.
Main results
According to Table 4, 5, 6 (Llama-3-8B series; safety is the proportion judged safe, domain is the average accuracy):
Swipe horizontally to read the table
Method Medical domain average Financial domain average BeaverTails (med/fin) HH red team (med/fin) Domain expert 61.37 74.47 67.8 / 79.70 29.74 / 52.95 Aligned model 58.07 70.84 99.3 / 99.3 98.78 / 98.78 ORPO(LoRA) 59.75 74.14 81.46 / 83.74 45.82 / 49.62 DPO(LoRA) 59.45 70.42 68.52 / 68.48 39.6 / 35.05 Slerp 62.2 73.24 95.46 / 96.25 92.26 / 92.41 MergeAlign 61.33 74.07 99.67 / 99.70 98.33 / 97.87 - The authors state that MergeAlign achieves safety performance comparable to the instruction-aligned model, with only a small drop in domain performance, and a knowledge-safety trade-off better than either source model individually.
- Slerp has similar domain performance, but is about 10% worse on safety benchmarks (the authors' words "about 10%"; in Table 6, BeaverTails is about 3-4 points worse and HH red team about 5-6 points worse), which the authors suggest may stem from interference in full-parameter interpolation.
- The authors state that ORPO improves the medical expert model's safety by about 15% (referring to BeaverTails 67.8→81.46), but brings no gain in the financial domain and degrades domain performance, consistent with the alignment tax literature.
Model similarity analysis
- Compute the L2 distance between the parameters of the merged model and the source models (Figure 3).
- The authors report: the ORPO(LoRA) fine-tuned model is very similar to the domain-expert model (possibly because LoRA changes few parameters); MergeAlign and Slerp are approximately equidistant from the two source models.
- The authors suggest this equidistance may be why the merged model has a better trade-off, but emphasize that this is a preliminary analysis and may not correlate with downstream performance, leaving it for future research.
Generalization on code and math
- Apply MergeAlign to the Qwen-2.5-7B series (Figure 4).
- Code: the authors report improved safety with very little effect on coding ability. Math: both safety and math ability decrease, which the authors suggest may be because core mathematical reasoning ability is sensitive to parameter changes.
- Appendix D: using DARE to drop 50% of delta parameters before merging still does not generalize to math tasks, but is better than standard MergeAlign in both domain and safety (on GSM8K, Figure 6; the main text gives no specific values).
Other ablations and analyses
- Full-parameter ORPO (Table 2, MedLlama): BeaverTails 89.55, medical 58.58, safety higher than the LoRA version but lower than MergeAlign's 99.67, with a slight domain drop.
- ORPO with the Safe-RLHF dataset (Table 3, MedLlama): BeaverTails 86.13, medical 60.29, both improved over the HH-RLHF version.
- Slerp weight variants (Table 1): giving the aligned model higher weight gives medical 61.67/safety 88.52, giving the domain model higher weight gives medical 62.14/safety 79.42, gradient slerp gives medical 62.2/safety 92.26; the authors suggest weight bias affects the trade-off and requires further study.
- Qualitative analysis (Appendix D): the authors manually inspect outputs on harmful prompts in BeaverTails; the unaligned expert model gives harmful responses, which turn into refusals after MergeAlign.
- Fine-grained results (Table 4, 5): MergeAlign is lower than the expert model on individual datasets (e.g., PubMedQA 66.4 vs 68.9, ConvFinQA 67.58 vs 74.42, NER 58.19 vs 63.56); the authors note that each method has strengths and weaknesses on different datasets.
What are some points that can be further explored?
The authors list limitations such as a single aligned model, limited scale, and reliance on LoRA, and plan to study safety-oriented merging methods and domain adaptation.
Limitations and future directions noted by the authors
- Merging results often depend on the respective capabilities of the merged models; the evaluation uses only Llama-3-Instruct as the aligned model, and its safety score is near perfect, so using a weaker aligned model might provide deeper insight (Limitations).
- Results use only 7B/8B parameter models, and conclusions may change with scale (Limitations).
- The comparison with explicit preference alignment relies on LoRA; full fine-tuning might yield different conclusions (Limitations).
- The method assumes the existence of a general instruction model with high alignment performance; how well a model custom-aligned with public data would perform is worth studying (Limitations).
- Evaluation is needed on more domains, base models of different quality, and more preference alignment methods; the code/math evaluation only partially covers this, with limited scope (Limitations).
- Future work: design safety-oriented merging methods drawing on safety vectors and safety basins; make MergeAlign domain-adaptive; open-source the models and merging configuration suite; evaluate on domain-specific safety benchmarks; conduct deeper theoretical analysis (Conclusion, Limitations).
Scope of experimental coverage
- The models tested are the Llama-3-8B series (medical, financial) and the Qwen-2.5-7B series (code, math), 4 domain/task expert models in total.
- Safety evaluation uses 3021 BeaverTails prompts and 659 HH-RLHF red-team subset prompts, automatically judged by Llama-Guard-3 and MD-Judge-v0.1 respectively; the paper does not report agreement between the judges and human annotation.
- The preference-alignment comparison uses LoRA (a 7000-example subset of HH-RLHF); the appendix adds one set each of full-parameter ORPO and Safe-RLHF (MedLlama only).
- The paper does not report the number of repetitions, confidence intervals, or statistical significance tests; the code/math experiments do not give specific values for Figure 4.
- The model similarity analysis uses only L2 distance, which the authors describe as a preliminary analysis.
Summarize the main content of the paper
MergeAlign uses vector addition to merge the domain and alignment vectors, bringing the safety rate of Llama-3-8B domain-expert models close to the aligned model without training.
An alignment methods paper: addressing the problem that domain-expert LLMs lack safety alignment while explicit alignment harms domain capability (alignment tax), the authors propose MergeAlign—taking a domain vector τd and an alignment vector τa separately from the same pretrained base, and adding them back to the base to obtain an aligned domain-expert model, with no training required and runnable on CPU.
- Method highlights: a generalization of task arithmetic; simple addition with α=β=1 works best; compared with Slerp full-parameter interpolation and LoRA versions of ORPO/DPO.
- Main results (Llama-3-8B, Table 4-6): MergeAlign on BeaverTails scores 99.67 for medical and 99.70 for financial, close to the aligned model's 99.3; domain averages are 61.33/74.07, essentially on par with the expert models' 61.37/74.47; on the HH red-team subset, 98.33/97.87.
- Comparison: Slerp is about 3-6 points lower on safety; ORPO(LoRA) medical expert scores 81.46 on BeaverTails, with no safety gain for financial; full-parameter ORPO is only 89.55.
- Generalization: for Qwen-2.5-Coder-7B, safety improves with little effect on coding ability; for Qwen-2.5-Math-7B, both safety and math ability decrease.
- Authors' conclusion: model merging can serve as an efficient, low-cost proxy for explicit alignment training; the merged model being approximately equidistant from the two source models may be why the trade-off is better; the authors plan to study safety-oriented merging methods, domain adaptation, and to open-source the model suite.
Related papers
- Disentangling Steering VectorsAnalysis / interpretabilityarXiv