Repository navigation
Honor mask in nnx.metrics.Welford - #5613
Open
vineethsaivs wants to merge 1 commit into
Open
vineethsaivs wants to merge 1 commit into
vineethsaivs wants to merge 1 commit into
Conversation
Welford.update took mask through **kwargs and dropped it, so a masked MultiMetric put padding into the Welford mean, std and SEM. Merge only the kept entries (masked count, mean and M2), guard the division so a fully masked batch is a no-op, and raise for a scalar with a mask, as Average does.
This branch has not been deployed
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?
nnx.metrics.Welfordignoresmask. UpdatingMultiMetric(loss=Average(), stats=Welford())with values[1, 2, 3, 100]and mask[1, 1, 1, 0]gives loss 2.0, but Welford reports mean 26.5 and std 42.44, not 2.0 and 0.8165.Welford.updatetakesmaskthrough**kwargsand never reads it, whileMultiMetricpasses an array mask to every metric.The fix merges only the kept entries (masked count, mean and M2), makes a fully masked batch a no-op, and raises for a scalar with a mask, like
Average. Unmasked results are bit-identical. Behavior change: a global mask that doesn't broadcast to a Welford's values now raises instead of being ignored; use a dict mask there.The new test fails on main (mean 51.0, expected 2.0) and passes with the fix.
Checklist