Skip to content

Fix Upsample align_corners singleton output - #3769

Merged
zcbenz merged 1 commit into
ml-explore:mainfrom
ishtihoss:fix-upsample-align-corners-one-dim
Jun 28, 2026
Merged

zcbenz merged 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

@zcbenz zcbenz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@zcbenz
zcbenz merged commit 1d20ba3 into ml-explore:main Jun 28, 2026
16 checks passed
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