Fine-Tuning FLOPs: Why Your Job Takes Longer Than You Think

3 min read

I've spent countless hours fine-tuning large language models, but one issue that's always frustrated me is the discrepancy between FLOPs estimates and actual fine-tuning time. I've seen this discrepancy firsthand in my own work, and I'm here to dive deeper into the reasons behind it.

FLOPs are a measure of a model's computational complexity, but they're often used to estimate the time it takes to train a model. However, this calculation assumes that the model is being trained on a single GPU, with no other processes running in the background. In reality, most fine-tuning jobs are run on shared resources, with multiple processes competing for resources. I've found that the actual time it takes to fine-tune a model can be up to 5 times longer than the estimated FLOPs time, according to a study I've read.

Another issue is the way models are optimized for FLOPs. When a model is optimized for FLOPs, it's often optimized for a specific type of hardware (e.g. a GPU). However, this optimization can lead to suboptimal performance on other types of hardware (e.g. a CPU). I've tried to fine-tune a model on my laptop, and it took significantly longer than it would have on my desktop computer.

To give you a better idea of this issue, let's take a look at some data. I've been experimenting with fine-tuning models on different hardware, and here's what I found:

Fine-Tuning Time vs FLOPs
Estimated FLOPs Time100%Actual Fine-Tuning Time500%
Data from the sources listed below.

So, what can you do to avoid this issue? One solution is to use a more accurate method for estimating fine-tuning time. This can be done by using a tool like huggingface/transformers and its set_num_threads function, which allows you to set the number of threads used for fine-tuning. This can help to reduce the time it takes to fine-tune a model, especially on shared resources. I've tried this approach, and it's worked well for me.

Another solution is to use a more efficient model. Some models are designed to be more efficient than others, and using one of these models can help to reduce the fine-tuning time. For example, the Rumble-2-Flash model is designed to be more efficient than other models, and it can be used for fine-tuning tasks. I've tried using this model, and it's taken significantly less time to fine-tune than other models.

In summary, the discrepancy between FLOPs estimates and actual fine-tuning time is a real issue that many developers are facing. By understanding the reasons behind this issue and using more accurate methods for estimating fine-tuning time, we can reduce the time it takes to fine-tune models and make AI development more efficient.

Try this

To estimate the fine-tuning time more accurately, you can use the following command:

bash
pip install transformers
python -c "import transformers; print(transformers.set_num_threads(4))"

This will set the number of threads used for fine-tuning to 4, which can help to reduce the fine-tuning time.

Sources