DaMoC: Efficiently Selecting the Optimal Large Language Model for Fine-tuning Domain Tasks Based on Data and Model Compression

Wei Huang, Huang Wei, Yinggui Wang

TL;DR

Choosing the right Large Language Model (LLM) for a specific domain can be a time-consuming process. This paper introduces DaMoC, a framework that efficiently selects the optimal LLM for fine-tuning by combining data filtering and model compression techniques. DaMoC significantly reduces training time (up to 20x) while ensuring the selection of the best-performing model for domain tasks.

What Problem Does This Paper Address?

Large Language Models (LLMs) have demonstrated impressive general capabilities. However, their performance often falters when applied to specialized domains like medicine or law, necessitating fine-tuning with domain-specific data. The proliferation of open-source LLMs presents a new challenge: how to quickly and effectively identify the best LLM to fine-tune for a particular domain task. Existing research has focused on hyperparameter tuning for fine-tuning, but not on the crucial step of selecting the optimal base LLM itself. This paper aims to bridge this gap by proposing a method that rapidly identifies the most suitable LLM, ensuring both speed and stable performance.

Methods

DaMoC tackles the LLM selection problem from two main angles: data and model.

Data Level: * Data Filtering: The authors categorize existing data filtering methodologies into three paradigms: 1. Distribution-aware: Focuses on data diversity. 2. Quality-aware: Emphasizes the quality of data points. 3. Hybrid: Combines both distribution and quality. They found that distribution-aware methods generally perform best for model selection. To enhance critical information density, they also use perplexity and iterative rewriting to compress text, achieving about a 50% reduction in length.

  • Token Compression: This technique aims to shorten input text length, primarily for inference, but is adapted here for the fine-tuning phase. It involves compressing questions and responses by assessing token importance based on question-related perplexity and then using iterative rewriting to maintain semantic coherence.

Model Level: * Layer-wise Pruning: The authors measure the importance of each layer in a model by calculating the cosine similarity between its input and output activations. Layers with high similarity are deemed less important and are pruned. * Sparse Merging: To preserve model accuracy and parameter distribution after pruning, a novel sparse merging paradigm is introduced. This involves subtracting pre-trained parameters from pruned layer parameters and then merging these "task vectors" with unpruned layers using a magnitude-based sparsification metric. This approach successfully prunes about 25% of layers.

Datasets

The authors evaluated DaMoC on four key tasks and datasets:

  • Medical Q&A: PubMedQA
  • Financial Q&A: BillSum
  • General Q&A: Alpaca (fine-tuned on the base model)
  • Reading Comprehension: SQuAD

They used eight open-source LLMs for their experiments, including Llama3.1, Qwen2.5, Gemma2, GLM4, Mistral-8B, Phi-3-small, Yi1.5, and Internlm2.5.

Key Insights and Ideas

  • Distribution-aware data filtering is key for LLM selection: The study highlights that focusing on data diversity is more crucial for identifying the optimal LLM for fine-tuning than solely focusing on data quality.
  • High data filtering ratios can be detrimental: Filtering too much data (e.g., >90%) can lead to suboptimal model selection, suggesting a balance is needed.
  • Combining data and model compression is powerful: The synergy between data filtering, token compression, and model pruning in DaMoC leads to significant improvements in both selection accuracy and efficiency.
  • Layer-wise pruning is more effective than pruning specific components (MHA, MLP, HZ): Experiments showed that pruning individual components did not yield significant speedups, whereas layer-wise pruning proved more beneficial.
  • DaMoC can also guide fine-tuning method selection: The framework demonstrated an ability to identify the optimal fine-tuning strategy (e.g., Full fine-tuning vs. LoRA) for a given model and task.

Key Results

  • Significant Time Savings: DaMoC reduces training time by approximately 20-fold compared to standard fine-tuning. For example, a test set of 3000 samples took 15.28 minutes to train for one epoch, while DaMoC required only 0.72 minutes.
  • Optimal LLM Selection: The framework consistently selects the optimal pre-trained LLM for domain-specific tasks across various datasets and models.
  • Model Compression: DaMoC can prune approximately 25% of model layers while maintaining performance.
  • Token Compression: Achieves a compression rate of approximately 50% for text.
  • Stability: Even when DaMoC impacts accuracy slightly, it still reliably selects the optimal model, demonstrating robustness.

Limitations and Future Work

  • Dependency on Pre-trained Weights (Wpre): The layer pruning component of DaMoC requires access to the pre-trained weights (Wpre) of the model. If these are not available (e.g., for proprietary models or when fine-tuning from a base model), only data filtering and token compression can be applied. Future work will explore pruning methods that do not rely on Wpre.
  • Broader Fine-tuning Method Exploration: While DaMoC has shown promise in selecting between full fine-tuning and LoRA, its effectiveness with a wider range of fine-tuning methods needs further investigation. This is a key area for future research.

Summary updated

BibTeX
@inproceedings{huang2025damoc,
  author = {Wei Huang and Huang Wei and Yinggui Wang},
  title = {{DaMoC: Efficiently Selecting the Optimal Large Language Model for Fine-tuning Domain Tasks Based on Data and Model Compression}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2025},
}
Figure