Repurposing Language Models into Embedding Models: Finding the Compute-Optimal Recipe

Albert Q. Jiang, Alicja Ziarko, Bartosz Piotrowski, Wenda Li, Mateja Jamnik, Piotr Miłoś

Introduction

Text embeddings are fundamental to modern information retrieval, retrieval-augmented generation (RAG), and semantic search. While Large Language Models (LLMs) excel at generation, their internal representations are not inherently optimized for semantic similarity tasks. Consequently, practitioners often "repurpose" these models through contrastive fine-tuning. However, the design space—encompassing model size, data volume, and tuning methods—is vast. This paper establishes a systematic "recipe" for compute-optimal text embedding models, deriving scaling laws that guide these choices under fixed computational budgets.

Methodology

The study utilizes the Pythia suite of decoder-only models, ranging from 14M to 2.8B parameters. The authors explore several fine-tuning strategies:

  • Full Fine-tuning: Updating all model weights.
  • Parameter-Efficient Fine-Tuning (PEFT): Specifically LoRA (Low-Rank Adaptation) with varying ranks.
  • Block Freezing: Freezing early layers to reduce trainable parameters.
  • Bias-only Tuning (BitFit): Updating only bias terms.

Training was conducted on the English partition of the BAAI BGE dataset (200 million pairs), and performance was evaluated using a representative subset of the Massive Text Embedding Benchmark (MTEB). By fitting power-law formulas to training losses across six log-spaced compute budgets, the authors identify the "compute-optimal frontier."

The Compute-Optimal Frontier

A primary finding is the existence of a crossover point between fine-tuning methods. For smaller computational budgets, full fine-tuning remains the most efficient path to minimizing loss. However, as the budget exceeds approximately $9.06 \times 10^{16}$ FLOPs, LoRA emerges as the superior strategy.

Figure 1: The compute-optimal frontier illustrates the crossover point where LoRA becomes more efficient than full fine-tuning as the budget increases.

Scaling Dynamics and Model Selection

The research reveals that for any given compute budget, there is an optimal model size. If a model is too small, it lacks the capacity to capture semantic nuances; if it is too large, the budget is exhausted on too few training steps. Interestingly, the "IsoFLOP" profiles—curves representing constant compute—are relatively flat near their minima. This suggests that practitioners have some flexibility in model selection without incurring a severe performance penalty, provided they stay near the optimal range.

Figure 3: Loss vs. model parameters for full fine-tuning (a) and block freezing (b). The U-shaped curves indicate that for every budget, an optimal parameter count exists.

Key Practical Insights

  • LoRA Configuration: For most budgets, a LoRA rank between 32 and 128 is the "sweet spot." Extremely high ranks (e.g., 2048) can actually degrade performance due to optimization challenges.
  • Bias Tuning is Ineffective: BitFit consistently underperformed all other methods, regardless of the budget, making it a poor choice for embedding tasks.
  • Mean Pooling is Essential: Averaging hidden states (mean pooling) consistently outperformed using the "last token" representation, which is common in generative tasks.
  • Loss as a Proxy: The study found a strong correlation (Spearman’s rank of -0.892) between training contrastive loss and downstream MTEB performance, validating the use of scaling laws to predict real-world utility.

Conclusion

By formalizing the relationship between compute, model size, and tuning methodology, this work provides a predictive framework for building high-quality embedding models. The provided "recipe" allows researchers to bypass expensive trial-and-error, moving directly to the most efficient configuration for their specific hardware and time constraints. Future work may extend these laws to include inference-time costs and the impact of hard negative mining.

Summary updated

BibTeX
@inproceedings{jiang2024repurposing,
  author = {Albert Q. Jiang and Alicja Ziarko and Bartosz Piotrowski and Wenda Li and Mateja Jamnik and Piotr Miłoś},
  title = {{Repurposing Language Models into Embedding Models: Finding the Compute-Optimal Recipe}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=kVL5rvkqGG},
}
Figure