Skip to content

M14: stream-per-process concurrent inference - #25

Merged
ausimian merged 2 commits into
mainfrom
m14-stream-per-process
Apr 16, 2026
Merged

M14: stream-per-process concurrent inference#25
ausimian merged 2 commits into
mainfrom
m14-stream-per-process

Conversation

@ausimian

Copy link
Copy Markdown
Owner

Summary

  • Emily.Stream lets each BEAM process use its own Metal command queue for concurrent inference on a shared model — no weight duplication, no SIGSEGV
  • Stream index passed explicitly to every op NIF (correct by construction, no thread-local race). -1 sentinel preserves backwards compatibility
  • Soak tests updated to use per-process streams — all tiers pass, including --only soak which previously crashed from the Metal concurrency bug

Test plan

  • mix precommit — 370 tests, 0 failures
  • mix test --only soak — 8 tests, 0 failures (was crashing pre-M14)
  • mix test --only conformance — 17 tests, 0 failures
  • mix test --only fast_kernels_full — 5 tests, 0 failures
  • mix test --only qwen3_full — 2 tests, 0 failures
  • mix test --only vit_full --only whisper_full --only qwen3_quant_full — 6 tests, 0 failures

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.
@ausimian
ausimian merged commit f22c689 into main Apr 16, 2026
1 check passed
@ausimian
ausimian deleted the m14-stream-per-process branch April 16, 2026 11:46
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.

1 participant