Repository navigation
perf(sparsify): select mode='mass' entries on the device for ott outputs - #851
Merged
Merged
Conversation
Rows built on the device were copied to the host in [batch_size, m] blocks only to keep max_k entries per row. OTTOutput now selects with jax.lax.top_k on the device and copies [batch_size, max_k]; other outputs keep the numpy selection through the new _mass_select hook. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CEkHnYavwEf7n32j7rNkPv
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #851 +/- ##
==========================================
+ Coverage 76.58% 76.74% +0.15%
==========================================
Files 36 36
Lines 4224 4252 +28
Branches 678 679 +1
==========================================
+ Hits 3235 3263 +28
Misses 689 689
Partials 300 300
🚀 New features to boost your workflow:
|
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.
sparsify(mode="mass", max_k=...)copied every[batch_size, m]block of rows to the host to keep at mostmax_kentries per row. For ott outputs the rows are built on the device, so this selects there and copies only[batch_size, max_k]per block.BaseDiscreteSolverOutput._mass_selectis a new hook for themassrule; its default is the existing numpy selection.OTTOutputoverrides it when the rows are ajax.Arrayandmax_kis set, usingjax.lax.top_kover 256 rows at a time: onetop_kover a 2048 × 92,507 block needed several times the block's memory and ran 3x slower.Two Sinkhorn couplings from a single-cell time course,
value=0.95, max_k=100, batch_size=2048, RTX 4090:Same number of entries in both; 22 and 60 rows keep a tied entry at another column (values differ by < 1e-7). On CPU, one 2048 × 92,507 block takes 0.99 s with numpy and 0.68 s with jax.
🤖 Generated with Claude Code
https://claude.ai/code/session_01CEkHnYavwEf7n32j7rNkPv