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

Authors: albert q jiang
alicja  ziarko
bartosz  piotrowski
wenda  li
mateja  jamnik
piotr  miłoś
Venue: NeurIPS_cc_2024_Conference
Published: 2024-05-14 22:15:21

Abstract: Text embeddings are essential for tasks such as document retrieval, clustering, and semantic similarity assessment. In this paper, we study how to contrastively train text embedding models in a compute-optimal fashion, given a suite of pretrained decoder-only language models. Our innovation is an algorithm that produces optimal configurations of model sizes, data quantities, and fine-tuning methods for text-embedding models at different computational budget levels. The resulting recipe, which we obtain through extensive experiments, can be used by practitioners to make informed design choices for their embedding models. Specifically, our findings suggest that full fine-tuning and Low-Rank Adaptation fine-tuning produce optimal models at lower and higher computational budgets respectively.

Main paper: 
 related work: 
 Embedding models Training neural networks to represent text as continuous vectors was popularised by word2vec [Mikolov et al., 2013] , which produced semantically meaningful embeddings of words. BERT [Devlin et al., 2019] and the further contrastively trained SimCSE [Gao et al., 2021c] quickly established encoder-only transformers as the go-to architecture for embedding text.More recently, decoder-only transformers have become increasingly more powerful and efficient at the same time [Brown et al., 2020 , Touvron et al., 2023 , Jiang et al., 2023] . Building an embedding model based on them utilises the knowledge from their pretraining, and thus it is a natural step. Neelakantan et al. [2022] set a successful precedent in this paradigm by initialising embedder training with decoder-only GPT models.Notably, the current open state-of-the-art (the top open model on the MTEB [Muennighoff et al., 2023b] leaderboard, as of 18 May 2024), SFR-Embedding-Mistral [Meng et al., 2024] , is also fine-tuned from the decoder-only Mistral 7B [Jiang et al., 2023] .Benchmarks for embedding models Embedding models are versatile in their applications. Therefore, a broad and diverse benchmark to provide a robust measure of their performance is called for. The first such benchmark was BEIR introduced by Thakur et al. [2021] . It has nine different information retrieval tasks (e.g., duplicate-question retrieval or citation-prediction) on 18 datasets. Recently, Muennighoff et al. [2023b] introduced MTEB (Massive Text Embedding Benchmark), which is substantially larger than BEIR and, in addition to information retrieval, has seven other types of tasks (e.g., clustering, summarisation, and pair classification) using 58 datasets and covering 112 languages. The authors also provide a leaderboard that currently contains more than 220 entries.Scaling laws Scaling laws predict the performance of models at larger scale (e.g., more parameters, more data) from experiments at smaller scales. Kaplan et al. [2020] and Hoffmann et al. [2022] used empirically fitted laws to predict the performance of neural language models at different model sizes and data scales, making it possible to calculate the optimal configuration before training. Muennighoff et al. [2023a] inspected model training in data-constrained, multi-epoch regime. Frantar et al. [2023] looked at scaling laws for language models in the context of weight sparsity. Zhang et al. [2024] investigates the scaling laws for model fine-tuning, including parameter efficient methods: LoRA [Hu et al., 2022] and prompt tuning [Lester et al., 2021] . They show that the scaling laws and the best fine-tuning method are task dependent. Biderman et al. [2024] investigates the properties of fine-tuning models with LoRA in detail, showing that LoRA underperforms full fine-tuning when fine-tuning the models on mathematical or code datasets.The single most related investigation is a concurrent work Fang et al. [2024] , where the scaling laws for encoder models for retrieval are investigated. There are significant differences in the settings we consider. Our focus is on investigating the process of fine-tuning decoder-only models for good quality embeddings. Moreover, our main goal is to find which strategy for achieving good embeddings is optimal in a budget-restricted settings, while taking into account the popularity of applying parameter efficient methods for fine-tuning, like LoRA or partial model freezing. In spirit, our work is similar to AutoML [He et al., 2021b] , which aims to automatically find the optimal ML architecture. However, our method goes beyond and targets the data and the training method as well.Parameter-efficient fine-tuning Modern language models have a lot of parameters, and fine-tuning them using consumer-grade hardware is difficult in general. Notwithstanding the recent turn to in-context learning, fine-tuning is still necessary for most applications. A range of techniques have been developed recently, to make fine-tuning more efficient [Houlsby et al., 2019 , Li and Liang, 2021 , Qi et al., 2022 , He et al., 2021a] . These approaches are all applicable to embedding models. Muennighoff [2022] explored a simple parameter-efficient approach to repurpose GPT models into embedding models where only the bias tensors of the transformer model are updated [Zaken et al., 2022] . [Sun et al., 2024] developed a parameter-efficient method designed specifically for fine-tuning embedding models. However, a systematic study of what parameter-efficient methods are optimal under what scenarios has not been performed, which is the aim of our work. 
scaling laws and compute-optimal models: 
 The constraint optimisation problem that we aim to solve is the following: given a fine-tuning corpus and a family of pre-trained decoder-only language models of different sizes, minimise the contrastive loss subject to a fixed computational budget.Following Hoffmann et al. [2022, Section 3 .2], we perform a hyperparameter search at different computational budget levels to obtain IsoFLOP profiles of models. We then find the optimal models at each level, fit a loss-size scaling law, and extrapolate it to unobserved FLOP budgets. We only focus on contrastive fine-tuning since state-of-the-art text embedder models are all trained in such fashion [Gao et al., 2021c , Neelakantan et al., 2022 , Wang et al., 2023] .We refer to the models with the lowest contrastive loss achievable with fixed computational costs as compute-optimal models. We focus on optimising three components specifically: model size, data quantity, and fine-tuning method. For each fine-tuning method, we find the optimal model configuration at each FLOP level and establish the relationship between the computational budget and optimal loss for that method. Then, for any unobserved computational budget, we use the scaling laws to predict the loss, and pick the method that gives the lowest loss and its corresponding configuration.We start with a standard decoder-only transformer model architecture, such as GPT architectures [Radford et al., 2019 , Brown et al., 2020] , or Pythia [Biderman et al., 2023] . Given a sequence of tokens S = (s 1 , . . . , s n ), we pass them through the transformer model and average the last layer representations as the embedding vector emb(S)= 1 n n i=1 h i ∈ R m, where h i is the last layer hidden state of the token s i . Some works apply the last token pooling approach [Neelakantan et al., 2022] instead of using mean pooling described above. Here, however, we default to mean pooling as in [Wang et al., 2022 , Li et al., 2023 , Günther et al., 2023] . It is a more popular method overall, and moreover, we find it to yield better performance, which we demonstrate in Appendix E.3.We use the contrastive loss as in [Neelakantan et al., 2022] , which has been widely used in fine-tuning pre-trained language models [Wang et al., 2022 , 2023 , Günther et al., 2023] .For a batch of n examples, that is, n pairs of texts (x 1 , y 1 ), . . . , (x n , y n ), we only treat examples (x i , y i ) n i=1 as positive matches, and all the pairs (x i , y j ), where i ̸ = j as negatives. Concretely, we calculate the batch contrastive loss in two steps. First, we calculate the logits:logits[i,j] = sim(emb(x i ), emb(y j )) • exp(τ ),where sim is the cosine similarity function between two vectors, and τ ∈ R is the temperature. The total loss is the sum of the cross entropy losses on both the row and the column directions:1 labels = [0, 1, ..., n -1] l_r = cross_entropy(logits, labels) l_c = cross_entropy(logits.T, labels) loss = (l_r + l_c) / 2Hard negatives in contrastive learning In our contrastive learning setting, we use in-batch examples as negatives. Some datasets additionally include tailored negative examples (hard negatives) for each positive datapoint, which can be incorporated into the contrastive loss to promote learning more precise representations. Moreover, there are works that focus on approaches for mining hard negatives which result in better training data in the context of specific downstream tasks [Xiong et al., 2021 , Zhan et al., 2021] .However, recent works aiming at training powerful, general-purpose embedding models that do rely on datasets with hard negatives often arrive at embeddings by having two distinct training phases: the expensive "unsupervised" phase one involving vast data from the internet, and then a "supervised" phase two, often targeted towards a specific downstream task, where training data of lower quantity -but containing high-quality hard negatives -is used [Li et al., 2023 , Wang et al., 2022 , Xiao et al., 2023] . Since the first phase is more expensive, it will benefit more from scaling laws such as the ones we derive.Moreover, the usefulness of hard negatives highly depends on their quality, which may vary wildly between datasets. Therefore, conclusions reached with hard negatives are more closely tied to the datasets the models are trained on. Since we develop scaling laws agnostic to the dataset, we abstain from using hard negatives in our experiments.The most basic and straightforward method of fine-tuning is full fine-tuning, where all the weights of the model are updated under the contrastive objective.We also study parameter-efficient fine-tuning (PEFT) methods, which are popular, especially in academic settings, because they have lower memory requirements than full fine-tuning. Since the PEFT methods update fewer parameters in the network than there are in total, the relationship between their computational cost, model size, and data quantity is different from full fine-tuning. Hence, we individually study the IsoFLOP profiles for four fine-tuning methods, namely, full fine-tuning, block freezing, bias-only tuning, and Low-Rank Adaptation (LoRA). Each of the last three non-standard methods is briefly characterised below.In this approach, we freeze the LLM token-embedding layer as well as the first k transformer blocks so that their parameters stay fixed during fine-tuning. Only the latter part of the model is back-propagated through and updates its parameters. To process the same amount of data, this is more computationally efficient than full fine-tuning. By varying the number of frozen blocks, one trades-off between the computational efficiency and flexibility of the model.Low-rank adaptation (LoRA) This method was introduced by Hu et al. [2022] to significantly reduce the number of trainable parameters of a neural network while maintaining high performance. LoRA introduces a small number of weights into the model and only trains those. It can be applied to a subset of dense layers of a model. It works by parametrising each dense layer W from a subset of linear layers of a model by two low-rank matrices A and B, and using W + AB instead of W , while training only A and B.Bias-only tuning In this method, only bias parameters are fine-tuned, and the rest of the model remains frozen. This approach was proposed by Zaken et al. [2022] as a parameter-efficient finetuning method for BERT encoders, and recently applied by Muennighoff [2022] to contrastively fine-tune GPT models.We denote the number of non-token-embedding parameters used in the forward pass to process each token as N F , the number of non-token-embedding parameters in backward-propagation as N B , the num-ber of non-token-embedding parameters updated during backward-propagation as N U , the total number of tokens processed as D, and the computational cost as C floating point operations (FLOP). Following the calculation by Kaplan et al. [2020] , we derive the relationship between the variables to beC = 2N F D + 2N B D + 2N U D.In case of full fine-tuning, every parameter is trainable, so N F = N B = N U , and thereforeC = 6N F D.This is the same as the formula for the computational cost used by Kaplan et al. [2020] for pre-training. 
experiments: 
 We first specify the relevant details of our experimental setup (Section 4.1). Next, we present the results of our experiments where we contrastively train a grid of models of different sizes, using different computational budgets, and apply different compute-optimal fine-tuning methods with varying hyperparameters (Section 4.2). Based on the collected data, we fit a mathematical formula describing the observed scaling laws (Section 4.3). Finally, we provide general observations and recommendations for efficient contrastive fine-tuning (Section 4.6). In these experiments2 we investigate the compute-constrained setup, but we present limited results on the data-constrained setup in Appendix D.We use eight decoder-only models from the Pythia suite [Biderman et al., 2023] , which have sizes 14M, 31M, 70M, 160M, 410M, 1B, 1.4B, and 2.8B of parameters. All the models have been pretrained on the Pile dataset [Gao et al., 2021a] for 300 billion tokens. We consider six computational budgets equally spaced on the log-scale: 1.5e15, 6e15, 2.4e16, 9.6e16, 3.8e17, and 1.5e18 FLOP.We fine-tune our models on the English partition of the BAAI BGE dataset [Xiao et al., 2023] , which contains 200 million semantically related (query, value) pairs from various internet sources such as Wikipedia and Stack Exchange. Note that since the BAAI BGE dataset is massive, for all our experiments we fine-tune for less than one epoch on this corpus, which allows us to avoid the effect of diminishing returns on subsequent training epochs [Muennighoff et al., 2023a] .We use the AdamW optimiser [Loshchilov and Hutter, 2019 ] and a cosine learning rate scheduler during training. The learning rate first goes through a linear warm-up phase of 1/10 of the total steps to a peak that is 1/10 of the pre-training peak learning rate, that is, to learning rates between 1.2 × 10 -5 and 6 × 10 -5 . Then, it decays in a cosine schedule to 1/10 of the maximum at the end of training. We employ gradient checkpointing [Chen et al., 2016] and GradCache [Gao et al., 2021b] to limit the peak GPU RAM usage during training. We use the Transformers [Wolf et al., 2020] library for the training of the models and use the Accelerate [Gugger et al., 2022] library to facilitate multi-GPU training. The batch size in our main line of experiments is 1024 sequences and the context length is 75 tokens. We give the full list of training hyperparameters in Appendix E.We also perform a less extensive grid of experiments to confirm that our findings are robust to change in hyperparameters. We find that our scaling law formula fitted to losses from models with batch size 1024 and context length of 75 tokens describes the loss for models trained with batch size 2048 and context length of 512 tokens very well. The detailed description and plots are shown in Appendix G.In addition to controlling the final training contrastive loss achieved by the models, we also measure downstream performance by evaluating the models on a representative subset of the MTEB benchmark [Muennighoff et al., 2023b] . The benchmark defines eight categories of tasks in total (e.g., retrieval, semantic text similarity). We select one task from each category by determining which ones are the most correlated with the performance for the whole category (see Appendix B for details).Full fine-tuning With full fine-tuning, the numbers of forward and backward parameters are the same, and the computational cost is straightforwardly C = 6N F D. In Figure 2a , we present the final contrastive loss vs. the number of parameters in the network on a log-log scale. Block freezing, loss vs model parameters(b)Figure 2 : (a) IsoFLOP profiles for full fine-tuning. The horizontal axis is the number of parameters in the model, and the vertical axis is the achieved loss. Both axes use log-scale. The optimal model size tends to increase as the computational budget increases. (b) IsoFLOP profiles for block freezing. The axes are the same as for full fine-tuning. Each data point denotes the optimal choice with respect to the fraction of active blocks during training, which is noted above the points. The optimal model size tends to increase as the computational budget increases, while the optimal active block fraction tends to slightly decrease as the model size gets larger.As expected, larger computational budgets consistently improve the loss. The IsoFLOP profiles resemble the classical ones from Hoffmann et al. [2022] . However, they tend to be flatter when the model size and computational budget are both small or both large. From the IsoFLOP profiles we can see what is the optimal model size that minimises the loss at each computational budget.Block freezing Since the Pythia models we experimented with have 6, 12, 16, 24 or 32 blocks, we freeze 0 6 , 1 6 , . . . , 5 6 of their blocks if their number is divisible by 6, and 0 8 , 1 8 , . . . , 7 8 if it is divisible by 8. In this setup, unlike for full fine-tuning, the token-embedding parameters always remain frozen even when all the transformer blocks are active. We have N B = N U < N F , and hence costC = 2N F D + 4N B D.In Figure 2b , we present IsoFLOP profiles for optimal loss at given model sizes. The trend of the profiles is quite similar to that of full fine-tuning presented in Figure 2a .We plot the loss with varying model sizes, computational budgets, and fractions of frozen blocks in Figure 3 . For smaller models (≤ 160M parameters), a lower fraction of frozen blocks leads to a lower final loss across all computational budgets. However, for larger models, using more than 70% of transformer often only marginally improves the model. For instance, for the model with 1e9 parameters, it is visible that freezing 50 -70% of the blocks gives the optimal results for all budgets except for 3.8e17 FLOP.Bias-only tuning Here we simply update only the bias parameters and not the weights of the model. Figure 4a shows the final training loss across all the model sizes and computational budgets. Increasing the computational budget decreases the optimal loss that is achievable, although the absolute values of the losses are high compared to other fine-tuning methods (the lowest achievable loss is above 0.4 with bias-only tuning).We use the LoRA implementation from the PEFT library [Mangrulkar et al., 2022] . We attach the adapter to all the dense layers of the network, and vary the adapter rank from 8 up to 2048, since even lower ranks resulted in an unstable training.We compare the loss obtained for each model size and computational budget for different LoRA rank values in Figure 5 . In almost all the combinations of the model size and computational budget, the rank of 32 or 128 (occasionally 512) is optimal. Wang et al. [2023] also use LoRA in the context of contrastive learning, but they fix the rank of 16 for their experiments. Our findings suggest that this choice should be reconsidered as being potentially suboptimal. LoRA, loss vs model parameters(b)Figure 4 : (a) IsoFLOP profiles for bias-only tuning. The horizontal axis is the number of parameters in the model, and the vertical axis is the achieved loss. Both axes use log-scale. The optimal model size increases as the computational budget increases, but the achievable loss is higher than for other fine-tuning methods. (b) IsoFLOP profiles for LoRA fine-tuning. The axes are the same as for bias-only tuning. Each data point denotes the optimal choice of the rank of LoRA matrices given the size of the model and the computational budget.In Figure 4b , we present IsoFLOP profiles for LoRA, where each data point represents the best LoRA rank setting for a given model size and computational budget. We see that the relationship between the optimal loss and the LoRA rank is quite consistent across model sizes and computational budgets, meaning that the rank hyperparameter is not very sensitive with respect to the two variables. In practice, this means that setting the LoRA rank to 32 or 128 are likely to be good default choices.Lookup table of optimal model sizes for different methods In Figure 6a (for full fine-tuning), Figure 6b (for LoRA), and Figure 13 (for freezing and bias tuning, in Appendix A), we visualise the relationship between the optimal model size and the computational budget. This makes looking up the optimal configuration for a given method at a given budget very convenient.In Figures 8, 9 , 10, and 11 (in Appendix A) we present the IsoFLOP plots of the downstream performance for all the four fine-tuning methods on the subset of the MTEB benchmark (described in Appendix B). Based on the performance results, we also present the optimal size choices per budget in Figure 15 in Appendix A (which is a performance analogue of Figure 13 ), and the optimal performance plot in Figure 12 (a performance analogue of Figure 1 ). These are mostly consistent with the loss results, albeit more noisy. In Appendix C, we demonstrate the significant correlation between the final training loss and the downstream task performance. We aim to model the behaviour of the loss L with an analytical formula as a function of the number of parameters N and the number of training tokens D. Following Hoffmann et al.[2022], we start with the following formula:L(N, D) = C + A N α + B D β, where A, B, C, α, β ∈ R + are real-valued parameters to be fitted. We found that this formula reasonably describes the loss behaviour for each of our methods. However, the fraction of trainable parameters is an important factor that is not considered in the model above. Following the modelling of Frantar et al. [2023] , we propose a modified formula:L(S, N, D) = C + a d log(D) + b d N α + a s (1 -S) bs + c s D β ,where S is an additional variable representing the trainable fraction of parameters, and a d , b d , a s , b s , c s ∈ R are additional coefficients to be fitted. We check that this new formula fits the data better than the original one, and conjecture that it can be used for larger models and larger computational budgets. More details about the derivation are presented in Appendix F.In Figure 1 , we plotted the best achievable losses against the computational budgets for the four finetuning methods considered. We then fitted a linear trend for each method on a log-log scale (equivalent to a power law relationship on a normal scale), and highlighted the lowest loss achievable at given budgets using the best corresponding fine-tuning method. We call the contour of this function that predicts the optimal loss across methods the compute-optimal frontier.The equation describing the full fine-tuning and the LoRA linear fits are ln(loss) = -0.21 • ln(budget) + 8.39, and ln(loss) = -0.22 • ln(budget) + 8.93, respectively. The equations suggest that at a budget lower than 9.06e16 FLOP, the optimal model is achieved with full fine-tuning, and at a higher budget, the optimal model is achieved with LoRA.With this, one becomes fully equipped to deduce the optimal recipe for text embedding model training for a given budget, by carrying out the procedure detailed in Algorithm 1. Note that although the block freezing approach is not predicted to be optimal at any budget, its performance is quite close to optimal. It also has the advantage of being easy to implement and has lower memory requirements, hence might be a good method to choose in practical use cases for larger budgets. Its optimal model size and fraction of active blocks hyperparameter can be worked out in the same way as for the other methods, with the help of Figure 3 and Figure 13 (left pane) in Appendix A.We briefly discuss the case of data-optimal frontier in Appendix D. We do not emphasise this setup due to it being less standard in language modelling research.To assess the generality of our findings, we investigate whether our analytical formula for predicting loss-fitted to datapoints from the Pythia suite (from Section 4.3) can also describe the behaviour of models from a different family. We conduct experiments on two language models, namely Gemma 2B [Mesnard et al., 2024 ] and Gemma 2 2B Team et al. [2024] . We trained both models with the computational budgets of 1.5e15, 6e15, 2.4e16, 9.6e16, 3.8e17, and 1.5e18 FLOP.Figure 7 presents results for Gemma 2B with both full fine-tuning and LoRA fine-tuning, while results for Gemma 2 2B are shown in Appendix A. In both cases, the formula provides a close approximation of the loss behavior. Although this study is limited to a single model size, it offers an initial indication that our findings may generalize to new models.We compile the takeaways from our extensive experiments by analysing each fine-tuning method individually and contrasting them afterwards.• Bias-only tuning is not a good fine-tuning strategy for embedding model training, as it is consistently worse than other strategies under IsoFLOP comparisons. • LoRA and block freezing are both effective approaches that improve the performance of the trained embedding models at higher budgets. For LoRA, the rank hyperparameter is not very sensitive to model size or computational budgets, with an optimum at around 128. • Finding the optimal recipe for fine-tuning embedding models requires a non-trivial effort, and the resulting optimal configurations are sometimes counter-intuitive (e.g., not using the largest model size possible). Carefully tuning hyperparameters is crucial and should be practised systematically. Red points are the models from runs on Pythia suite of size smaller than 2.8B, blue points are from runs on Pythia 2.8B and green points are from runs on Gemma 2B. The formula is fitted using the red points. 
limitations and future work: 
 Other families of models In this paper, we experimented with the Pythia [Biderman et al., 2023] suite of pre-trained models, which are of different sizes but have all been trained on 300B tokens. This means that they have been over-trained with respect to the Chinchilla scaling law [Hoffmann et al., 2022] to different degrees. The relationship between the optimal model size and the computational budget might differ for a suite of pre-trained models with different over-training ratios. We note that prior efforts [Dettmers et al., 2024] have found that fine-tuning conclusions reached with Pythia do generalise to other model families such as OPT [Zhang et al., 2022] , LLaMA [Touvron et al., 2023] , and BLOOM [Scao et al., 2022] , in the quantised setting. Indeed, in Section 4.5, we find that a model from a different family (Gemma [Mesnard et al., 2024] ) closely fits our loss predictions.Averaging Due to constraints on our computational resources, we ran each experiment exactly once. Averaging over multiple random seeds for the experiments would reduce the variance involved in each, and potentially result in less noisy conclusions. This is a straightforward extension that we leave to carry out in future work, should we have more resources. We also plan to evaluate the trained models on the entirety of the MTEB benchmark [Muennighoff et al., 2023b] , instead of using the losses from the last steps of training, to better reflect the performances of embedding models.Other forms of embedding readout We only experimented with mean pooling as a way of extracting embeddings from the transformer models. Other readout methods could be used, like the max pooling or extracting the hidden state corresponding to the end-of-sequence token, which might result in different scaling laws and optimal frontiers.Inference cost analysis In this work, we only focus on the training cost and refrain from taking inference costs into account. However, in certain practical scenarios, the latter may also be relevant. 
conclusions: 
 In this paper, we systematically investigated the influence of pre-trained model size, fine-tuning data quantity, and fine-tuning method in the final performance of embedding models repurposed from language models. As a result, we devised an algorithm that takes in the computational budget and returns the optimal configuration for the embedding model to train. This enables researchers who wish to adapt language models to embed their own data, especially those with limited computational resources, to obtain optimal text embedding models with greater efficiency in time and resources. 
safeguards: 
 Question: Does the paper describe safeguards that have been put in place for responsible release of data or models that have a high risk for misuse (e.g., pretrained language models, image generators, or scraped datasets)?Answer: [NA] Justification: The paper poses no such risks.Guidelines:• The answer NA means that the paper poses no such risks.• Released models that have a high risk for misuse or dual-use should be released with necessary safeguards to allow for controlled use of the model, for example by requiring that users adhere to usage guidelines or restrictions to access the model or implementing safety filters. • Datasets that have been scraped from the Internet could pose safety risks. The authors should describe how they avoided releasing unsafe images. • We recognize that providing effective safeguards is challenging, and many papers do not require this, but we encourage authors to take this into account and make a best faith effort.12. Licenses for existing assets Question: Are the creators or original owners of assets (e.g., code, data, models), used in the paper, properly credited and are the license and terms of use explicitly mentioned and properly respected?Answer: [Yes] Justification: We cite the original paper that has produced the dataset we use. We provide the dataset webpage, which contains the licence in Appendix I. We cite the relevant packages that we used in our code in section 4.1.Guidelines:• The answer NA means that the paper does not use existing assets.• The authors should cite the original paper that produced the code package or dataset.• The authors should state which version of the asset is used and, if possible, include a URL. • The name of the license (e.g., CC-BY 4.0) should be included for each asset.• For scraped data from a particular source (e.g., website), the copyright and terms of service of that source should be provided. • If assets are released, the license, copyright information, and terms of use in the package should be provided. For popular datasets, paperswithcode.com/datasets has curated licenses for some datasets. Their licensing guide can help determine the license of a dataset. • For existing datasets that are re-packaged, both the original license and the license of the derived asset (if it has changed) should be provided. • If this information is not available online, the authors are encouraged to reach out to the asset's creators. 
new assets: 
 Question: Are new assets introduced in the paper well documented and is the documentation provided alongside the assets?Answer: [Yes] Justification: The main asset introduced in the paper is the code, that is attached as a supplementary material and it does contain the documentation.Guidelines:• The answer NA means that the paper does not release new assets.• Researchers should communicate the details of the dataset/code/model as part of their submissions via structured templates. This includes details about training, license, limitations, etc. • The paper should discuss whether and how consent was obtained from people whose asset is used. • At submission time, remember to anonymize your assets (if applicable). You can either create an anonymized URL or include an anonymized zip file. 
crowdsourcing and research with human subjects: 
 Question: For crowdsourcing experiments and research with human subjects, does the paper include the full text of instructions given to participants and screenshots, if applicable, as well as details about compensation (if any)?Answer: [NA] Justification: The paper does not involve crowdsourcing nor research with human subjects.Guidelines:• The answer NA means that the paper does not involve crowdsourcing nor research with human subjects. • Including this information in the supplemental material is fine, but if the main contribution of the paper involves human subjects, then as much detail as possible should be included in the main paper. • According to the NeurIPS Code of Ethics, workers involved in data collection, curation, or other labor should be paid at least the minimum wage in the country of the data collector. 
institutional review board (irb) approvals or equivalent for research with human subjects: 
 Question: Does the paper describe potential risks incurred by study participants, whether such risks were disclosed to the subjects, and whether Institutional Review Board (IRB) approvals (or an equivalent approval/review based on the requirements of your country or institution) were obtained?Answer: [NA] Justification: The paper does not involve crowdsourcing nor research with human subjects.Guidelines:• The answer NA means that the paper does not involve crowdsourcing nor research with human subjects.• Depending on the country in which research is conducted, IRB approval (or equivalent) may be required for any human subjects research. If you obtained IRB approval, you should clearly state this in the paper. • We recognize that the procedures for this may vary significantly between institutions and locations, and we expect authors to adhere to the NeurIPS Code of Ethics and the guidelines for their institution. • For initial submissions, do not include any information that would break anonymity (if applicable), such as the institution conducting the review. 
: 
 Figure 1 : The optimal loss achieved using four different fine-tuning methods (full fine-tuning, only tuning the bias, low-rank adaptation, and freezing transformer blocks) at given budgets. The horizontal axis is the computational budget in floating point operations (FLOP) and the vertical axis is the contrastive loss. The X marks are datapoints and dotted lines are fitted linear trends for different methods. The solid black line is the "optimal frontier," i.e., the optimal loss achievable with a fixed budget and the best method.Text embeddings are vector representations of text sequences [Devlin et al., 2019] . A desired property of text embeddings is that their distribution in the embedding space reflects the semantic relations of the embedded texts. This property benefits multiple practical tasks [Muennighoff et al., 2023b] , such as document retrieval (where documents are ranked based on the distance between their representations and that of a query), document clustering, sentiment analysis, or textual similarity measurement.In the era of large language models (LLMs) that are pre-trained on vast textual data, it is a natural idea to capitalise on the language representations learned by these models to achieve high-quality embedding models. A common and effective approach has been to initialise an embedding model from a pre-trained LLM and fine-tune it with a contrastive loss [Neelakantan et al., 2022 , Izacard et al., 2022] . This phase is of crucial importance, as the quality of the embeddings extracted directly from a pre-trained LLM (e.g., by averaging hidden states of the last layer) is not sufficient for most tasks.However, the best performing modern LLMs are usually massive in terms of the parameter counts (e.g., 175B parameters for GPT3 [Brown et al., 2020] and 340B for PaLM2 [Anil et al., 2023] ), and are therefore difficult to train with limited resources. This motivates a practical question, that to the best of our knowledge has not been addressed systematically, and thus we address it in this paper: what is the best embedding model one can train from a backbone decoder-only LLM with a fixed training compute budget?To answer this, we performed an extensive empirical study. We started by identifying design choices one can make when fine-tuning language models into embedding models, including: model size, data volume, parameter-efficient fine-tuning technique, and the hyperparameters of the chosen technique.Then, we performed a grid search over the pre-defined design choices, and found the best performing configuration under each computational budget. Using these findings, we established scaling laws for contrastive fine-tuning, which enabled us to build an algorithm that produces a general recipe for efficient fine-tuning of a decoder-only LLM that obtains a high-quality embedding model.We comprehensively experimented with contrastively fine-tuning language models into text embedding models. We analysed how the choice of model sizes, data quantities, and fine-tuning methods affect the performance in the resource-constrained training regime. We compiled the findings into an algorithm that, given a fixed computational budget, predicts the optimal network architecture, data quantity, and parameter-efficient fine-tuning hyperparameters. We open-source the code to train and evaluate our models at: https://github.com/SeqDM/Efficient-Embeddings. 
 
 Appendix: In Figure 8 (for full fine-tuning), Figure 9 (for block freezing), Figure 10 (for LoRA), and Figure 11 (for bias tuning), we present the IsoFLOP profiles where downstream task performance is shown.The downstream performance is measured on a subset of MTEB tasks described in Appendix B.Using the location of optimal loss given the computational budget for freezing and bias tuning methods -as illustrated in Figures 2b and 4a -we project optimal model sizes for each computational budget in Figure 13 . Similar figures for full fine-tuning and LoRA are presented in the main text in Figure 6a and Figure 6b , respectively.Using the location of optimal downstream task performance given the computational budget for all the four fine-tuning methods -as illustrated in Figures 8, 9 , 10, and 11 -we project optimal model sizes for each computational budget in Figure 15 .In Figure 14 we present how our formula fitted to models from the Pythia suite describes the loss behaviour of the Gemma 2 model.For each category present in the MTEB benchmark [Muennighoff et al., 2023b] , we take the data from the models evaluated in the original paper and select the task that has the highest correlation with the category average. This results in 8 tasks from the MTEB benchmark used for the downstream task evaluation:1 Figure 12 : The optimal downstream task performance achieved using all four different fine-tuning methods at given budgets. This is a performance analogue of Figure 1 (which shows final training loss instead). For each of the task above, we specify its category in brackets. Since Tatoeba is not featured in the MTEB leaderboard,3 we skip it when calculating our approximation of the MTEB performance of the embedding models.In principle, one could evaluate all the checkpoints on all the MTEB tasks. However, we decided to evaluate on a representative subset in order to speed up evaluation (evaluating some MTEB task takes more than 24 hours, and we have close to 1000 checkpoints, so the overall cost is significant).In our work, we use loss as the main metric used to formulate the conclusions in form of the computeoptimal recipe and the scaling laws. This is in line with other works investigating scaling laws in various contexts, like [Hoffmann et al., 2022 , Muennighoff et al., 2023a , Zhang et al., 2024] . However, we additionally evaluated the trained models on a subset of MTEB benchmark. We calculated the Spearman's rank correlation between the loss and the MTEB performance and it is equal to -0.892, which is significant. Additionally, Figure 16 visually compares the loss and MTEB performance.In our work, we mainly focus on finding the compute-optimal recipe. The training datapoints we share can however be utilised to obtain conclusions about other setups. In particular, we can consider the data-constrained setup. Here, we compare models trained with the same amount of training data instead of the same amount of computation. In Figure 17 we present the plot the final contrastive loss vs. the amount of tokens seen by the network on a log-log scale. The conclusion that can be drawn is that in a data-constrained setup, one should use the largest model available and fine-tune it using full fine-tuning or LoRA with a rank on the bigger side.Below, we list the hyperparameters that we used for training. For all the experiments with block freezing and full fine-tuning, we base our peak learning rate on the peak learning rate from Pythia [Biderman et al., 2023] . We calculate our learning rate by dividing the Pythia learning rate by ten. We use the cosine learning rate schedule with warmup, warmup period being fixed to 10% of the training steps. Learning rate starts at zero, goes up to the peak learning rate, then follows the cosine schedule back to zero.We found the temperature to affect the training performance rather significantly, while the weight decay was of a very slight importance. We run a grid search for partial tuning, varying temperature and weight decay and arrived at a choice of τ = 1 40 and weight decay 0.1. We compared the runs by calculating the results on a subset of MTEB benchmark. Grid results for temperature are detailed in Table 1 , with best scores for each of the temperature value listed. We found that using the averaging of embeddings as the pooling method results in a better performance over selecting the last embedding. We compare the results of the best run for mean and last pooling on full MTEB without MSMarco subset. The scores are presented in Table 2 . In order to be able to compare the loss from LoRA with partial block freezing, we leave most of the hyperparameters unchanged. We change the learning rate, we find the optimal learning rate by running a grid search over hyperparameters. The result shows that for 3 different rank choices, the same learning rate works best. The exact values are presented in Table 3 .Similarly, as with LoRA, for bias tuning to be comparable with partial block freezing, we leave most of the hyperparameters the same. We vary the learning rate, we find the optimal learning rate by running a grid search over hyperparameters. The exact values can be seen in Table 4 . We aim to express the formula describing the behaviour of the loss for our models as a function of the number of parameters N and training tokens D. Following Hoffmann et al. [2022] we start with:L(N, D) = C + A N α + B D β, where A, B, C, α, β ∈ R are parameters to be fitted based on the data.Our setting differs from that of Hoffmann et al. [2022] as we train using the contrastive objective instead of the next-token prediction task, and moreover we apply various compute-efficient methods making some fraction of the parameters of the model not trainable. Despite that, we can still observe certain linear trends that the loss follows. For all the methods, when the FLOP budget is not overly restricted, if we fix the amount of both all the parameters as well as the trainable parameters and vary the amount of FLOP, the loss behaves approximately linearly. We observe that for full fine-tuning, the points are roughly collinear, as in Figure 18 . On the other hand, for LoRA and partial block freezing, we discover that while the lines for one model are parallel, they are translated, depending on the amount of trainable parameters, which can be observed in Figures 21 and 22 .Following the Frantar et al. [2023] 's approach, we replace the term B D β by (as(1-S) bs +csD β, where S is an additional parameter indicating the fraction of the model's parameters that are trainable, and a s , b s are real-valued constants. Similarly, if we keep the forward token amount fixed and vary the amount of model parameters, the linear trend can be observed. Again, the lines are parallel and differ by an intercept, that seems to be linearly dependent on the logarithm of forward tokens, shown in Figure 20 . Therefore, we replace the term A N β bya d •log(D)+b d N β, where a d , b d are real-valued constants. The final formula describing the loss in our setting has the form:L(S, N, D) = C + a d • log(D) + b d N α + a s • (1 -S) bs + c s D β .We split our dataset into train and test set, with test set being the points corresponding to Pythia 2.8B which is the biggest model that we consider and train set the rest. Similarly to Hoffmann et al. [2022] , we use L-BGFS optimization algorithm and Huber loss. We find that δ = 0.001 prevents over-fitting and decreasing it further does not bring more benefits. We then compare the base formula being fitted formula from Chinchilla to our modified formula and find that our works better, as demonstrated in Figure 19 . Both formulas are fitted after a grid search on the initial values of their coefficients. It can Figures 19a, 19c, 19e, and 19g are the results of fitting our formula for different fine-tuning methods, while Figures 19b, 19d, 19f, and 19h are the result of fitting the standard formula from Hoffmann et al. [2022] . It can be observed, that in contrast to the standard formula, our results in plots that are roughly linear, without additional trends visible.be observed that we are able to accurately predict the loss for the bigger model for all the methods. Therefore, we hypothetize that our formula can be used for prediction the performance of models of an even larger scale.Constrained by the computational budget, we performed the biggest line of experiments using batch size 1024 and context length 75. However, an increased context length as well as batch size might be desirable in many cases. Here, we demonstrate that the scaling laws established by us extend to a setting with batch size 2048 and context length 512. For those experiments, we trained five pre-trained decoder-only models from the Pythia suite [Biderman et al., 2023] , with sizes 14M, 31M, 70M, 160M, and 410M. We consider five computational budgets: 1.5e15, 6e15, 2.4e16, and 9.6e16 FLOP. We fit the formula following the method from Appendix F, with the change of using the number of training steps as the measure of data seen by the model instead of forward tokens. We then use it to predict the loss for the changed hyperparameters values. The results are visible in Figure 23 . We conclude that our findings are relevant for setups with a larger batch size and context length.For all the trainings, we used a cluster with A100 GPUs with 40GB VRAM or with 80GB VRAM. We used 4 CPUs and 128GB of RAM per GPU. We estimate that the results contained in this article were obtained by expanding somewhere in between 30k and 40k GPU hours.We utilize the BAAI dataset available at https://data.baai.ac.cn/details/BAAI-MTP.It has a custom licence that allows for conducting academic research.Question: Does the paper provide open access to the data and code, with sufficient instructions to faithfully reproduce the main experimental results, as described in supplemental material? Answer: [Yes] Justification: We will open-source the code used for training. We share the code as a supplementary material to the submission. We share the link for downloading the dataset in the zip file with the code. We moreover share the training results used for creating the plots here.Guidelines:• The answer NA means that paper does not include experiments requiring code. Justification: As this work aims at improving the efficiency for people to obtain embedding models, we only see positive social impacts. This was discussed in Section 6. Guidelines:• The answer NA means that there is no societal impact of the work performed.• If the authors answer NA or No, they should explain why their work has no societal impact or why the paper does not address societal impact. • Examples of negative societal impacts include potential malicious or unintended uses (e.g., disinformation, generating fake profiles, surveillance), fairness considerations (e.g., deployment of technologies that could make decisions that unfairly impact specific groups), privacy considerations, and security considerations. • The conference expects that many papers will be foundational research and not tied to particular applications, let alone deployments. However, if there is a direct path to any negative applications, the authors should point it out. For example, it is legitimate to point out that an improvement in the quality of generative models could be used to generate deepfakes for disinformation. On the other hand, it is not needed to point out that a generic algorithm for optimizing neural networks could enable people to train models that generate Deepfakes faster. • The authors should consider possible harms that could arise when the technology is being used as intended and functioning correctly, harms that could arise when the technology is being used as intended but gives incorrect results, and harms following from (intentional or unintentional) misuse of the technology. • If there are negative societal impacts, the authors could also discuss possible mitigation strategies (e.g., gated release of models, providing defenses in addition to attacks, mechanisms for monitoring misuse, mechanisms to monitor how a system learns from feedback over time, improving the efficiency and accessibility of ML).We adopt the PyTorch notation here, where the cross entropy loss takes two arguments: the logits of the probability distribution, and the indices of the true categories.The data collected in our experiments and their interactive visualisations are available in this Colab notebook: https://colab.research.google.com/drive/1EC2QdVrOIXhamLJI51CUywWJ33sApXX8https://huggingface.co/spaces/mteb/leaderboard 


Decision: This work investigates how to contrastively train text embedding models in a compute-optimal manner using a suite of pre-trained decoder-only language models. The motivation is solid, and the quality of the work is high. However, one limitation is the relatively small model sizes used in the study, with a maximum of 3B parameters. It would be more compelling to explore the scaling laws for larger models, especially considering that the leading embedding models today are typically around 7B parameters e.g., NV-Embed, bge-en-icl, SFR-Embedding.
https://huggingface.co/spaces/mteb/leaderboard

Reviews: review: paper_summary: paper_summary: This paper focuses on the efficient contrastive training of text embedding models using pre-trained decoder-only language models. The main contribution is an algorithm that determines the best configuration of model sizes, data amounts, and fine-tuning methods for different computational budgets. Through extensive experimentation, the authors developed a guideline that helps practitioners choose the most suitable design options for their text embedding models. The study finds that full fine-tuning is best for lower computational budgets, while low-rank adaptation fine-tuning is optimal for higher budgets.
strength_weakness: strength_weakness: The paper does not introduce a new methodology. The techniques employed, such as scaling laws, extracting representations from transformers, and contrastive fine-tuning, are all well-established in the literature. 

There are several existing studies that the paper fails to acknowledge, which could provide a richer context and enhance the literature review. Notable omissions include works like “LLM-Oriented Retrieval Tuner” and “Scaling Laws for Dense Retrieval.” Acknowledging and discussing these related studies could strengthen the paper by positioning it within the existing research landscape more accurately.
questions: questions: Please refer to the previous sections.
limitations: limitations: This paper discusses the limitation in Section 5.
paper_summary: paper_summary: This paper investigates how to effectively train text embedding models from pre-trained decoder-only language models while considering computational budget constraints. The authors explore the influence of model sizes, fine-tuning methods, and computational budgets on the performance of the embedding models. The results demonstrate that full fine-tuning is optimal for lower computational budgets, whereas low-rank adaptation fine-tuning is more effective for higher computational budgets.
strength_weakness: strength_weakness: (1) In L51-52, it is stated that "given a fixed computational budget, predicts the optimal network architecture, data quantity, and parameter-efficient fine-tuning hyperparameters". However, data quantity, a very crucial factor, is not investigated in the paper.

(2) The conclusion that full fine-tuning and low-rank adaptation fine-tuning produce optimal models at lower and higher computational budgets respectively seems somewhat superficial.

(3) I have concerns about the selection of the MTEB subset. Retrieval is a crucial task for which embedding models can be used. However, only SciFact is evaluated. Scifact is not a representative retrieval dataset as its corpus is relatively small (only with 5183 documents).

(4) Figure 1 is somewhat hard to read since it is difficult to distinguish the lines representing full fine-tuning, LoRA, and block freezing.

(5) The average pooling method to extract representation is not entirely reasonable, as the autoregressive characteristic would cause the outputs of the first tokens to lack information about the latter tokens.

(6) L141-146 is not entirely accurate. Hard negative mining methods like [1] and [2] do not require this two-stage training procedure. This two-stage training procedure is more of a recent trend in training powerful general-purpose embedding models.

[1] Lee Xiong, Chenyan Xiong, Ye Li, Kwok-Fung Tang, Jialin Liu, Paul Bennett, Junaid Ahmed, Arnold Overwijk. Approximate Nearest Neighbor Negative Contrastive Learning for Dense Text Retrieval. ICLR 2021.

[2] Jingtao Zhan, Jiaxin Mao, Yiqun Liu, Jiafeng Guo, Min Zhang, Shaoping Ma. Optimizing Dense Retrieval Model Training with Hard Negatives. SIGIR 2021.
questions: questions: Please see my comments in Weakness.
limitations: limitations: The paper has a proper Limitations and future work section.
paper_summary: paper_summary: This paper proposes a new algorithm to automatically find optimal configurations of model sizes, data quantities, and fine-tuning methods for text embedding models at different computational budget levels by contrastive pretraining. Specifically, the paper analyzes the choices of different configurations and then designs an algorithm to predict optimal architecture based on budget. The paper also designs a new task to find optimal model configuration given limited budgets. The paper first introduces basics, including the scaling laws, the constrained optimization problem, the contrastive learning,  fine-tuning methods, and then computational cost formulas. The paper then experiments with different finetuning methods to find the optimal loss regarding parameters. Furthermore, the paper aims to find the relationship between loss functions regarding the number of parameters (trainable/total) and the number of training tokens. The paper then fit the plots to find the best equations.
strength_weakness: strength_weakness: 1.  The paper's generalization ability is limited. As mentioned in the limitation, the proposed computation law is only on the Pythia; additional language models might better reflect the generalization ability. The paper also only focuses on contrastive finetuning.
2. The whole paper mainly focuses on the performance analysis. It would be better to include additional theoretical support for the phenomenon that appears in the paper. The paper can also be strengthened by testing the proposed performance law on some unobserved configurations. 
3. The paper claims to also analyze the relationships between the data quantities and the performance. However, I cannot find it in Section 4.2. The paper fails to follow the NeurIPS citation format, which uses numbers for references/citations.
questions: questions: See weakness
limitations: limitations: The paper includes a limitation section in Section 5.
paper_summary: paper_summary: The paper fine-tunes Pythia LLMs with different sizes for information retrieval (IR) applications. The paper investigates the effect of different model sizes, FLOPs, fine-tuning methods such as LoRA or bias tuning, and some important hyperparameters (e.g., dimension in LoRA) on loss and downstream applications (measured by MTEB). Some takeaways are interesting and counterintuitive (e.g., the larger model does not necessarily achieve better loss).
strength_weakness: strength_weakness: Although I think the experiments in this paper are valuable, I think main goal of the analyses is not very practical. Personally, I think the term Compute-Optimal from Chinchilla (https://arxiv.org/pdf/2203.15556) and this paper is very misleading because it only considers the training cost and ignores the inference cost. In practice, the LLMs are often trained much longer than this "optimal" value. For example, Chinchilla-optimal for 8B LLM is just 200B tokens, but LLaMA 3 is trained using over 15T tokens (https://ai.meta.com/blog/meta-llama-3/). For the information retrieval (IR) models, the inference cost might be even more important compared to LLMs.

In addition to main complaint above, I think that some details could be explained more clearly (see the questions below). Finally, I think that the figures with FLOPs on the x-axis and different curves are for different model size are much easier to read than what the paper has now (the model size on the x-axis and different curves are for different FLOPs), but it might be my personally preference.
questions: questions: 1. Although you show that the correlation between MTEB and loss is very high (−0.892) overall, some important trends seem to be different, which might affect your takeaway message. For example, the best score of MTEB always comes from the largest model in Figure 7-10, but the lowest loss often comes from smaller model size in Figure 2 and 4. The bias tuning methods are significantly worse in terms of loss, but it seems to achieve the best MTEB when FLOP is 5e+18 in Figure 11. When you write your takeaways, why not also include the results of MTEB?

2. I don't understand l_r and l_c in line 134 and 135. Why don't we need to use labels.T for l_c?  If this is a standard loss, please cite. Otherwise, please provide more explanations/motivations for this loss.

3. Why do you choose to use the English partition of the BAAI BGE dataset, which is designed for Chinese embedding? If it is not a common choice, you should explain more about this.

4. Did you get the performance of full MTEB? Does the full MTEB give you different trends? In the figures, MTEB performances means the performances on the task subset, right? I think you should make it clear in those figures (MTEB performances -> MTEB subset performances).
limitations: limitations: The current limitation section is good and adding some discussion of inference cost could make it better.

Comments: title: New Results
Thank you
Thank you
Thank you for your detailed explaination
comment: Dear Reviewers,

We are happy to announce one more result concerning the very recent Gemma-2-2b model (released two weeks ago). Despite the limited time, we managed to conduct experiments with full fine-tuning and observed that they were consistent with those obtained with Gemma-2 (see the first subplot of Figure 4 in the attached document). This result further supports the robustness and broad applicability of our work. We will present a more exhaustive study on this model in the camera-ready version.

Best regards,
Authors
Dear reviewer, we thank you again for your review. We would like to confirm if our rebuttal answers are satisfactory. Please let us know if you have any new questions.
Again, we thank the reviewer for their constructive feedback. As we have passed the middle of the discussion period, we would like to confirm if our answers are comprehensive and satisfactory. Should any new questions arise, we would be happy to answer them.
We again thank you for your feedback, and we are grateful for your support of our work!
Thank you very much for your detailed explanation! The authors have addressed my concern. I will raise my score to 7.
We thank the reviewer for their prompt response and for increasing the score of our manuscript. 

We are also happy to answer new questions if any arise.

Best regards, Authors
The authors address my concerns well. I have no other major reasons to reject this paper, so I raise my score from 6 to 7.