Skip to content

Fix Upsample align_corners singleton output#3769

Open
ishtihoss wants to merge 1 commit into
ml-explore:mainfrom
ishtihoss:fix-upsample-align-corners-one-dim
Open

Fix Upsample align_corners singleton output#3769
ishtihoss wants to merge 1 commit into
ml-explore:mainfrom
ishtihoss:fix-upsample-align-corners-one-dim

Conversation

@ishtihoss

Copy link
Copy Markdown
Contributor

Summary

Fix nn.Upsample with align_corners=True when an output spatial dimension is 1.

The aligned-corners scale used (N - 1) / (M - 1), so M == 1 raised a ZeroDivisionError. Using max(M - 1, 1) keeps existing behavior for M > 1 and maps singleton outputs to the first input coordinate.

Tests

  • black --check python/mlx/nn/layers/upsample.py python/tests/test_nn.py
  • python -m unittest test_nn.TestLayers.test_upsample_align_corners_one_dim -v
  • python -m unittest test_nn.TestLayers.test_upsample -v

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