Skip to content

fix: clamp --parallel to 1 with --stream-experts - #231

Merged
solderzzc merged 1 commit into
mainfrom
fix/stream-experts-parallel-clamp
Oct 12, 2026
Merged

solderzzc merged 1 commit into
mainfrom
fix/stream-experts-parallel-clamp

Conversation

@solderzzc

Copy link
Copy Markdown
Member

--parallel N>1 with --stream-experts corrupts the heap and garbles output.

Repro (OLMoE-1B-7B-0125-Instruct-4bit, 6 concurrent chat requests x 3 rounds, half streaming, temperature 0):

  • --parallel 3 --stream-experts: 12/18 requests failed, streamed text interleaved across requests, then the server crashed (EXC_BREAKPOINT inside libsystem_malloc freelist, called from rms_norm on the generation queue).
  • --parallel 3 without --stream-experts: 18/18 ok, server alive.

Cause: the SSD streaming fast path in SwitchGLU (mlx-swift-lm SwitchLayers.swift) keeps one persistent pread buffer set per layer (_persistentGate/_persistentUp/_persistentDown) plus last-token routing prediction state. Concurrent requests pread into the same buffers and mutate the same graph state. The design is single-request.

Fix: with --stream-experts, print a warning and force parallel = 1. Requests queue instead of running concurrently. Per-request buffers would be the real fix for concurrency, but that is a larger change.

Verified after the fix: same stress, 18/18 ok, server alive. No unit test: the clamp lives in run(), so the stress run is the check.

Needs the OLMoE tokenizer support from #230 to repro with that model; the clamp itself is independent.

🤖 Generated with Claude Code

SSD expert streaming keeps one persistent pread buffer set per layer; concurrent
requests overwrote each other's experts and corrupted the heap (OLMoE,
--parallel 3: 12/18 failures, garbled output, crash). Warn and use 1.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@solderzzc
solderzzc merged commit b077f39 into main Oct 12, 2026
15 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.

1 participant