读见

为什么你的微调任务耗时比 FLOP 估算更长

原题Why your fine-tuning job takes longer than the FLOPs say

约 8 分钟约 1,867 字原文英文已翻译

推荐理由数百次真实微调运行揭示验证集、环境启动与检查点写入会拉长任务,帮助读者在排 GPU 工期时拆出 FLOP 估算漏掉的成本。

读前速览

4 个要点

本文解释了微调任务为何比基于 FLOP 的估算耗时更长,并介绍了一种 CatBoost 模型:通过纳入评估和检查点开销特征,该模型的 R-squared 达到 98%。

  1. 基于 FLOP 的估算难以准确预测微调任务时长

    使用 MFU 值(30%-60%)进行传统的纯计算量估算,R-squared 仅为 0.31,MAE 为 12.41 hours,无法捕捉环境设置、评估和检查点 I/O 等会显著影响实际耗时的开销。

  2. 基于任务派发前特征的 CatBoost 模型实现了近乎完美的预测准确度

    CatBoost 回归模型纳入了 24 个特征,包括评估频率、检查点策略和每 GPU 负载指标;这些特征在任务派发前即可获取。模型的 R-squared 达到 0.98,MAE 为 1.71 hours,中位误差为 0.51 hours。

  3. 评估和检查点开销特征是预测任务时长的最强指标

    特征重要性分析显示,num_eval_data 排名第一,其次是可训练参数和检查点 I/O 指标。这表明,除了纯计算需求,评估数据量和持久化策略也会显著影响实际耗时。

  4. 由于数据有限,模型对耗时极长任务的预测准确度会下降

    任务时长超过 60 hours 后,预测误差增大,而该区间仅有 13 次运行,说明问题在于数据有限,而非模型失效;使用 100% 的训练数据时,MAE 从使用 85% 训练数据时的 1.63 降至 1.50 hours。

完整摘要

本文探究了基于 FLOP 计算的微调任务时长估算为何不准确,其 R-squared 仅为 0.31。作者分析了在 NVIDIA H200 GPU 上运行的 272 个真实监督微调任务,总计 7,382 GPU-hours,并使用任务派发前即可获取的配置特征训练 CatBoost 回归模型。该模型的 R-squared 达到 0.98,平均绝对误差为 1.71 hours,中位误差为 0.51 hours。主要预测因素包括评估数据量、可训练参数数量和检查点 I/O。研究表明,传统的纯计算量估算之所以失效,是因为它忽略了环境设置、评估周期和检查点上传等开销,而这些开销不会随工作负载线性增长。

目录 · 10 节

查看原文
Team Article
Published November 18, 2026

基于 272 次生产运行,预测共享 GPU 集群上的端到端微调时间。Predicting end-to-end fine-tuning time on shared GPU clusters, from 272 production runs.

我们即将发表的论文《预测生成式语言模型端到端微调所需时间》的预览版。完整版很快将在 arXiv 上发布。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.

GPU 是当今 AI 领域中最昂贵、最稀缺的资源之一。任何运行共享集群的人都必须每天决定哪些任务使用哪些 GPU,以及按什么顺序运行。调度计划的效果取决于对每项任务所需时间的估算是否准确。任务提前数小时完成时,GPU 就会闲置,直到调度下一个任务;任务晚数小时完成时,所有排在它后面的任务都会延误,实验只能等待,交付日期也会推迟。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.

更准确的耗时估算能让这从猜测变成规划:安排哪些任务运行、何时运行、使用多少块 GPU,同时减少其间闲置的算力。然而,大多数团队采用的估算仍只是粗略的 FLOP 计算。它算出需要九小时,结果任务却到第二天下午才完成。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.

我们想了解这些计算结果究竟偏差有多大,以及能否在作业调度之前做得更好。因此,我们从生产环境的 NVIDIA H200 GPU 集群中抽取了 272 个真实的监督微调(SFT)作业,总计约 7,382 个 GPU 小时,并将解析估算与学习型预测器进行了比较。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.

简而言之:通常基于 FLOP 的估算无法解释我们观察到的大部分现象(R² = 0.31,MAE 为 12.41 小时)。一个仅使用派发前可获取信息的 CatBoost 回归器,在 5 折交叉验证中达到 R² = 0.98,平均绝对误差为 1.71 小时,中位误差为 0.51 小时。差距源于闭式估算无法做到的两件事。回归器能利用更多特定于训练过程的信号,例如评估频率、检查点策略、每 GPU 负载和微调方案,并从过往运行记录中学习这些因素之间的非线性交互。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

对于一个稠密 Transformer,训练成本约为 6·P·D 次浮点运算,其中 P 是参数量,D 是训练 token 数量。用这个数除以 GPU 的算力,就能得到训练循环所需的时间: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)

这里,N_GPU 是 GPU 的数量,FLOPS_peak 是单个 GPU 在规格表中标注的峰值吞吐量,而 MFU(模型浮点运算利用率,Model FLOPs Utilization)表示训练实际达到的峰值比例。由于内存流量、通信和内核效率低下等因素,实际任务永远无法达到峰值,因此 MFU 通常在 30% 到 60% 之间,而特定任务的实际值事先无法确定。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.

这是对优化循环的一个很好的描述。不过,作业不只有优化循环。在第一步开始之前,还需要设置环境、下载并加载模型,以及进行分词。训练过程中会定期进行评估并上传检查点。训练结束后,最终模型会存入对象存储。在多租户集群上,所有这些操作都要与其他作业争用网络和存储 I/O。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.

这些开销取决于配置,而且不会随着工作负载或 GPU 数量的变化而整齐地缩放。名义计算量相同的两个任务,完成时间可能相差数小时。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.

为确保比较公平,我们测试的 FLOP 基线将计划用于评估的 token 和训练 token 都计入,并在较大范围内扫描 MFU。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

我们将端到端时长视为一个有监督回归问题。给定由作业配置和模型元数据构建的特征向量,预测作业获得 GPU 到完成之间的实际耗时。不包括排队时间。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:

  • 在任务派发之前,一切信息都已确定。每项输入都来自提交的配置:超参数、数据集大小、模型标识符、GPU 分配情况。没有运行时日志,也没有部分进度信息。这正是该预测能够用于调度的原因。
    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.
  • 用于体现额外开销的特征。在原始配置的基础上,我们推导出一些量,例如 num_eval_data(所有评估周期中处理的样本数)、num_saves 和 num_params_saved(检查点 I/O),以及每个 GPU 的 token 数量。FLOP 估算值本身(MFU 固定为 0.45)也作为一个特征加入(baseline_time),这样模型便以仅考虑计算量的数值为起点,并学习相应的修正项。
    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.

我们比较了线性回归、Ridge、XGBoost 和 CatBoost。特征选择结合了相关性筛选、互信息和置换重要性,并评估了 18 组候选特征集,随后以 MAE 为评判标准进行网格搜索。最终的 CatBoost 模型使用了 24 个特征。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 运行记录,涵盖多个模型系列(参数量最高达 150 亿)、LoRA 和全量微调,以及范围广泛的数据集规模和超参数。
    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.
  • 共享基础设施。作业使用从 1 至 4 个节点上的 8 至 32 块 H200 GPU 池中分配的 1、2 或 4 块 GPU 运行,同时还有其他训练和推理工作负载。测得的时间包含实际资源争用的影响。
    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.
  • 时长为 1.6 至 172.4 小时,平均时长为 23.43 小时,中位数为 15.29 小时。
    Durations from 1.6 to 172.4 hours, with a mean of 23.43 h and a median of 15.29 h.
  • 技术栈:Hugging Face Transformers 和 Unsloth。我们将技术栈建模为一个类别特征,不假设两者之间存在固定的加速比。
    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.

fig-duration-distribution

272 次运行的端到端时长分布。平均值为 23.43 小时,中位数为 15.29 小时。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.

Model R² RMSE (h) MAE (h)
FLOP baseline (MFU 30%) 0.31 20.45 12.41
FLOP baseline (MFU 45%) 0.18 22.38 13.01
FLOP baseline (MFU 60%) 0.01 24.56 14.62
Calculon −0.51 30.40 20.36
Linear Regression 0.69 ± 0.14 13.52 ± 4.23 7.52 ± 0.49
Ridge 0.73 ± 0.09 12.72 ± 3.70 7.23 ± 0.68
XGBoost 0.97 ± 0.01 4.18 ± 1.17 1.95 ± 0.32
CatBoost 0.98 ± 0.01 3.52 ± 0.78 1.71 ± 0.33

有几点值得注意。A few things stand out.

没有任何单一的 MFU 值能确定 FLOP 基线。我们将 MFU 从 0.25 到 0.65 进行了扫描。最佳设置为 30%,但对于平均持续 23 小时的作业,平均误差仍超过 12 小时。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.

更详细的分析模型也无法弥合这一差距。作为第二个基线,我们采用了 Calculon(Isaev 等,SC ’23),这是先前工作中用于 LLM 训练的分析性能模型。它构建了显式的层图,并考虑计算、内存流量和设备间通信。我们扩展了其公开实现,使其支持 LoRA、分组查询注意力、融合注意力、bfloat16 和 SwiGLU。即便如此,其估算值的中位数仍仅为观测到的实际运行时间的 11%。这并不意味着 Calculon 作为步骤级工具有什么不足;它本来就是为此设计的。这说明生产任务中有多少工作发生在优化步骤之外。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.

线性模型有所帮助,但随后便陷入瓶颈。Ridge 将 MAE 降至 7.23 小时。纯线性模型无法很好地捕捉配置与持续时间之间的关系。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.

梯度提升承担了主要工作。CatBoost 和 XGBoost 在每项指标上的表现差异都在一个标准差以内。我们选择继续使用 CatBoost,因为它在所有指标上的平均误差都最低。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 的特征重要性集中在少数几个特征上。正如预期,模型和工作负载变量位列其中,但评估和检查点变量也同样重要。num_eval_data(任务整个运行期间在评估中处理的样本总数)排名第一,其次是 num_trainable_params、batch_eval_size_percent、num_all_params 和 num_gpus*batch_train_percent,num_params_saved 紧随其后。SHAP 值也反映了相同的情况:较高的评估量会持续推高预测时间,而可训练参数的数量则呈非线性影响,只有对最大的模型,这种影响才会变得显著。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.

fig-feature-importance

CatBoost 模型在各折中的平均特征重要性(PredictionValuesChange)。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.

解读这些图表时有一点需要注意:更大的 GPU 分配量对预测耗时的贡献为正。在我们的数据中,GPU 分配量越大,作业规模通常也越大,因此 num_gpus 在一定程度上是作业规模的代理变量。这并不意味着增加 GPU 会让作业变慢。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

查看全部 272 个折外预测,中位绝对误差为 0.51 小时。80% 的预测误差在 2.20 小时以内,90% 在 4.31 小时以内。按任务时长细分如下: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:

Job duration (h) Runs Median abs. error (h) P90 (h)
1.56 to 5 60 0.30 1.55
5 to 10 63 0.18 1.27
10 to 30 69 0.73 4.17
30 to 60 67 1.06 5.50
60 to 175 13 5.19 18.51

在60小时以内,误差中位数始终约为1小时或更低。模型难以应对的是长尾部分;而超过60小时的运行仅有13次,因此我们将其视为数据方面的局限。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.

fig-error-by-duration

针对实际时长的折外绝对误差,按时长范围着色。误差在 60 小时以内保持较低,在稀疏的长尾区间则有所扩大。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.

更多数据仍然有帮助。在固定的 20% 留出集上,训练分区的使用比例从 85% 提高到 100% 时,MAE 从 1.63 小时降至 1.50 小时,且没有明显的平台期。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

在实际应用中,预测器会在任务开始前向调度器提供一个可供规划的时长信息:哪些任务可以一起运行、GPU 何时会空闲,以及任务能否在截止时间前完成。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。我们没有纳入 RLHF、DPO 或 RLVR 等其他训练和对齐策略。
    SFT only. We did not include other training and alignment strategies such as RLHF, DPO or RLVR.
  • 单一 GPU 类型。每次运行都使用 H200。拟合出的模型针对这套基础设施进行了校准,因此不应指望它在未经重新训练的情况下,数值上能够迁移到其他 GPU 代际。要为混合 GPU 池构建预测器,还需要提供计算吞吐量、内存容量和带宽,以及互连拓扑等硬件描述信息。
    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.
  • 持续时间特别长的区间很少。超过60小时后,误差会扩大。
    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.

接下来我们将关注:特定于硬件的描述符、在其他 GPU 类型上的验证、针对观测数据较少的配置进行迁移学习、其他训练目标,以及收集更多长时间运行的数据。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

完整论文即将发布在 arXiv 上。关注 Hugging Face 上的 Dharma-AI 组织,以便在论文发布时收到通知,并在下方评论区留下你的问题。我们也很想了解你如何估算自己集群上的作业时长。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 研发 · 我们让 AI 成为你的专属模型Dharma-AI R&D · We Make AI Your Model

值得记下

  1. GPU 是当今 AI 领域成本最高、也最稀缺的资源之一。任何运行共享集群的人每天都必须决定哪些任务使用哪些 GPU,以及按什么顺序运行。
  2. 大多数团队采用的估算方法,不过是粗略地计算一下 FLOP。估算说需要 9 小时,结果任务却到第二天下午才完成。
  3. 一个只使用任务派发前可获取信息的 CatBoost 回归模型,在 5 折交叉验证中达到 R-squared = 0.98,平均绝对误差为 1.71 h,中位误差为 0.51 h。
  4. 特征重要性并不能证明因果关系。不过,这种模式与任务实际耗时的构成相吻合。评估频率、评估集大小以及持久化检查点的数量,都会和模型及数据集规模一起影响实际耗时。

← 回到本期 · 第 15 条