Repository navigation
[metrics] Do not report MFU when the device peak FLOPS is unknown - #5880
Merged
Merged
Conversation
This was referenced Nov 6, 2026
fegin
marked this pull request as ready for review
November 6, 2026 02:05
fegin
requested review from
acisseJZhong,
d4l3k,
felipemello1,
shuhuayu,
tianyu-l and
wwwjn
as code owners
November 6, 2026 02:05
tianyu-l
approved these changes
Nov 6, 2026
fegin
added a commit
that referenced
this pull request
Nov 8, 2026
Stacked PRs: * #5882 * #5881 * #5880 * __->__#5879 --- --- --- ## Summary (human-written) With fake_pg, the tflops becomes `tflops // dp_mesh_size`. The reason is that `allreduce` is an no-op but `dp_mesh_size` is a constant value not affected by whether it is fake pg or real pg. This PR submit another row that contains all 1 so that when doing real or fake `allreduce`, the `tflops` is always accurate (fake pg tflops is pure computation). ## Why Since #4819, the trainer logs the DP average of FLOPs as `dist_sum(flops) / dp_mesh.size()`. On a fake process group the all-reduce is a no-op, so the "sum" is only the local value, but it is still divided by the DP size. Logged TFLOPS and MFU come out 1/DP of the right value. Real process groups are not affected. **Example.** DP8, each rank does 100 TFLOPS: | | all-reduce sum | divided by | logged | |---|---|---|---| | real PG | 800 | 8 (mesh size) | 100 | | fake PG, main | 100 | 8 (mesh size) | 12.5 (8x too low) | | fake PG, this PR | 100 | 1 (summed count) | 100 | ## What changed - New `dist_utils.dist_mean(x, mesh)`: all-reduces `[x, 1]` and returns `sum / count`. On a real process group this equals `dist_sum(x) / mesh.size()`. On a fake process group it returns the local value. - `Trainer.train_step` and the RL trainer use it for the DP average of FLOPs. ## Alternatives considered - Log local FLOPs only: drops the DP average that #4819 added for batches whose FLOPs differ across ranks. - Check for the fake backend in the trainer: extra code for a case the count already handles. ## Numerics / performance - Loss and grad norm are unchanged. Logged FLOPs are unchanged on real process groups. - llama3 debug model, fake PG, NGPU=8 (DP8): FLOPs per token is 8.946e6 on main and 7.158e7 with this PR, matching the value before #4819. ## Testing - `test_trainer_accumulates_reused_accelerator_graph_losses[fake_dp=True]` runs `train_step` on an 8-way fake DP mesh. On main it logs 75.0 instead of 600.0. - CPU tests for the trainer, distributed utils, FLOPs estimators, and observability pass. ## Known issues / follow-ups - The TorchFT trainer divides its FLOPs and loss sums by the mesh size in the same way. Not changed here.
## Summary (human-written)
<!-- Write this yourself, not with an AI tool. 2-5 sentences: the problem, why
this approach, and what you checked yourself. -->
## Why
`get_peak_flops` falls back to the A100 peak (312 TFLOPS) for any device it does not list, from any vendor: a new NVIDIA, AMD, or Intel GPU, or an unknown TPU version. On an unlisted device, MFU is then computed against the wrong peak. The value looks plausible but is wrong, and on a fast device it can go above 100%.
**Example.**
```text
GPU with 4x the A100 peak, running at 40% real MFU
before: Peak FLOPS used for computing MFU: 3.120e+14 ... mfu: 160.00%
after: WARNING Peak FLOPS unknown for <device name>. MFU is not reported. ... mfu: N/A
```
## What changed
- `get_peak_flops` returns None for an unknown GPU and for an unknown TPU version, and logs a warning that MFU is not reported. Known devices keep their values. The lspci H100 detection stays.
- `compute_training_performance_metrics` skips `mfu_percent` when the peak is None. The metrics log already prints `mfu: N/A` and leaves out `mfu(%)` when MFU is missing, as it does for quantized runs. TFLOPS is still reported.
- The Trainer, RL trainer, and TorchFT trainer log "Peak FLOPS used for computing MFU" only when the peak is known. The RL trainer already reports `trainer/mfu_percent` only when it is present.
- Unchanged: an unknown AWS Neuron device still falls back to the trn2/trn3 peak. That is a same-family estimate, not a different vendor's peak, and it is out of scope here.
## Alternatives considered
- Keep the A100 fallback and only warn. The wrong MFU still reaches dashboards, where the warning is not seen.
- Raise for an unknown device. That blocks training on new hardware only for a metric.
## Testing
- `test_get_peak_flops` (CPU): H100 and A100 keep their values. An unknown GPU name and an unknown TPU version give None. The unknown cases catch a silent A100 fallback. lspci is mocked so the device name decides.
- `test_compute_training_performance_metrics_without_peak_flops` (CPU): with no peak, the metrics keep tokens per second and TFLOPS and have no `mfu_percent`.
- CPU tests: tools utils, observability, trainer, TorchFT, and RL CPU tests. The RL failures and collection errors also happen on main (missing vllm, and an old `renderers` package).
stack-info: PR: #5880, branch: fegin/stack/9
fegin
marked this pull request as draft
November 8, 2026 17:52
fegin
marked this pull request as ready for review
November 8, 2026 17:53
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked PRs:
Summary (human-written)
When running on an unkown hardware, TorchTitan just uses the peak flops of A100, which is very confusing. Instead of using A100 peak flops, we should just warn and not report.
Why
get_peak_flopsfalls back to the A100 peak (312 TFLOPS) for any device it does not list, from any vendor: a new NVIDIA, AMD, or Intel GPU, or an unknown TPU version. On an unlisted device, MFU is then computed against the wrong peak. The value looks plausible but is wrong, and on a fast device it can go above 100%.Example.
What changed
get_peak_flopsreturns None for an unknown GPU and for an unknown TPU version, and logs a warning that MFU is not reported. Known devices keep their values. The lspci H100 detection stays.compute_training_performance_metricsskipsmfu_percentwhen the peak is None. The metrics log already printsmfu: N/Aand leaves outmfu(%)when MFU is missing, as it does for quantized runs. TFLOPS is still reported.trainer/mfu_percentonly when it is present.Alternatives considered
Testing
test_get_peak_flops(CPU): H100 and A100 keep their values. An unknown GPU name and an unknown TPU version give None. The unknown cases catch a silent A100 fallback. lspci is mocked so the device name decides.test_compute_training_performance_metrics_without_peak_flops(CPU): with no peak, the metrics keep tokens per second and TFLOPS and have nomfu_percent.rendererspackage).