Use the val argument in mask_nan_or_inf_with_val_inplace - #8386
Open
vineethsaivs wants to merge 1 commit into
Open
Use the val argument in mask_nan_or_inf_with_val_inplace#8386vineethsaivs wants to merge 1 commit into
vineethsaivs wants to merge 1 commit into
Conversation
The helper takes `val` and then hardcodes -1.0 in the tensor it fills with, so any caller asking for a different sentinel silently gets -1 instead. `val` was added with the helper in deepspeedai#7184, which folded three copies of the inf/nan masking into one function; the parameter is the knob that refactor introduced and it was never wired to the body. Every in-tree caller uses the default, so the fix is a no-op for them: -1. is the same float the body hardcoded. Signed-off-by: Vineeth Sai <vineethsai4444@gmail.com>
vineethsaivs
requested review from
loadams,
tjruwase and
tohtana
as code owners
September 1, 2026 16:11
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
mask_nan_or_inf_with_val_inplace(input, device=None, val=-1.)acceptsvaland then builds the fill tensor from a hardcoded-1.0, so the argument is dead:Why it is there
valarrived with the helper in #7184, which folded three copies of the inf/nan masking (runtime/utils.py,zero/stage3.py,zero/stage_1_and_2.py) into one function. The parameter is the knob that refactor introduced, and the body kept the literal from the code it replaced.Fix
One line: build
errfromval.All three in-tree callers use the default, and
-1.is the same float the body hardcoded, so the gradient-norm paths are bit-identical.Test
New
test_mask_nan_or_inf_with_val_inplace_honors_valintests/unit/runtime/test_runtime_utils.py, covering nan / +inf / -inf for severalvals plus the unchanged default.The
TestClipGradNorm*/TestCheckOverflowcases in the same file areDistributedTestand were deselected on this CPU-only box; they do not touchval.