Speed up Augur predict - #1043
Merged
Merged
Conversation
Two results-preserving changes to Augur.predict: - run_cross_validation now passes the dense expression matrix to cross_validate instead of subsample.to_df(). The DataFrame's arrow-backed string column index forced scikit-learn to re-validate pandas dtypes on every fold and scorer, which dominated runtime for the many small models Augur fits (~14% per cross-validation in isolation). - predict fans all (cell_type, subsample) cross-validation tasks out through a single joblib pool instead of a per-cell-type pool inside a serial loop, so workers no longer idle at each cell-type boundary. Submission order is preserved and results regroup per cell type unchanged. The gain grows with the number of cell types (20-30% on the parallel portion in isolation). Signed-off-by: Lukas Heumos <lukas.heumos@posteo.net>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1043 +/- ##
==========================================
+ Coverage 77.99% 78.46% +0.46%
==========================================
Files 50 51 +1
Lines 6694 7039 +345
==========================================
+ Hits 5221 5523 +302
- Misses 1473 1516 +43
🚀 New features to boost your workflow:
|
Zethson
enabled auto-merge (squash)
July 13, 2026 21:38
Zethson
disabled auto-merge
July 13, 2026 21:38
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.
Speeds up
Augur.predictwith two results-preserving changes.Background
Profiling
predict()on the bundled dataset showed the time is dominated by scikit-learn per-call overhead across the many small models Augur fits (n_cell_types x n_subsamples x folds), not the random-forest math itself (tree building was ~1.2 s of ~42 s).Changes
NumPy instead of
subsample.to_df()inrun_cross_validation. The DataFrame carries an arrow-backed string column index, which forces scikit-learn to re-validate pandas dtypes and convert the column labels on every fold and every scorer. Passing the dense matrix (with gene names kept separately for the feature-importance table) avoids that. The values, and therefore the results, are identical. ~14% per cross-validation in isolation.Flattened parallelism.
predictnow fans every(cell_type, subsample)cross-validation task out through a single joblib pool instead of a per-cell-type pool inside a serial loop, so workers no longer idle at each cell-type boundary. Feature selection and eligibility checks still run serially first; submission order is preserved so results regroup per cell type unchanged. 20-30% on the parallel portion in isolation, growing with the number of cell types.A
threadingbackend was also evaluated and rejected (~3x slower, GIL-bound), so loky is kept.Results
Back-to-back on the bundled 3-cell-type dataset (best of 3):
The end-to-end gain is diluted here by serial fixed costs and only 3 cell types; datasets with more cell types benefit more from change 2.
Testing
pytest tests/tools/test_augur.py-> 9 passed (the exact-value AUC assertions confirm results are unchanged)