Skip to content

onnx-infer: review fixes (AGBD footer, tract names, extraction retry, N-term sites, Unimod matching) - #145

Merged
ypriverol merged 7 commits into
exp/onnx-infer-ortfrom
onnx-infer/review-fixups-b
Oct 13, 2026
Merged

ypriverol merged 7 commits into
exp/onnx-infer-ortfrom
onnx-infer/review-fixups-b

Conversation

@ypriverol

Copy link
Copy Markdown
Contributor

Fixes the review findings on the onnx-infer stack (#132 → #142). Stacked on #142.

AGBD export reads the calibration footer. parse_agbd raised on every native blob because GbdtPeakModel::to_bytes always appends n_iso + iso_x/iso_y. The parser now reads that footer before rejecting extra bytes. The ONNX graph still exports the raw tree sum, the same value native predict_value returns. The sigmoid flag and the isotonic points go into the manifest extras (apply_sigmoid, iso_x, iso_y). The fixtures now carry a non-trivial footer, and the new tests/agbd_fixtures.rs decodes them with the native from_bytes and checks they re-serialise byte-for-byte.

tract output names. Names now come from outlet_label, not the producing node, so tract and ort agree. This was visible on real exports: DeepLC rt was reported as /Add_1 and PeptDeep rt_pred as /Squeeze. A test covers both backends and fails on the old code.

Extraction retry. ms2_extract_raw writes the part parquet only when every run succeeded. A task is marked done by complete: true in part-N.json, so a partial failure is redone when resubmitted. A pytest covers fail → resubmit → complete → skip.

N-terminal mods at site 0. The example encoders now parse peptides through RtPeptide::from_andes, so every model path uses one parser. pyro-Glu, and a lone TMT on a leading K, now sit at site 0, which matches training and alphabase. The position changes peptdeep output: N-terminal TMT RT moves from 0.507 to 0.580. The parity panel gained pyro-Gln, pyro-Glu and N-terminal TMT peptides.

Unimod mass matching. When resolving a mass delta, the closest mass now wins and the lowest id only breaks ties; this is done the same way in Rust and Python. Before, TMTpro resolved to iTRAQ8plex. Training never used mass matching, because ProForma is parsed by Unimod id, so the trained RT model is unaffected. Only inference on TMTpro PINs was affected.

Smaller items:

  • rescore_pin skips malformed PIN rows and spectra with a missing or duplicate scan number, reporting how many it skipped instead of panicking.
  • A non-finite RT prediction is written as missing.
  • The README quick start no longer pads the peptides.
  • The encode.rs comments now match the code.
  • RT calibration runs only for arms that use RT.
  • Few-shot training excludes the held-out PTM's other peptidoforms.
Feature set Tests (--all-targets) clippy -D warnings
none pass clean
tract pass clean
ort pass clean
Parity tract ort
PeptDeep (incl. pyro-Gln, pyro-Glu, N-terminal TMT) RT 1.2e-7, MS2 1.1e-5 RT 6.0e-8, MS2 1.1e-5
DeepLC encoding exact, RT rel 2.9e-5 encoding exact, RT rel 9.3e-6
MS²PIP features exact, log2 ≤ 1.2e-5 features exact, log2 ≤ 1.2e-5

…it and decode natively

parse_agbd reads the n_iso/iso_x/iso_y footer that GbdtPeakModel::to_bytes
writes and rejects only bytes after it. The ONNX graph stays the raw tree sum
(predict_value); the sigmoid flag and isotonic map go to the manifest extras.
make_local_fixtures writes the footer and now also builds tree_leq; the
committed .agbd fixtures are regenerated and a test decodes them with
scoring::gbdt_eval::GbdtPeakModel::from_bytes.
Names come from the outlet labels tract-onnx sets from the graph's tensor
names; the producing node's name is only the fallback. The intensity_mlp
fixture now names its nodes (/MatMul, /Add, /Relu) so tests on both backends
check that the output is reported as `score`.
The part parquet is written only when every run of the task succeeded; the
summary JSON's complete field is the done marker, a failed task removes any
stale part and exits 1, so resubmitting the array retries it.
…-terminal mods at site 0

parse_peptide builds the Form from RtPeptide::from_andes, so the PeptDeep,
DeepLC, Prosit, MS2PIP and andes-ms2 paths share the parser andes-rt and
andes-ms2 use. pyro-Glu and a lone TMT delta after a leading K now sit at
site 0, as in alphabase (Gln->pyro-Glu@Q^Any_N-term at site 0); before, they
went to residue 1, which changes PeptDeep's mod_x row. DeepLC keeps pyro-Glu
on residue 1, matching its reference panel. Masses are Unimod monoisotopic.
The PeptDeep reference panel gains pyro-Gln, pyro-Glu and N-terminal TMT
peptides with their andes spelling; model_parity checks the parsed names and
sites against peptdeep's.
TMTpro (+304.207145) resolved to iTRAQ8plex (+304.205359) because every entry
within 2 mDa competed on id alone. rt_native::mods::match_mass and
mod_composition.match_mass now pick the closest site-compatible mass; equal
masses (to 1e-6 Da) still go to the lowest id.
- rescore_pin: skip and count PIN lines that are blank, short or have a
  non-numeric ScanNr, spectra without a scan number and duplicate scans;
  a non-finite RT prediction is written as missing.
- README quick start packs the two 7-residue peptides at seq_len 7.
- peptdeep::encode comments: nothing reads extras.mod_hidden; lowercase
  residues are read as uppercase.
- rescore_pin_arms: RT calibration only for sources an arm uses as rt.
- rt_train: --fewshot-ptm drops that PTM's other peptidoforms from train/val.
@qodo-code-review

Copy link
Copy Markdown

ⓘ Qodo reviews are paused because the subscription is no longer active. Ask your workspace admin to reactivate the subscription to resume reviews. Manage billing

@coderabbitai

coderabbitai Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 53 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c82b2495-5595-4b37-8524-2aefc725c2ce
📥 Commits

Reviewing files that changed from the base of the PR and between 3ef75a3 and 64337f4.

📒 Files selected for processing: 17
  • crates/onnx-infer/MODELS.md
  • crates/onnx-infer/README.md
  • crates/onnx-infer/examples/common/models.rs
  • crates/onnx-infer/examples/model_parity.rs
  • crates/onnx-infer/examples/rescore_pin.rs
  • crates/onnx-infer/fixtures/intensity_mlp.onnx
  • crates/onnx-infer/scripts/export_agbd_to_onnx.py
  • crates/onnx-infer/scripts/make_local_fixtures.py
  • crates/onnx-infer/scripts/peptdeep_reference.py
  • crates/onnx-infer/scripts/student/mod_composition.py
  • crates/onnx-infer/scripts/student/ms2/ms2_extract_raw.py
  • crates/onnx-infer/scripts/student/ms2/slurm/extract_array.sh
  • crates/onnx-infer/scripts/student/ms2/test_ms2_extract.py
  • crates/onnx-infer/src/peptdeep/encode.rs
  • crates/onnx-infer/src/rt_native/mods.rs
  • crates/onnx-infer/tests/ort_backend.rs
  • crates/onnx-infer/tests/tract_intensity_mlp.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@ypriverol ypriverol left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review — tip of onnx-infer stack (primary fix target)

Good cleanup PR (AGBD footer, tract names, extract retry, N-term/Unimod). This tip is where remaining substrate bugs should be fixed before merging the stack toward main.

Still open at this tip (verified against onnx-infer/review-fixups-b)

Sev Location Finding
High src/rescoring/features.rs SPECTRUM_CORE_FEATURES Still tic_top_fraction / mz_intensity_weighted_std. quantms-rescoring uses fraction_tic_top_10 / weighted_std_mz (QUANTMS_FEATURES). Contract tests freeze the wrong names.
High ALPHAPEPTDEEP_CORE_FEATURES Still includes rt_diff / predicted_retention_time (DeepLC). Combining generators → duplicate PIN columns / unit confusion.
Medium RescoringBatch::from_rows Missing features → 0.0 (looks like perfect RT/MSE). Prefer hard error.
Medium TopNPolicy::filter_sorted_by_rank Does not read rank; interleaved spectra can admit >N.
Medium Cargo.lock time still 0.3.41 (RUSTSEC-2026-0009) via tract pin.
Low CI Clippy without --features tract,ort; no Python test_fixtures.py lane for TreeEnsemble.

PeptDeep AA/pads/scaling/dtype casts and run_one look fixed upstack — good.

LLM Fix Brief (copy-paste for implementing agent)

You are fixing remaining onnx-infer review items on bigbio/andes.
Checkout: onnx-infer/review-fixups-b (PR #145 tip). Open a branch onnx-infer/review-fixups-c from it.

MUST FIX:
1) crates/onnx-infer/src/rescoring/features.rs
   - SPECTRUM_CORE_FEATURES := ["snr","spectral_entropy","fraction_tic_top_10","weighted_std_mz"]
   - ALPHAPEPTDEEP_CORE_FEATURES := remove "rt_diff" and "predicted_retention_time" (MS2-only names)
   - Update crates/onnx-infer/tests/contracts.rs frozen lists to match
   - Grep repo for old names and update docs/examples

2) crates/onnx-infer/src/rescoring/psm.rs
   - RescoringBatch::from_rows: if feature missing → return Err(Error::InvalidArg(...)) not 0.0
   - Replace test batch_packs_missing_as_zero with batch_errors_on_missing_feature
   - TopNPolicy: add filter that groups by spectrum_ref and keeps lowest ranks; reject or sort unsorted input; add interleaved-spectrum test

3) Dependencies
   - Bump tract-onnx to a release that does not force time<0.3.42, OR document isolation; ensure Cargo.lock time >= 0.3.42
   - cargo test -p onnx-infer --features tract
   - cargo test -p onnx-infer --features ort (if available)
   - cargo clippy -p onnx-infer --all-targets --features tract -- -D warnings

4) CI (.github/workflows/ci.yml)
   - clippy step also with --features tract (and ort on ubuntu if feasible)
   - optional: python scripts/test_fixtures.py in onnx-infer with pip onnxruntime

DO NOT: reintroduce alphabetical AA table; do not remove L+2 pads or CHARGE_FACTOR/NCE_FACTOR; do not make ort default.

Acceptance:
- All onnx-infer tests green with tract (and ort if feature builds)
- rg confirms no tic_top_fraction / mz_intensity_weighted_std left
- time crate in Cargo.lock >= 0.3.42
Open PR against onnx-infer/review-fixups-b describing each fix.

@ypriverol
ypriverol added this pull request to stack #134 October 13, 2026 18:22
The stack fixed several of the same review findings. Where both sides fix
one finding, the stack's implementation is kept:

- AGBD footer: parse_agbd_full, the parity table, peak_gbdt_calibrated.agbd
  and tests/agbd_native.rs replace this branch's calibrated peak_gbdt.agbd
  and tests/agbd_fixtures.rs. The export manifest keeps apply_sigmoid,
  iso_x and iso_y in its extras.
- tract output names: the stack's outlet-label lookup; the intensity_mlp
  name tests for tract and ort are kept (the fixture keeps its named nodes).
- Unimod mass matching: the stack's closest-mass rule in Rust and Python;
  this branch's extra TMTpro/iTRAQ8plex, pyro-Glu and oxidation asserts are
  kept.
- RT calibration per arm and few-shot exclusion: the stack's versions.

The example parser stays on RtPeptide::from_andes (N-terminal mods at
site 0), which already decodes the summed N-terminal + residue delta through
split_nterm_residue_delta; the stack's andes-writer test is kept on it.
@ypriverol

Copy link
Copy Markdown
Contributor Author

Merged exp/onnx-infer-ort (3ef75a3) into this branch in 64337f4. Several findings were fixed on both sides; the stack's version is kept for those.

Superseded by the stack:

  • AGBD calibration footer: 43494f7 (parser) and f1e8560 (fixtures, parity/agbd.json, tests/agbd_native.rs). This branch's calibrated peak_gbdt.agbd and tests/agbd_fixtures.rs are dropped. The export manifest still records apply_sigmoid, iso_x and iso_y in extras.
  • tract output names: 892c191. The reports_onnx_tensor_names tests for tract and ort on intensity_mlp are kept, and the fixture keeps its named nodes.
  • Unimod closest-mass rule: 9459803, in both mods.rs and mod_composition.py. The extra asserts from this branch are kept (iTRAQ8plex on Y, pyro-Glu tie-break, oxidation).
  • RT calibration only for the arms that use RT: 6a9743c.
  • Few-shot exclusion of the held-out PTM: 2c0565d.

Unique to this PR, kept:

  • ms2_extract_raw completion marker and retry, with its test.
  • parse_peptide via RtPeptide::from_andes: pyro-Glu and N-terminal TMT at site 0. The summed N-terminal + residue delta from f674d69 is decoded through from_andes, and the stack's andes-writer test now runs against this parser.
  • PeptDeep parity panel with pyro-Gln, pyro-Glu and N-terminal TMT.
  • rescore_pin skips malformed rows and duplicate scans, and writes a non-finite RT as missing.
  • README, MODELS.md and encode.rs doc fixes.

@ypriverol
ypriverol merged commit f9517f3 into main Oct 13, 2026
5 checks passed
@ypriverol
ypriverol deleted the onnx-infer/review-fixups-b branch October 15, 2026 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant