Skip to content

Fix 'Adaptive pool MPS' crash in post-optimization search - #63

Merged
hvoss-tech merged 1 commit into
hvoss-tech:mainfrom
florissmit10:fix/mps-area-resize
Oct 13, 2026
Merged

hvoss-tech merged 1 commit into
hvoss-tech:mainfrom
florissmit10:fix/mps-area-resize

Conversation

@florissmit10

@florissmit10 florissmit10 commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #62

Problem

On Apple Silicon (MPS), runs crash when the post-optimization search starts:

Adaptive pool MPS: input sizes must be divisible by output sizes.

For large images, the search first shrinks the target with F.interpolate(mode="area"). That uses adaptive_avg_pool2d internally, and MPS only supports it when the old size divides evenly by the new one (pytorch#96056). The new size comes from a scale factor, so in practice it almost never does.

Fix

On MPS only, this one resize now runs on the CPU, and the result moves straight back to MPS. Everything else in the search, including scoring, stays on the GPU.

 target = saved[0].permute(2, 0, 1)[None].float()
+if target.device.type == "mps":
+    target = target.cpu()
 self.target = F.interpolate(target, size=size, mode="area")...
+    .to(saved[0].device)

CUDA, ROCm and CPU runs are unchanged.

Testing

  • The repro from MPS: post-optimization search crashes with 'Adaptive pool MPS' error #62 (1000×777 → 613×477 on MPS) used to raise this error and now returns the expected tensor on mps:0.
  • "Area" resizing is a block average, so the CPU and MPS results match exactly (max difference 0.0, checked on a size MPS can handle).
  • The CPU round trip takes about 10 ms for a 2000×1500 image, and it happens once per search, not once per iteration.
  • Test suite: 762 passed, 8 failed. The same 8 tests also fail on main without this change.

Risk

Low. The change only affects MPS runs with images large enough to be downsampled for the search, and it's easy to revert.

F.interpolate(mode="area") uses adaptive_avg_pool2d, which MPS only
supports for evenly divisible sizes. Fixes hvoss-tech#62.
@hvoss-tech

Copy link
Copy Markdown
Owner

Hey Floris,

Thank you for the quick fix! I'll merge it.

@hvoss-tech
hvoss-tech merged commit 1791f68 into hvoss-tech:main Oct 13, 2026
1 of 4 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.

MPS: post-optimization search crashes with 'Adaptive pool MPS' error

2 participants