Skip to content

Track masked running normalization per feature and valid row - #425

Open
Afloat16 wants to merge 2 commits into
Denys88:masterfrom
Afloat16:afloat16/masked-feature-normalization-statistics-20261116
Open

Afloat16 wants to merge 2 commits into
Denys88:masterfrom
Afloat16:afloat16/masked-feature-normalization-statistics-20261116

Conversation

@Afloat16

Copy link
Copy Markdown
Contributor

Problem

The masked RunningMeanStd update delegates to a pooled scalar-moment helper, although the unmasked normalizer tracks separate feature/channel statistics. It also adds the full input batch length to its count, including masked-out rows. Depending on shape, row masks either broadcast incorrectly or produce pooled statistics; excluded NaN padding can also poison persistent state through multiplication by zero.

Changes

Select valid rows before computing moments, use the normalizer's existing reduction axes and population-variance convention, and increment the running count by the number of selected rows. An empty masked selection leaves the prior unchanged. Both one-dimensional and column row masks are supported.

The 40 regression cases compare each update against feeding the actual valid rows to an unmasked normalizer. They cover feature and per-channel layouts, Boolean/float masks, eager/TorchScript execution, repeated updates, zero/one valid rows, NaN padding, normalization/denormalization, and state-dictionary restoration.

Validation

On Python 3.11 and 3.14, the full suite changes from 40 failed, 413 passed, 16 skipped to 453 passed, 16 skipped. All six existing CI jobs pass, including lock, lint, and Python 3.11–3.14 tests.

Related: #379 addresses pooled masked moments and #399 handles physically empty input batches. This change corrects featurewise statistics and sample counts for nonempty masked normalization calls.

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (master@9c0b3a0). Learn more about missing BASE report.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff            @@
##             master     #425   +/-   ##
=========================================
  Coverage          ?   58.37%           
=========================================
  Files             ?       70           
  Lines             ?     8868           
  Branches          ?        0           
=========================================
  Hits              ?     5177           
  Misses            ?     3691           
  Partials          ?        0           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Denys88

Denys88 commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Thanks for the detailed PR. I checked master and no caller passes mask= to RunningMeanStd.forward: the value normalizer is fed the sliced valid rows (values[valid]), observation normalization has no mask, and the advantage normalizer is a different class. So this rewrites a path that is dead in the repo, and it replaces a mask-multiply with boolean indexing, which forces a device sync on a hot path if it ever did get used. Do you have a real caller or training scenario where the masked path is exercised and the pooled statistics produced a measurable problem? Without one I'm inclined to close this. (Also overlaps with #379 which touches the same masked moments.)

@Afloat16

Copy link
Copy Markdown
Contributor Author

Thanks. I traced the current callers and your distinction is correct: value normalization slices values[valid] / returns[valid] before calling RunningMeanStd, observation normalization passes no mask, and the masked advantage calls use GeneralizedMovingStats, a different class.

The 40 cases here exercise the public masked normalizer API directly; they do not establish an in-repository training regression or a measured training impact. I also have no GPU profiling result that would justify dismissing the dynamic boolean-indexing/synchronization cost you identified.

This therefore remains an API correctness case pending a concrete consumer and workload evidence. I will keep it separate from #379's actively used pooled-moment path and defer further changes until that evidence supports the extra masked-normalizer implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants