Repository navigation
Cut ORT session memory: disable weight prepacking, free the session when idle - #81
Merged
sanylax0 merged 1 commit intoJul 18, 2026
Conversation
…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
approved these changes
Jul 18, 2026
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.
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:
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.OnnxStemSeparator.releaseSession()is called (from both the normal completion and the already-has-stems early-bail path) whenstemsInFlightempties, 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