Conversation
Values grabbed from Torchtitan + expanded with some instances available in hf jobs
fix: device name check is now bounded to avoid collisions (like A100 and A1000) add: mfu infos in trainers docs
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
Signed-off-by: DWarez <dario.salvati@huggingface.co>
|
|
||
| # Theoretical dense accelerator throughput. Values and sources follow TorchTitan's BF16 peak-FLOPs lookup, extended | ||
| # with the additional NVIDIA GPUs offered by Hugging Face Jobs. More specific names must precede their prefixes. | ||
| _PEAK_FLOPS_BY_DEVICE = ( |
There was a problem hiding this comment.
Niice, I wanted to have this in utils for a long time 😄 !
bf16 is enough for now I think, most people will train in this precision
| device_name = torch.xpu.get_device_name(device) | ||
| else: | ||
| device_name = device.type | ||
| dtype = {"bf16": torch.bfloat16, "fp16": torch.float16, "no": model_dtype}.get(accelerator.mixed_precision) |
There was a problem hiding this comment.
right that makes sense, I changed it and also changed the mapping (the dict associated to the accelerator name) to reflect the same naming (so without torch.) to make matching more immediate 👍
| ("NVIDIA L40", torch.bfloat16), | ||
| ("NVIDIA A1000", torch.bfloat16), | ||
| ("NVIDIA XA100", torch.bfloat16), | ||
| ("Intel Data Center GPU Max 15500", torch.bfloat16), |
There was a problem hiding this comment.
I am really not sure trl works with this device in the general settings.
We use NCCL groups and I am pretty just this vllm weightransfer is Nvidia only 🤔
There was a problem hiding this comment.
yeah I wasn't really sure about that. I saw that TRL has explicit support for XPUs but I guess that not everything works out of the box. I've removed those entries for the time being, we can also add them back eventually
change: removed intel stuff from the lookup because of we're not sure it's supported, so removing it for now
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want higher recall? High effort reviews run extra passes and find more bugs. A team admin can switch effort levels in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit daf8010. Configure here.
| device = accelerator.device | ||
| if device.type == "cuda": | ||
| device_name = torch.cuda.get_device_name(device) | ||
| else: | ||
| device_name = device.type | ||
| peak_flops = get_peak_flops(device_name, dtype) | ||
| peaks = gather_object([peak_flops]) | ||
| if any(peak is None for peak in peaks): | ||
| logger.info( | ||
| "MFU metrics are disabled because the peak FLOPs are unknown for at least one training device or " | ||
| "precision. Throughput and timing metrics are still reported." | ||
| ) | ||
| return None | ||
| return sum(peaks) / len(peaks) |
There was a problem hiding this comment.
I think this is too defensive: mixed GPU models in a single job basically never happens, and even when it does nothing breaks, log builds the metrics dict locally and only the main process reports, so ranks disagreeing about whether to emit perf/mfu_* doesn't hang anything.
I'd drop the gather and just use the local device's peak. Same for the device.type != "cuda" branch, xla devices report device.type == "xla" so it never matches the TPU or trn entries in the table.
There was a problem hiding this comment.
can I use torch.cuda.get_device_name(accelerator.device) or do we need a check also for TPUs? In that case I can drop tranium entries from the mapping. In case we cannot map we just warn and then omit the metric

What does this PR do?
The async trainers currently compute MFU using the
compute_mfufunction but without passing it the device's flops, therefore the formula will use the default value for it, which is the peak flops for the H100.In this PR we define
_PEAK_FLOPS_BY_DEVICEwhich maps the device name to its peak flops (I used torchtitan's mapping as the main source of truth and validated most of nvidia's entries with the official specs). Furthermore, the mapping is dtype/precision aware so it can be eventually expanded with lower precision types.I preferred to avoid exposing the mfu computation when the peak flops could not be retrieved since using a generic denominator would provide false data to the user, but let me know if you'd like this behavior to be different.
I tested these changes using hf jobs with 2xH200 for both trainers on some smoke runs (so the mfu is quite low) but the retrieved peak flops was indeed correct
Before submitting
AI writing disclosure
We welcome the use of AI tools to help with contributions. For transparency and to help us improve our review process, please indicate the level of AI involvement in this PR.
Who can review?
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag members/contributors who may be interested in your PR.
Note
Low Risk
Changes are limited to observability (MFU metrics) and utility lookups; training loss and optimization paths are untouched, with MFU omitted rather than misreported when capacity is unknown.
Overview
MFU in AsyncGRPO and AsyncDistillation no longer assumes a fixed H100 peak FLOPs denominator. At trainer init, peak capacity is resolved from the actual training devices and mixed-precision dtype via new helpers
get_peak_flopsandget_peak_flops_per_deviceintrl/trainer/utils.py, backed by a dtype-aware_PEAK_FLOPS_BY_DEVICEtable (NVIDIA, AMD, Trainium/Inferentia, TPU).compute_mfunow requires an explicitpeak_flops_per_device(the old H100 default is removed).perf/mfu_fwd_bwdandperf/mfu_wall_clockare logged only when every rank has a known peak for that precision; otherwise MFU is skipped and throughput/timing metrics still run. Heterogeneous clusters use the mean peak across ranks when all are known.Docs for both async trainers expand the Performance section (throughput vs MFU,
_fwd_bwdvs_wall_clock, training-device-only scope, omission behavior). Tests cover the lookup table, distributed “all ranks must be known” rule, and step-metric MFU gating.Reviewed by Cursor Bugbot for commit e658593. Bugbot is set up for automated code reviews on this repo. Configure here.