test(clip_grads): add regression coverage for get_grad_norm_fp32 - #5828
test(clip_grads): add regression coverage for get_grad_norm_fp32#5828Mattral wants to merge 3 commits into
Conversation
test_clip_grads.py previously contained a single test covering only
OptimizerConfig.grad_norm_skip_threshold's default value. get_grad_norm_fp32
itself had no coverage across any of its three norm_type branches.
Add parametrized tests for norm_type in {2.0, inf, 1.0}, covering:
- empty grads_for_norm returning 0.0 without raising (regression test
for the crash fixed in NVIDIA#5530 / issue NVIDIA#5529)
- non-empty grads_for_norm matching a plain torch.norm-based reference
computation
Signed-off-by: Min Htet Myet <88831350+Mattral@users.noreply.github.com>
|
This PR has been automatically converted to draft because all PRs must start as drafts. When you are ready for review, click Ready for Review to begin the review process. This will:
See the contribution guide for more details. |
|
/ok to test 254c131 |
|
@Mattral please fix the failing tests. |
|
Thanks for the ping I'll investigate the unit test failure (want to confirm whether it's related to this change or a pre-existing issue in the suite) and push a fix by Monday. |
Signed-off-by: Mattral <mattralminn@gmail.com>
Head branch was pushed to by a user without write access
254c131 to
c43b3a0
Compare
|
@guihong-nv . Found the root cause: the test assumed a single rank, but CI runs unit tests with |
|
Hi @guihong-nv following up here. The fix landed last week (test now accounts for world_size in the SUM vs MAX all-reduce comparison). I notice a couple of checks are still pending let me know if those need an approval on your end, or if there's anything else you'd like adjusted before another look. |
|
@Mattral may you please resolve the conflict here? |
|
@guihong-nv |
Summary
Follow-up to #5530.
test_clip_grads.pyhad no test coverage forget_grad_norm_fp32itself — this adds regression tests for all threenorm_type branches, including the empty-
grads_for_normcase that #5530 fixed.Changes
tests/unit_tests/optimizer/test_clip_grads.pytest_empty_grads_returns_zero(parametrized over2.0,inf,1.0):regression test for the crash fixed in fix(clip_grads): handle empty grads_for_norm in inf-norm and p-norm paths #5530
test_nonempty_grads_matches_reference(same parametrization): baselinecorrectness check against a plain
torch.normcomputationTesting
black,isort,pylint,ruff—all clean via
tools/autoformat.sh)and every test in this suite requires
torch.distributedinitialization);relying on CI's GPU runners for actual execution
megatron/core/optimizer/clip_grads.py— test-only PRChecklist
git commit -s)mainFixes #5827