为什么你的微调任务比理论FLOPs计算的耗时更长?
基于272次生产级训练的数据,预测端到端微调时间。
本文预览我们将于近期在arXiv发布的论文《预测生成式语言模型的端到端微调时间》。
GPU是当前AI领域最昂贵且最稀缺的资源之一。任何运营共享集群的团队都必须每天决策:哪些任务分配到哪些GPU,以何种顺序执行。调度方案的质量直接取决于对每个任务耗时的预估准确性。当任务提前数小时结束时,GPU将空等至下一任务派发;而当任务超时数小时后,后续所有排队任务均会顺延,实验周期与交付日期随之推迟。
更精准的时间预估能将被动猜测转化为主动规划——明确什么任务、何时运行、占用多少GPU算力,从而减少中间的空置等待。然而多数团队仍依赖纸面上的FLOPs粗略估算。这种估算显示9小时可完成任务,实际却耗时到次日午后才结束。
我们试图量化这种理论估算与实际性能的偏差程度,并探索在任务派发前能否给出更准确的预测。为此,我们收集了来自NVIDIA H200 GPU生产池的272个真实监督微调(SFT)任务样本,累计涉及约7,382 GPU-hours的算力消耗,通过对比解析模型估算与机器学习预测器的效果展开分析。
简短版:常规的基于FLOP的估算几乎无法解释我们的观测结果(R² = 0.31,MAE 12.41 h)。一个仅在使用前即可获取的信息作为输入的CatBoost回归器在5折交叉验证中达到了R² = 0.98,平均绝对误差为1.71 h,中位误差为0.51 h。这一差距源于封闭形式估算无法做到的两件事:该回归器能看到更多训练特定的信号,例如评估频率、检查点策略、每张GPU的负载和微调方案,并且它能从历史训练中学习到这些信号之间的非线性交互关系。
人人都在用的估算只看计算量
对于稠密Transformer,训练大约需要6·P·D次浮点运算,其中P是参数量,D是训练token数量。将其除以你的GPU能提供的算力,就能得到训练循环时间:
T_theoretical = (6 · P · D) / (N_GPU · FLOPS_peak · MFU)
这里的N_GPU是GPU数量,FLOPS_peak是单张GPU规格表上标称的峰值算力,MFU(Model FLOPs Utilization)则是训练实际达到的峰值比例。由于显存访问、通信和内核效率等因素,实际作业永远跑不到峰值,因此MFU通常落在30%到60%之间,而某个具体作业的合理取值事先并不知道。
这只是对优化循环的良好描述。但一个作业不止有训练循环。在第一步之前还有环境搭建、模型下载和加载、分词等步骤。训练过程中还有周期性评估和检查点上传。最后还需要将最终模型转存到对象存储。在多租户集群上,上述所有操作都需要与其他作业竞争网络与存储I/O资源。
这些开销取决于配置,并且不会随工作负载或GPU数量整齐缩放。两项名义计算量相同的作业可能相差数小时完成。
为了保持比较公平,我们测试的FLOP基线既计入计划的评估token,也计入训练token,并且在很宽的范围内扫描MFU。
我们构建的内容
我们将端到端时长视为一个监督回归问题。基于从作业配置和模型元数据构建的特征向量,预测作业获得GPU到完成之间的墙钟时间(排队时间除外)。
两项设计选择塑造了这项工作:
- 所有信息在分发前均可知。每个输入均来自已提交的配置:超参数、数据集大小、模型标识符、GPU分配。不使用运行时日志,也不使用部分进度。这正是使预测可用于调度安排的原因。
- 暴露开销的特征。在原始配置之上,我们导出诸如num_eval_data(所有评估轮次中处理的样本数)、num_saves和num_params_saved(检查点I/O)以及每GPU token量等数值。FLOP估算值本身(MFU固定为0.45)作为另一个特征(baseline_time)输入,使模型从纯计算量出发并学习校正量。
我们比较了线性回归、Ridge、XGBoost和CatBoost。特征选择综合了跨18个候选特征集的相关性过滤、互信息和排列重要性,随后以MAE为标准进行网格搜索。最终的CatBoost模型使用24个特征。
数据
- 来自企业生产环境操作日志的 272 次 SFT 训练运行,涵盖多个模型族(最大 150 亿参数),包括 LoRA 和全量微调,以及广泛的数据集规模和超参数。
- 共享基础设施。作业在从 8 到 32 张 H200 组成的池中抽取的 1、2 或 4 张 GPU 上运行,分布在 1 到 4 个节点上,同时运行其他训练和推理工作负载。测量的时间包含实际竞争开销。
- 持续时间从 1.6 小时到 172.4 小时不等,平均值为 23.43 小时,中位数为 15.29 小时。
- 技术栈:Hugging Face Transformers 和 Unsloth。我们将技术栈作为分类特征建模,不对两者之间的固定加速比做任何假设。
272 次运行的端到端耗时分布。均值 23.43 小时,中位数 15.29 小时。
结果
所有数据均来源于分层 5 折交叉验证。前四行为分析性估算,不涉及模型拟合。
以下几个观察值得注意。
没有单一的 MFU 值可以准确确定 FLOP 基准。我们扫描了从 0.25 到 0.65 的 MFU 范围。最佳设置(30%)仍导致对平均耗时 23 小时的作业产生超过 12 小时的平均误差。
更详细的分析模型仍未能缩小差距。作为第二个基线,我们采用了 Calculon(Isaev et al., SC '23)——一种来自先前工作的 LLM 训练分析性能模型。它构建了显式的层图,并考虑了计算、内存流量和设备间通信。我们扩展了公开实现以支持 LoRA、分组查询注意力(grouped-query attention)、融合注意力(fused attention)、bfloat16 和 SwiGLU。其估计仍仅对应于实测墙钟时间的约 11%。这并非否定 Calculon 作为步骤级工具的价值——这正是它的设计目标——而是说明了生产作业中有大量时间发生在优化步骤之外。
线性模型有所帮助,但随后陷入瓶颈。Ridge将MAE降至7.23小时。纯线性模型无法很好地捕捉配置与耗时之间的关系。
梯度提升承担了主要的工作量。CatBoost和XGBoost在所有指标上的差异都在一个标准差以内。我们最终选用CatBoost,因为它的各项平均误差均为最低。
预测器所依赖的因素
CatBoost的特征重要性集中在少数几个特征上。如预期那样,模型和工作负载变量位列其中,评估和检查点变量也位列其中。num_eval_data(任务运行期间评估处理的样本总数)排名第一,其次是num_trainable_params、batch_eval_size_percent、num_all_params和num_gpus*batch_train_percent,num_params_saved紧随其后。SHAP值讲述着同样的故事:高评估量持续推高预测时间,而可训练参数数量的影响是非线性的,仅对最大规模的模型才会变得显著。
CatBoost模型跨折的平均特征重要性(PredictionValuesChange)。
特征重要性并不构成因果主张。尽管如此,这一模式与实际任务的耗时方式相符。评估频率、评估集大小以及持久化检查点的数量都与模型和数据集规模共同决定了实际墙钟时间。这些都是在编写训练配置时人们往往凭习惯做出的选择。
阅读图表时需注意一点:较大的GPU分配显示对预测时间为正向贡献。在我们的数据中,更大的分配伴随着更大规模的任务,因此num_gpus在某种程度上充当了任务规模的代理变量。这并不意味着增加GPU会使任务变慢。
它在何处出错,误差多大
查看所有272个跨折(out-of-fold)预测结果,中位数绝对误差为0.51小时。80%的预测误差在2.20小时以内,90%的预测误差在4.31小时以内。按任务持续时间细分:
不超过60小时的范围内,中位数误差维持在约一小时或更低。长尾部分是模型的薄弱环节,但由于超过60小时的运行仅有13次,我们将其视为数据限制。
跨折绝对误差与真实持续时间的关系图,按持续时间区间着色。误差在60小时以下保持较低,在稀疏的尾部逐渐扩大。
更多数据仍会有所帮助。在固定的20%预留集上,将训练分区从85%扩大到100%时,MAE从1.63小时降至1.50小时,未出现明显平台期。
适用场景
在实际应用中,该预测器可在任务启动前提前给出一个调度员可以据此规划的时间段:哪些任务应并行运行、GPU何时会释放、以及一次运行是否能在截止时间内完成。
局限性
- 仅使用了SFT。未包含其他训练和对齐策略,如RLHF、DPO或RLVR。
- 单一GPU型号。每次运行均使用H200。拟合好的模型针对该基础设施进行了校准,不应期望在不重新训练的情况下数值上迁移到其它GPU代际。面向混合资源池的预测器还需要硬件描述符,如计算吞吐率、内存容量和带宽,以及互联拓扑结构。
- 超长运行样本稀少。60小时以上的误差会扩大。
真正可迁移的是方法本身:考虑开销的特征、感知多重共线性的特征选择和比较协议。完整论文将详细报告特征公式、选择流程、搜索空间和最终超参数,以便在任何具有相似结构的执行日志数据集上重建整个流程。
接下来的清单包括:硬件特定的描述符和其他GPU类型的验证,少观测配置下的迁移学习,其他训练目标以及更多长时运行数据。
最新动态
完整论文即将上传至arXiv。请关注Hugging Face上的Dharma-AI组织,以便及时获取更新通知,并在下方评论区留下您的问题。我们希望了解您是如何在自己集群上估算作业持续时间的。
延伸阅读
Dharma-AI研发部 · 让AI成为您的专属模型
本文由 AI图鉴自动抓取并翻译,版权归原作者所有;如需查看原文请点下方链接。
Why your fine-tuning job takes longer than the FLOPs say
Predicting end-to-end fine-tuning time on shared GPU clusters, from 272 production runs.
A preview of our upcoming paper, Predicting End-to-End Fine-Tuning Time for Generative Language Models. The full version will be on arXiv soon.
GPUs are among the most expensive and scarcest resources in AI today. Anyone running a shared cluster has to decide, every day, which jobs go on which GPUs and in what order. That plan is only as good as the estimate of how long each job will take. When a job finishes hours early, GPUs sit idle until the next one is dispatched. When it runs hours late, everything queued behind it slips, experiments wait and delivery dates move.
Better duration estimates turn this into planning instead of guesswork: what runs, when, and on how many GPUs, with less idle capacity in between. Yet the estimate most teams use is a back-of-the-envelope FLOP calculation. It says nine hours, and the job finishes the next afternoon.
We wanted to know how far off that math really is, and whether we could do better before a job is even dispatched. So we took 272 real supervised fine-tuning (SFT) jobs from our production pool of NVIDIA H200 GPUs, about 7,382 GPU-hours in total, and compared analytical estimates against learned predictors.
The short version: the usual FLOP-based estimate explains little of what we observed (R² = 0.31, MAE 12.41 h). A CatBoost regressor that only sees information available before dispatch reaches R² = 0.98, with a mean absolute error of 1.71 h and a median error of 0.51 h in 5-fold cross-validation. The gap comes from two things a closed-form estimate cannot do. The regressor sees more training-specific signals, such as evaluation cadence, checkpoint policy, per-GPU load and fine-tuning regime, and it learns the nonlinear interactions between them from past runs.
The estimate everyone uses is compute-only
For a dense Transformer, training costs roughly 6·P·D floating-point operations, where P is the parameter count and D the number of training tokens. Divide that by what your GPUs can deliver and you get a training-loop time:
T_theoretical = (6 · P · D) / (N_GPU · FLOPS_peak · MFU)
Here N_GPU is the number of GPUs, FLOPS_peak is the peak throughput of one GPU from its spec sheet, and MFU (Model FLOPs Utilization) is the fraction of that peak the training actually achieves. Real jobs never run at peak because of memory traffic, communication and kernel inefficiencies, so MFU typically sits somewhere between 30% and 60%, and the right value for a given job is not known in advance.
This is a good description of the optimization loop. A job is more than its loop, though. Before the first step there is environment setup, model download and loading, and tokenization. During training there are periodic evaluations and checkpoint uploads. At the end, the final model goes to object storage. On a multi-tenant cluster, all of it competes with other jobs for network and storage I/O.
These overheads depend on configuration, and they do not scale neatly with workload or GPU count. Two jobs with the same nominal compute can finish hours apart.
To keep the comparison fair, the FLOP baseline we test counts the scheduled evaluation tokens as well as the training tokens, and we sweep MFU over a wide range.
What we built
We treat end-to-end duration as a supervised regression problem. Given a feature vector built from the job configuration and model metadata, predict the wall-clock time between the moment the job gets its GPUs and the moment it is done. Queue time is excluded.
Two design choices shaped the work:
- Everything is known before dispatch. Every input comes from the submitted configuration: hyperparameters, dataset sizes, model identifiers, GPU allocation. No runtime logs, no partial progress. That is what makes the prediction usable for scheduling.
- Features that expose the overheads. On top of the raw configuration we derive quantities such as num_eval_data (samples processed across all evaluation cycles), num_saves and num_params_saved (checkpoint I/O), and per-GPU token volumes. The FLOP estimate itself, with MFU fixed at 0.45, goes in as one more feature (baseline_time), so the model starts from the compute-only number and learns the corrections.
We compared Linear Regression, Ridge, XGBoost and CatBoost. Feature selection combined correlation filtering, mutual information and permutation importance across 18 candidate feature sets, followed by a grid search with MAE as the criterion. The final CatBoost model uses 24 features.
The data
- 272 SFT runs from the operational logs of a corporate production environment, covering several model families up to 15 billion parameters, both LoRA and full fine-tuning, and a wide range of dataset sizes and hyperparameters.
- Shared infrastructure. Jobs ran on 1, 2 or 4 GPUs drawn from a pool of 8 to 32 H200s across 1 to 4 nodes, alongside other training and inference workloads. The measured times include real contention.
- Durations from 1.6 to 172.4 hours, with a mean of 23.43 h and a median of 15.29 h.
- Stack: Hugging Face Transformers and Unsloth. We model the stack as a categorical feature and make no assumption about a fixed speedup between the two.
Distribution of end-to-end duration across the 272 runs. Mean 23.43 h, median 15.29 h.
Results
All numbers come from stratified 5-fold cross-validation. The first four rows are analytical and involve no fitting.
A few things stand out.
No single MFU value fixes the FLOP baseline. We swept MFU from 0.25 to 0.65. The best setting, 30%, still leaves a mean error above 12 hours on jobs that last 23 hours on average.
A more detailed analytical model does not close the gap. As a second baseline we took Calculon (Isaev et al., SC '23), an analytical performance model for LLM training from prior work. It builds an explicit layer graph and accounts for compute, memory traffic and inter-device communication. We extended the public implementation to cover LoRA, grouped-query attention, fused attention, bfloat16 and SwiGLU. Its estimates still correspond to a median of only 11% of the observed wall-clock time. That says nothing against Calculon as a step-level tool, which is what it was designed for. It shows how much of a production job happens outside the optimization step.
Linear models help, and then stall. Ridge brings MAE down to 7.23 h. The relationship between configuration and duration is not well captured by a purely linear model.
Gradient boosting does the heavy lifting. CatBoost and XGBoost land within one standard deviation of each other on every metric. We carry CatBoost forward because it has the lowest mean error across the board.
What the predictor relies on
CatBoost's feature importance concentrates in a handful of features. Model and workload variables are there, as expected, but so are evaluation and checkpoint variables. num_eval_data, the total number of samples processed in evaluation over the life of the job, ranks first, followed by num_trainable_params, batch_eval_size_percent, num_all_params and num_gpus*batch_train_percent, with num_params_saved close behind. SHAP values tell the same story: high evaluation volume consistently pushes the predicted time up, while trainable parameter count has a nonlinear effect that only becomes large for the biggest models.
Mean feature importance of the CatBoost model across folds (PredictionValuesChange).
Feature importance is not a causal claim. Still, the pattern lines up with how a job is actually spent. How often you evaluate, how large the evaluation set is and how many checkpoints you persist all shape the wall-clock time, alongside model and dataset scale. These are choices people often make by habit when writing a training config.
One caveat on reading the plots: larger GPU allocations show positive contributions to predicted time. In our data, bigger allocations go with bigger jobs, so num_gpus acts partly as a proxy for job scale. It does not mean adding GPUs makes a job slower.
How wrong is it, and where
Looking at all 272 out-of-fold predictions, the median absolute error is 0.51 h. 80% of predictions are within 2.20 h and 90% are within 4.31 h. Broken down by job duration:
Up to 60 hours, the median error stays at about one hour or less. The long tail is where the model struggles, and with only 13 runs above 60 hours we read that as a data limitation.
Out-of-fold absolute error against real duration, colored by duration range. Errors stay low up to 60 h and widen in the sparse tail.
More data should still help. On a fixed 20% holdout, MAE drops from 1.63 h to 1.50 h when going from 85% to 100% of the training partition, with no clear plateau.
What it is good for
In practice, the predictor gives a scheduler a duration it can plan around before a job starts: which jobs to run together, when GPUs will free up, and whether a run will finish in time for its deadline.
Limitations
- SFT only. We did not include other training and alignment strategies such as RLHF, DPO or RLVR.
- One GPU type. Every run used H200s. The fitted model is calibrated to that infrastructure and should not be expected to transfer numerically to other GPU generations without retraining. A predictor for mixed pools would also need hardware descriptors such as compute throughput, memory capacity and bandwidth, and interconnect topology.
- Few very long runs. Errors widen above 60 hours.
What does transfer is the method: overhead-aware features, multicollinearity-aware selection and the comparison protocol. The full paper will report the feature formulas, the selection procedure, the search spaces and the final hyperparameters in full, so the pipeline can be rebuilt on any execution-log dataset with a similar structure.
Next on our list: hardware-specific descriptors and validation on other GPU types, transfer learning for configurations with few observations, other training objectives, and more data on long runs.
What's next
The full paper is coming to arXiv soon. Follow the Dharma-AI organization on Hugging Face to be notified when it is out, and leave your questions in the comments below. We would like to hear how you estimate job duration on your own clusters.
Further reading
Dharma-AI R&D · We Make AI Your Model
Auto-fetched and translated by AI Atlas. All rights belong to the original author.