amyloid finder: add experimental downscale-once path - #1364
Open
hilaolu wants to merge 1 commit into
Open
Conversation
Author
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.

This PR adds an opt-in
downscale_onceimage-preparation backend to the amyloid finder. Instead of rotating the full-resolution micrograph and Fourier-cropping every sampled orientation, the new backend Fourier-crops the micrograph once and rotates the smaller image for every orientation.The legacy backend remains the default. The new backend is explicitly experimental because changing the order of discrete rotation and downscaling changes the FOM and PSI maps. It should not be used as a numerically equivalent replacement until its biological output has been validated on a broader dataset.
This work is separate from #1351. That PR uses a three-angle ring buffer to reduce memory while preserving bit-identical results. This PR explores a different performance/quality tradeoff: it reduces image-preparation work, but does not preserve legacy numerical results.
Rationale
The legacy preparation path performs the following work for each of the
K = nr_psi / 2independently rotated orientations:where:
Ais the full-resolution padded image;Bis the Fourier-cropped image;K = 18for 36 PSI orientations at the benchmark settings.The experimental backend instead performs:
For the benchmark pixel sizes, the linear scale factor is
and the approximate two-dimensional pixel-area fraction is
Each low-resolution rotation therefore touches approximately 15.6% as many pixels, an 84.4% reduction. The number of full-resolution Fourier transforms and crops falls from 18 to 1, a 94.4% reduction.
The
2.1 A/pixeldownscaled image has a4.2 ANyquist limit, which includes the configured4.65-4.85 Asignal band and reaches the edge of the4.2-4.4 Anon-signal band. In continuous mathematics, isotropic low-pass filtering and rotation can commute. In this implementation they are discrete operations with interpolation, finite support, and boundary handling, so their order is not numerically interchangeable. That difference is visible in the validation below.Interface and safety
The new expert option is:
legacyremains the default. Selectingdownscale_onceprints a warning that the interpolation order changes and that FOM/PSI quality must be validated before production use. Unknown backend names are rejected.Benchmark method
The benchmark used:
5760 x 4092, float32, at0.83 A/pixel;--down_angpix 2.1;--psi_step 5.0;--shift_step 5;--skip_tracing;OMP_PLACES=coresandOMP_PROC_BIND=close;memory.peak;Benchmark results: 1 MPI x 8 threads, 1 micrograph
The coarse internal progress timings localise most of the gain to image preparation:
The coordinate-scoring phase is intentionally unchanged by this PR.
Weak scaling: 2-4 MPI ranks x 8 threads
Additional single-run benchmarks tested node-level weak scaling with two, three, and four MPI ranks. Each rank was bound to eight cores and processed one micrograph, so both the rank count and the number of micrographs increased together. All input micrographs had the same file size and came from the same dataset.
Using the 2-rank result as the weak-scaling baseline, legacy efficiency falls to 84.96% at three ranks and 69.76% at four ranks.
downscale_onceretains 93.96% and 89.03%, respectively. From two to four ranks, the legacy wall time grows by 43.3% for the same work per rank, while thedownscale_oncewall time grows by only 12.3%.On this node, the legacy preparation path therefore does not scale well beyond two MPI ranks, whereas
downscale_oncecontinues to scale. The growing gap is consistent with the legacy path hitting shared memory-bandwidth pressure: every rank repeatedly rotates and Fourier-transforms a full-resolution padded image, so additional ranks increase traffic to shared memory.downscale_onceremoves most of that full-resolution work and shows much less cross-rank contention. Hardware memory-bandwidth counters were not collected, so bandwidth saturation is an inference from the scaling behavior rather than a direct measurement.Peak memory grew approximately linearly with rank count and was nearly identical between backends: 20.73/20.38 GiB at two ranks, 31.01/30.41 GiB at three ranks, and 40.80/40.86 GiB at four ranks for legacy/
downscale_once. Every run completed the expected FOM and PSI maps with exit status 0, zero swap, and no memory-limit or OOM events. The legacy scaling loss is therefore not explained by exhausting the memory-capacity limit. Aggregate user and system CPU time was 59.86%, 64.85%, and 68.00% lower withdownscale_onceat two, three, and four ranks.It is worth to note that the reported 10x throughput improvement in #1351 requires a joint effort of 4 optimizations in place, including MPI proc scaling. Downscale-once only doesn't yield such result.