perf: predict each distinct peptidoform once - #128
Merged
Merged
Conversation
Identification output holds one PSM per match, so a peptidoform reappears for every scan, charge state and run that matched it. Each copy was parsed, encoded and pushed through the trunk again for a value that is identical by construction. `predict` now reduces the parsed PSM list to its distinct peptidoforms, predicts those, and scatters the answer back over the caller's rows, so the returned array still has one entry per PSM in the original order. On 8,000 peptides this is 6.4x faster at five copies per peptidoform and 21.9x at twenty; the two paths agree to 9e-05 min, which is float non-associativity from the differing batch layout rather than a change in the answer. Input that is already distinct takes the old path and pays only for building the keys. The charge state is deliberately not part of the key: it reaches no feature the model reads, and predictions for PEPTIDEK, PEPTIDEK/2 and PEPTIDEK/3 are bitwise equal. This matches `deduplicate_psms`, which already ignores charge when choosing calibration references. For `return_matrix`, the column is taken before the scatter so that what gets duplicated is one value per PSM rather than one row of every head. The factored matrix keeps its row-selection path, so a duplicated request still never builds the dense matrix. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
Identification output holds one PSM per match, so a peptidoform reappears for every scan, charge state and run that matched it. Each copy was parsed, encoded and pushed through the trunk again for a value that is identical by construction.
predictnow reduces the parsed PSM list to its distinct peptidoforms, predicts those, and scatters the answer back over the caller's rows. The returned array still holds one entry per PSM, in the caller's order.Measured
On 8,000 peptides, repeated to simulate real search output:
The two paths agree to 9e-05 min. That residual is float non-associativity from the differing batch layout, not a change in the answer. Input that is already distinct takes the old path and pays only for building the keys.
For context on where this lands:
core.predicton main currently runs at about 7,800 peptidoforms per second on CPU (16 threads) and 21,000 on an RTX 4090, measured on 50,000 distinct peptidoforms. Those are the worst case for this change, since nothing is repeated.Two decisions worth review
Charge state is deliberately not part of the key. It reaches no feature the model reads, and predictions for
PEPTIDEK,PEPTIDEK/2andPEPTIDEK/3are bitwise equal, so charge states of one peptidoform share a prediction. This matchesdeduplicate_psms, which already ignores charge when choosing calibration references.return_matrixtakes the column before the scatter, so what gets duplicated is one value per PSM rather than one row of every head. The factored matrix keeps its row-selection path, so a duplicated request still never builds the dense matrix. Verified directly: with duplicated input,return_matrix=Truereturns aFactoredPredictionMatrix, duplicate rows come back identical and distinct rows differ.Tests
Four added to
tests/test_core.py: repeated peptidoforms get one prediction repeated in place; the distinct path is undisturbed; charge states share a prediction;return_matrixkeeps one row per PSM in the caller's order. Full suite passes, 250 tests.🤖 Generated with Claude Code