Skip to content

perf: predict each distinct peptidoform once - #128

Merged
RobbinBouwmeester merged 1 commit into
mainfrom
perf/deduplicate-prediction-input
Sep 22, 2026
Merged

RobbinBouwmeester merged 1 commit into
mainfrom
perf/deduplicate-prediction-input

Conversation

@RobbinBouwmeester

Copy link
Copy Markdown
Member

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. 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:

copies per peptidoform speedup
5 6.4x
20 21.9x

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.predict on 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/2 and PEPTIDEK/3 are bitwise equal, so charge states of one peptidoform share a prediction. This matches deduplicate_psms, which already ignores charge when choosing calibration references.

return_matrix takes 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=True returns a FactoredPredictionMatrix, 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_matrix keeps one row per PSM in the caller's order. Full suite passes, 250 tests.

🤖 Generated with Claude Code

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>
@RobbinBouwmeester
RobbinBouwmeester merged commit 5ba315d into main Sep 22, 2026
5 checks passed
@RobbinBouwmeester
RobbinBouwmeester deleted the perf/deduplicate-prediction-input branch September 22, 2026 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant