Guard compute_mfu against a zero denominator (world_size == 0)#6174
Open
CharlesCNorton wants to merge 1 commit into
Open
Guard compute_mfu against a zero denominator (world_size == 0)#6174CharlesCNorton wants to merge 1 commit into
CharlesCNorton wants to merge 1 commit into
Conversation
compute_mfu divided by peak_flops_per_device * world_size with no guard, raising ZeroDivisionError when world_size (or peak_flops_per_device) is 0. Return 0.0 in that case so a metric on the logging path cannot abort training.
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.
What does this PR do?
compute_mfu(intrl/trainer/utils.py) divides bypeak_flops_per_device * world_sizewith no guard, so a zero denominator (world_size == 0, or a zeropeak_flops_per_device) raisesZeroDivisionError: float division by zero:compute_mfuis a metric helper for the trainer's logging path, so a degenerate input should not be able to abort training. This returns0.0when the denominator is zero (no compute capacity to utilize, so MFU is 0) instead of raising; normal inputs are unchanged.A regression test is added to
TestComputeMfuintests/test_utils.py.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.
Note
Low Risk
Tiny change to a metric helper with no effect on normal training inputs; only avoids crashes on edge-case logging values.
Overview
compute_mfuno longer divides whenpeak_flops_per_device * world_sizeis zero (e.g.world_size == 0or zero peak FLOPs). It returns0.0instead of raisingZeroDivisionError, so degenerate inputs on the trainer MFU logging path cannot crash training. Valid inputs behave the same as before.A regression test
test_zero_world_size_returns_zerowas added inTestComputeMfu.Reviewed by Cursor Bugbot for commit 3839e9a. Bugbot is set up for automated code reviews on this repo. Configure here.