Repository navigation
fix: make CPU predictions thread-count invariant and floor nonnegative linear fallback - #139
Merged
RobbinBouwmeester merged 2 commits intoNov 29, 2026
Conversation
…e linear fallback Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LKxc9GKLwnyeV2jaZBxH9N
- Wrap both the parallel CPU path and the default path in the same save/restore block, so predict never leaves the caller's Torch thread setting changed. - Raise ValueError for a negative num_threads. - Document the CPU batch_size cap of 64 in predict and core.predict. - Changelog: note that CPU predictions differ slightly from 4.5.0 and that a larger batch_size is lowered on the parallel path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RobbinBouwmeester
approved these changes
Nov 29, 2026
Merged
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.
Summary
After PR #138 prevented small-reference spline/ridge blow-ups, two issues from #136 remain on
main(35025c3c):deeplc._model_ops.predict()callstorch.set_num_threads(num_threads), changing CPUConv1D/Linearfloating-point reduction order (~3e-8to1.2e-6in shared projections). The float32 per-head spline + ridge calibration amplifies that rounding perturbation across thread counts (up to5.27e-4 minon the 1,536-row bundled subset and0.01225 minon the full 5,430-row bundled example between 1 and 3 threads).F006544_PSMList.tsv(1,125 target PSMs, 15 distinct peptidoforms, head 6310),MultiHeadRidgeCalibration's< 200-peptidoform straight-line fallback extrapolates below zero (-3,098.15 s) even when every observed reference RT is nonnegative.Who hits this: proteomics users running DeepLC (directly or via MS²Rescore's
DeepLCFeatureGenerator) across machines with different CPU core/thread counts, or calibrating on small reference sets where the linear fallback extrapolates below 0 (#136).Changes
deeplc/_model_ops.py:DeepLCModel,FlexCNNMultitaskModel) with the standardDeepLCDatasetandnum_workers == 0, compute length buckets first (preserving original padding windows), subdivide into fixed batches of at most 64 peptides, run each batch withtorch.set_num_threads(1), and schedule independent batches across a boundedThreadPoolExecutor(max_workers=num_threads)(_ordered_cpu_batches)._CPU_PREDICTION_LOCK, propagate caller CPU autocast settings to worker threads, and always restoreprior_threadsin afinallyblock (including on exceptions).num_workers > 0calls on the existing path.deeplc/calibration/multihead.py:MultiHeadRidgeCalibration._fit_linear(), record_linear_floor = 0.0when all observed reference retention times are nonnegative (and-np.infotherwise), and applynp.maximum(..., self._linear_floor)intransform()for the straight-line fallback. Signed reference scales retain signed outputs.tests/test_thread_invariance.py&CHANGELOG.md:main, passing with this patch) covering thread invariance acrossnum_threads, thread-setting restoration, concurrent calls, and nonnegative vs signed linear-fallback bounds.Verification
num_threads in {1, 2, 3, 4, 8}, calibrated RT predictions have0.0max absolute difference on bothF006544_PSMList.tsvand the bundled example datasets (1,536-row subset and full 5,430-row file), match unpatchednum_threads=1(0.0diff on the 5,430-row file), and retain~3.1x–3.4xmulti-thread speedup at 4 threads vs 1 (note: ~10% slower than unpatched at 4 threads in local macOS arm64 benchmarks, ~7% faster at 1 thread).F006544_PSMList.tsv, the residual-3,098.15 sdecoy extrapolation is floored to0.0 s(0negatives), while signed reference scales, refits, pickling, andNaNpropagation are preserved.260 passedvs255onmain), along withruff check deeplc,ruff format --check deeplc, andmypy deeplc(0new diagnostics).Fixes #136
🤖 Generated with Claude Code
https://claude.ai/code/session_01LKxc9GKLwnyeV2jaZBxH9N