Skip to content

Cut ORT session memory: disable weight prepacking, free the session when idle - #81

Merged
sanylax0 merged 1 commit into
mainfrom
claude/repo-review-improvements-yvk3t7-oom-ort-session
Jul 18, 2026
Merged

sanylax0 merged 1 commit into
mainfrom
claude/repo-review-improvements-yvk3t7-oom-ort-session

Conversation

@sanylax2

Copy link
Copy Markdown
Collaborator

What

The device is still jetsamming at play time. Pressing play triggers just-in-time stem separation; the streaming pipeline (#61) already bounds the audio buffers to O(segment), so the remaining large allocation is the ONNX Runtime session for the 85M-param HT-Demucs transformer — loaded on top of live playback, the SwiftUI shell, and the decode path, and cached for the rest of the process once created.

How

Two independent cuts:

  1. session.disable_prepacking = 1 — ONNX Runtime "prepacks" weights into kernel-friendly layouts as additional copies of the originals; for a transformer this size that's hundreds of MB of duplicated RSS in exchange for a marginal speedup on an offline cache-once job.
  2. Release the cached session when the separation queue drains — OnnxStemSeparator.releaseSession() is called (from both the normal completion and the already-has-stems early-bail path) when stemsInFlight empties, returning the weights/arenas to the OS instead of holding them under playback forever. Back-to-back separations within one batch still share a single session load; only the next batch re-pays it.

Testing

Not buildable here (iOS-only module). On device: press play on a fresh (un-separated) track and watch the memory gauge in Xcode — the peak during separation should drop materially, and RSS should fall back down once the neighborhood's separations finish. If it still jetsams with this in, the next lever is capping protectedStemKeys's separation fan-out to 1 track ahead while playback is active — say the word and I'll follow up.

🤖 Generated with Claude Code

https://claude.ai/code/session_013TJoWkqg8bzkGdzxWhWjWP


Generated by Claude Code

…idle

Still jetsamming on device at play time: pressing play kicks off
just-in-time stem separation, and the HT-Demucs ORT session is the
remaining big allocation. Two cuts: (1) disable ONNX Runtime weight
prepacking, which duplicates packed copies of the 85M-param
transformer's weights for marginal CPU speedup; (2) release the cached
session when the separation queue drains, instead of holding hundreds
of MB under live playback for the rest of the process. Back-to-back
separations in one batch still share one session load.
@sanylax0
sanylax0 merged commit d1dee55 into main Jul 18, 2026
2 of 4 checks passed
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.

3 participants