Abstract
Fine-tuning large language models (LLMs) for specific tasks often results in "catastrophic forgetting," where the model's general-purpose capabilities significantly decline. We present LM-Cocktail, a resilient model merging strategy that mitigates this issue. By blending a fine-tuned specialist model with the original base model and other domain-specific "peer" models, LM-Cocktail preserves target task expertise while maintaining or enhancing general performance. Weights for the merge are automatically calculated using a few-shot validation set, providing a computationally efficient post-refinement method.
Introduction
The prevailing "pre-train then fine-tune" paradigm effectively creates specialists for domains like medical Q&A or code generation. However, this specialization typically comes at the cost of general reasoning and knowledge. Existing mitigation strategies, such as experience replay or complex regularization, are often computationally expensive or difficult to integrate into standard pipelines. LM-Cocktail addresses these challenges through a simple parameter-averaging approach that requires no additional training and maintains the original model's inference latency.
Methodology
LM-Cocktail utilizes weighted averaging of model parameters to create a "cocktail" of three model types:
- The Specialist ($M_t$): The model fine-tuned on the target task.
- The Base Model ($M_b$): The original pre-trained generalist (e.g., Llama-2).
- Peer Models ($M_d$): Models fine-tuned on diverse, unrelated domains.
Automated Weight Calculation
A key innovation of LM-Cocktail is its automated weighting mechanism. Instead of manual tuning, the system uses a tiny (e.g., 5-shot) validation set from the target domain. The prediction loss of each candidate model is calculated on these examples. A softmax function applied to the negative loss determines the mixing proportions, ensuring that models contributing most to the target task receive higher weights. This allows the cocktail to leverage cross-domain synergies, where a peer model might unexpectedly aid a new target task.
Experimental Results
The researchers evaluated LM-Cocktail using Llama-2-7b-chat and BGE-base-v1.5 across nine diverse fine-tuning tasks and extensive benchmarks including FLAN, MMLU, and MTEB.
Mitigating Catastrophic Forgetting
As shown in the evaluation on the AG News dataset, standard fine-tuning improved target task performance but caused a drop in general task performance from 46.80% to 38.58%. LM-Cocktail successfully restored this general performance to 47.73% while maintaining a high target accuracy of 94.46%.
General Knowledge Enhancement
On the MMLU benchmark, LM-Cocktail achieved an average score of 48.01, surpassing both the base Llama (45.87) and Llama using 5-shot in-context learning (46.65). These results suggest that merging specialists can consolidate general knowledge rather than just preventing its loss. Furthermore, the system proved remarkably efficient, with 5-shot weight calculation performing nearly as well as using over 100 examples.
Conclusion
LM-Cocktail provides a robust, low-cost solution for maintaining model resilience during fine-tuning. By treating model merging as a post-refinement step, it offers the benefits of an ensemble without increased inference costs. Future work may explore more granular merging techniques, such as Fisher-weighted averaging or parameter pruning, to further optimize the blending of specialized knowledge.
Summary updated