Skip to content

Keep refined disk centres float32 so neural Find Vectors works on MPS - #244

Merged
CSSFrancis merged 3 commits into
mainfrom
fix/mps-float64-centre-refiner
Oct 20, 2026
Merged

CSSFrancis merged 3 commits into
mainfrom
fix/mps-float64-centre-refiner

Conversation

@CSSFrancis

@CSSFrancis CSSFrancis commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

Problem

On Apple-silicon Macs, neural Find Diffraction Vectors finds no peaks in v0.6.0-rc.2. Every batch fails at the centre-refine step with:

TypeError: Cannot convert a MPS Tensor to float64 dtype as the MPS framework doesn't support float64.

CentreRefiner.refine (spyde/models/centre_network.py) called centre.double().cpu(). That converts the centres to float64 while they are still on the device. MPS has no float64. CUDA and CPU accept the cast, so CI never saw the failure.

Fix

Keep the centres in float32, the precision the network computes in: centre.float().cpu(). They are window-local coordinates (0–32 px), where float32 is accurate to about 1e-6 px, and the caller widens them for its own arithmetic. Nothing is cast to float64 on the device, and half as much data is copied back. The empty-batch return is float32 too, so both paths return the same dtype.

Verification

  • New TestRefineStep.test_runs_on_apple_mps runs the bundled F5 refiner on MPS against the reference centres. It skips when no MPS device is present. It fails without the fix with the error above and passes with it.
  • test_centre_refiner.py passes in full, including the CPU match against the training code's centres (tolerance 3e-5 px).
  • Real app on a Mac: find_vectors_workflow.spec.ts and fv_neural_calibration.spec.ts both failed on rc.2 with this error. Both pass with the fix. The result window shows "Found 741 diffraction vectors" with the peak markers on the disks.

MPS has no float64, so centre.double() on the device raised in every
neural Find Vectors batch on a Mac and no peaks were found.
They are window-local coordinates (0-32 px), where float32 is exact to
~1e-6 px; the caller widens them for its own arithmetic.
@CSSFrancis CSSFrancis changed the title Move refined disk centres off the GPU before widening them to float64 Keep refined disk centres float32 so neural Find Vectors works on MPS Oct 19, 2026
@CSSFrancis
CSSFrancis merged commit 9caa0f5 into main Oct 20, 2026
35 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.

1 participant