Skip to content

fix(inference): avoid float32 overflow in StatsNormalizer - #327

Open
ShubhJain09 wants to merge 1 commit into
openvinotoolkit:mainfrom
ShubhJain09:fix/stats-normalizer-overflow
Open

ShubhJain09 wants to merge 1 commit into
openvinotoolkit:mainfrom
ShubhJain09:fix/stats-normalizer-overflow

Conversation

@ShubhJain09

Copy link
Copy Markdown

Summary

  • _normalize in StatsNormalizer now does the math in float64 and casts the result back to the dtype it produced before
  • The fix covers the mean std and min max and quantiles modes which all had the same overflow
  • Added regression tests for each mode and a check that the output dtype stays the same for float16 float32 and float64 inputs

Why

  • The stats normalizer fuzz job fails on main because intermediates like 2 * (x - q01) overflow float32 to inf even when the normalized value is an ordinary number
  • One crash input had x equal to 0 and q01 around -2.3e38 where the correct output is 1 but the old code returned inf
  • This makes the required fuzz check fail on unrelated PRs such as fix(runtime): discard stale inference after watchdog reset and warmup timeout #320

Validation

  • The new overflow tests fail on main for all three modes and pass with this change
  • Both crash inputs saved by CI now pass the harness and a 120 second fuzz run did over 4 million executions with no crash
  • pytest tests/unit packages/*/tests passes and prek run --all-files is clean
  • The float64 path adds roughly 1.4 ms on a 640x480 frame and under a microsecond for joint state

Breaking changes

  • None

Related issues

Signed-off-by: ShubhJain09 <shubhmohta07@gmail.com>
@ShubhJain09
ShubhJain09 requested a review from a team as a code owner October 2, 2026 14:21
Copilot AI balanced review requested due to automatic review settings October 2, 2026 14:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The focused implementation resolves the overflow while preserving established dtype behavior with comprehensive regression coverage.

Review effort: Balanced
Findings: None

What changed in this PR

Prevents representable normalization results from overflowing during float32 intermediate calculations.

Changes:

  • Performs normalization arithmetic in float64, then restores the expected output dtype.
  • Adds overflow regressions and dtype-preservation tests for all normalization modes.
File Description
src/​physicalai/​inference/​preprocessors/​stats_normalizer.py Uses float64 intermediates across normalization modes.
tests/​unit/​inference/​preprocessors/​test_stats_normalizer.py Covers overflow cases and output dtypes.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

This branch has not been deployed

No deployments
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.

2 participants