Fix MFU helpers for configs without KV head count - #6871
Open
DaoyuanLi2816 wants to merge 2 commits into
Open
Conversation
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 33fe81a. Configure here.
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_flops_per_tokenandadjusted_mfucurrently raise anAttributeErrorfor GPT-NeoX configs because they do not declarenum_key_value_heads. GPT-NeoX uses standard multi-head attention, so this falls back tonum_attention_headswhen the optional KV-head field is absent.The regression tests compare the implicit fallback with the same config after explicitly setting
num_key_value_headstonum_attention_heads.Validation
python -m pytest -q tests/test_utils.py -k "ComputeFlopsPerToken or ComputeMfu or AdjustedMfu"— 11 passed, 222 deselectedpython -m ruff check trl/trainer/utils.py tests/test_utils.pypython -m ruff format --check trl/trainer/utils.py tests/test_utils.pygit diff --checkBefore 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
Narrow fallback in FLOP/MFU estimation only; no training, auth, or data-path changes.
Overview
Stops
compute_flops_per_tokenfrom crashing on configs that omitnum_key_value_heads(e.g. GPT-NeoX MHA). It now falls back tonum_attention_heads, which also unblocksadjusted_mfu.Tests compare the implicit fallback against the same config with the field set explicitly.
Reviewed by Cursor Bugbot for commit 5833714. Bugbot is set up for automated code reviews on this repo. Configure here.