Skip to content

[metrics] Do not report MFU when the device peak FLOPS is unknown - #5880

Merged
fegin merged 1 commit into
mainfrom
fegin/stack/9
Nov 8, 2026
Merged

fegin merged 1 commit into
mainfrom
fegin/stack/9

Conversation

@fegin

@fegin fegin commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

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_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.

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).

@pytorch-bot pytorch-bot Bot added the ciflow/rl label Nov 6, 2026
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 6, 2026
@fegin
fegin marked this pull request as ready for review November 6, 2026 02:05
@pytorch-bot pytorch-bot Bot added the ciflow/fake-pg Run 1-GPU Fake PG integration tests label Nov 6, 2026
@github-actions
github-actions Bot requested a review from pzhan9 November 6, 2026 02:05
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
fegin marked this pull request as draft November 8, 2026 17:52
@fegin
fegin changed the base branch from fegin/stack/8 to main November 8, 2026 17:52
@pytorch-bot pytorch-bot Bot removed the ciflow/fake-pg Run 1-GPU Fake PG integration tests label Nov 8, 2026
@fegin
fegin marked this pull request as ready for review November 8, 2026 17:53
@pytorch-bot pytorch-bot Bot added the ciflow/fake-pg Run 1-GPU Fake PG integration tests label Nov 8, 2026
@fegin
fegin merged commit c561eee into main Nov 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/fake-pg Run 1-GPU Fake PG integration tests ciflow/rl CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants