Fix BatchNorm docstring to cover 4D input and test the NHWC path#3782
Merged
Conversation
The BatchNorm summary line said it applies over a 2D or 3D input, but the layer also accepts 4D NHWC tensors: the __call__ guard allows 2-4 dims (and its error message says "2, 3 or 4 dimensions"), and the docstring body already describes the four-dimensional NHWC shape. Correct the summary to match, and add the missing 4D coverage to test_batch_norm, asserting that an NHWC input is normalized per channel across N, H and W.
05881b5 to
a105e98
Compare
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.
Summary
nn.BatchNorm's docstring summary says it applies over a "2D or 3D input", but the layer also supports 4D NHWC tensors:BatchNorm.__call__guardsx.ndim < 2 or x.ndim > 4and its own error message says"Expected input tensor to have 2, 3 or 4 dimensions".NHWC...".So the summary line contradicts both the code and the rest of its own docstring. This corrects the summary to "2D, 3D or 4D input".
Test
test_batch_normpreviously covered only 2D and 3D inputs (plus a 5DValueErrorcheck); the 4D NHWC path was never exercised. Added a 4D case asserting the output is normalized per channel across N, H and W (per-channel mean ≈ 0, var ≈ 1).No behavior change — documentation + test coverage only.