Repository navigation
Keep refined disk centres float32 so neural Find Vectors works on MPS - #244
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
CentreRefiner.refine(spyde/models/centre_network.py) calledcentre.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
TestRefineStep.test_runs_on_apple_mpsruns 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.pypasses in full, including the CPU match against the training code's centres (tolerance 3e-5 px).find_vectors_workflow.spec.tsandfv_neural_calibration.spec.tsboth 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.