Skip to content

fix(rpp): Fix normalize to apply per-sample mean/stddev for caller-supplied params - #12002

Open
sruthi0107 wants to merge 1 commit into
developfrom
users/sruthi0107/fix-normalize-cms0-per-sample-params
Open

fix(rpp): Fix normalize to apply per-sample mean/stddev for caller-supplied params#12002
sruthi0107 wants to merge 1 commit into
developfrom
users/sruthi0107/fix-normalize-cms0-per-sample-params

Conversation

@sruthi0107

Copy link
Copy Markdown

Motivation

Normalize processes a batch of samples, and each sample has its own mean and stddev. Internally it locates a sample's parameters with a per-sample stride (meanTensor + batchCount * maxSize). When the caller supplies both mean and stddev, that stride was set to zero, so every sample read sample 0's values and the whole batch was normalized with sample 0's mean and stddev. The modes where the kernel computes one statistic (cms1: mean computed; cms2: stddev computed) already stride per sample and match the reference on both backends, so per-sample is the intended layout. The both-supplied mode (cms0) was the outlier.

Issue

JIRA ID : AICV-222

Technical Details

Remove the stride zeroing on both backends so each sample reads its own parameters again.

  • HOST: drop maxSize = 0 in both entry points (f32/f32 and generic). The supplied stddev also gets converted to the scale / stddev multiplier form in a one-time loop; that loop only covered sample 0 before (safe only because of the broadcast), so it now runs over the whole batchSize * maxSize array.
  • HIP: drop the matching maxParamVolume = 0. No conversion loop is needed here — the kernel computes scale / stddev at the point of use, so restoring the stride is enough.

Test Plan

Ran the normalize correctness filters from the GoogleTest suite: rpp_tests --gtest_filter='*NormalizeTest*cms0*'.

Test Result

Test Before After
HOST F32 2D axis3 cms0 2×24×32, sample 1 element (0,0) 0.314706 (expected 0.043137) 0.043137 PASS
HIP F32 2D cms0 (all reduction masks) FAIL PASS
HIP F16 2D cms0 FAIL PASS
HOST F16 2D cms0 FAIL PASS

…upplied

When both statistics are caller-supplied, the per-sample stride into
meanTensor/stdDevTensor was zeroed (HOST: maxSize = 0; HIP:
maxParamVolume = 0), so every sample read sample 0's parameter block
instead of its own. The partial-compute modes already stride per sample
and match the reference on both backends, so per-sample is the intended
layout and the both-supplied path was the outlier.

HOST: drop the maxSize zeroing in both entry points and convert the whole
batchSize * maxSize stddev array (previously only sample 0's block was
converted to the scale / stddev multiplier form, which was masked by the
broadcast). HIP: drop the maxParamVolume zeroing; the kernel already
derives scale / stddev at point of use, so per-sample indexing is enough.

Fixes cms0 on both backends (HIP F32/F16 fully green; HOST 2D/4D/F16
green). HOST 3D cms0 remains red due to a separate 3D reduction defect
tracked in its own issue.
@sruthi0107
sruthi0107 requested a review from a team as a code owner September 11, 2026 20:25
@therock-pr-bot

therock-pr-bot Bot commented Sep 11, 2026

Copy link
Copy Markdown

✅ All Checks Passed — Ready for Review

Check Status Details
📝 PR Description ✅ Pass
Forbidden Files ✅ Pass
🧪 Unit Test ⚠️ Warning Error: Source/code files changed without an accompanying unit test.
Expected: add at least one test file named like test_<name>.py / test_<name>.cpp (or <name>_test.*).
Current: code file(s) changed: projects/rpp/src/modules/tensor/cpu/kernel/normalize.cpp, projects/rpp/src/modules/tensor/hip/kernel/normalize.cpp; no test file found
🔎 pre-commit ✅ Pass
🚫 Draft PR 🔜 To Be Enabled
🚩 Feature Flag 🔜 To Be Enabled
📊 Code Coverage 🔜 To Be Enabled
🤖 therock-pr-bot ✅ Pass

🎉 All checks passed! This PR is ready for review.

📖 Need help? See the Policy FAQ for details on every check and how to fix failures.

🙋 Wish to Override Policy?

@therock-pr-bot

Copy link
Copy Markdown

🎉 All checks passed! This PR is ready for review.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant