Skip to content

Fix InstanceNorm Shape docstring to require at least 3 dimensions#3903

Open
ayaangazali wants to merge 1 commit into
ml-explore:mainfrom
ayaangazali:fix-instancenorm-shape-doc
Open

Fix InstanceNorm Shape docstring to require at least 3 dimensions#3903
ayaangazali wants to merge 1 commit into
ml-explore:mainfrom
ayaangazali:fix-instancenorm-shape-doc

Conversation

@ayaangazali

Copy link
Copy Markdown
Contributor

Proposed changes

The InstanceNorm docstring Shape section says the input is (..., C), which reads like a 2D (N, C) input is allowed, but __call__ raises for anything with fewer than 3 dimensions:

import mlx.core as mx
import mlx.nn as nn

nn.InstanceNorm(4)(mx.zeros((2, 4)))
# ValueError: InstanceNorm expects inputs with at least 3 dimensions (N, ..., C) ...

Updated the Shape line to (N, ..., C) and noted the at-least-3-dimensions requirement, matching the error message and the reduction over the spatial axes. Same spirit as the earlier BatchNorm shape doc fix (#3782).

Checklist

Put an x in the boxes that apply.

  • I have read the CONTRIBUTING document
  • I have run pre-commit run --all-files to format my code / installed pre-commit prior to committing changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the necessary documentation (if needed)

(docstring-only, test_nn.py passes 69/69)


being honest: freshman here, Claude Code helps me find these mismatches but i reproduced the 3-dimension error above myself and read the reduction axes to make sure the constraint is real before opening this. corrections welcome :)

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.

1 participant