M14: stream-per-process concurrent inference - #25
Merged
Conversation
Clients can bring their own pooling over N Nx.Serving instances; Emily doesn't need to own that abstraction. The stream-per-process path (Emily.Stream.with_stream/2) is the capability only the library can provide, so it becomes the primary M14 deliverable. Pooling is retained as a documented cookbook pattern.
Emily.Stream lets each BEAM process use its own Metal command queue for concurrent inference on a shared model. new/1 creates a stream, with_stream/2 scopes all ops in a block to that stream, and synchronize/1 waits for completion. The stream index is passed explicitly to every op NIF — no thread-local race. A -1 sentinel means "use default stream", keeping existing code paths unchanged. Soak-tested: 4+ concurrent workers, 50 iterations each, bit-identical outputs, no Metal assertion failures.
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.
Summary
Emily.Streamlets each BEAM process use its own Metal command queue for concurrent inference on a shared model — no weight duplication, no SIGSEGV-1sentinel preserves backwards compatibility--only soakwhich previously crashed from the Metal concurrency bugTest plan
mix precommit— 370 tests, 0 failuresmix test --only soak— 8 tests, 0 failures (was crashing pre-M14)mix test --only conformance— 17 tests, 0 failuresmix test --only fast_kernels_full— 5 tests, 0 failuresmix test --only qwen3_full— 2 tests, 0 failuresmix test --only vit_full --only whisper_full --only qwen3_quant_full— 6 tests, 0 failures