Repository navigation
Conversation
With --stream-experts the text-only Qwen3.5 decoder layer evaluates and synchronizes the GPU before and after every MoE layer (about 80 syncs per token). Keep that for prefill, where it isolates the expert loads, but skip it when decoding one token: the VLM implementation of the same model never flushed. Measured on a 16 GB M2 with a 35B-A3B 4/5/8-bit checkpoint, ABAB, 3 reps per arm: decode 4.4 -> 5.4 tok/s (+22%); at an 8k-token prompt 4.8/4.0 -> 5.9/5.1. Generated text identical, no GPU timeouts, TTFT unchanged. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…t, fix comment Move the per-layer MoE flush decision into a pure static function so it can be unit tested without weights or a GPU. MLX_MOE_DECODE_FLUSH=1 restores the old flush on single-token decode, in case a heavily swapping setup needs it. The comment now describes the actual ordering invariant (SwitchGLU's per-layer router readback plus the token dependency chain) instead of the stale "VITAL" text. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
|
Thanks @CodeAndCanvas728, this is a clean, well-measured change. I went through the paths and also ran a differential test on a small synthetic Qwen3.5 MoE with To save you a round trip, I pushed one small follow-up commit on top of yours (a plain push, nothing rewritten): 44ae062
Please take a look and revert anything you don't like. Nice work. |
What
In
Qwen35DecoderLayer.callAsFunction, the "flush-load-execute" syncs (eval+Stream.gpu.synchronize()before and after each MoE layer, only with SSD expert streaming) now run only for prefill (x.dim(1) > 1). Single-token decode skips them. One condition, no other change.Why
With
--stream-expertsthe text-only (LLM) Qwen3.5 path syncs the GPU twice per MoE layer, about 80 hard syncs per decoded token on a 40-layer model. The VLM implementation of the same model has no such flush and streams fine. This is why a vision-capable checkpoint loaded with--no-vision(SwiftLM#206, needed for the prompt cache) decoded about 19% slower than the same weights loaded as a VLM.Measurements
Rig: 16 GB M2 Air, 35B-A3B hybrid MoE (30 GatedDeltaNet + 10 attention layers, 256 experts top-8, mixed 4/5/8-bit affine),
--stream-experts, greedy, 588-token code prompt, 100 new tokens,iogpu.wired_limit_mb=13500. Same binary for every arm (an env switch selected the behaviour), alternating order, 3 repetitions per arm, 3 requests each.At a ~8k-token prompt (
--prefill-size 2048): 5.9 and 5.1 tok/s against 4.8 and 4.0 before. Generated text was identical in every run, there were no GPU timeouts, and TTFT was unchanged (prefill still flushes).Not covered
Mistral4.swiftandSwitchLayers.swiftalso callsynchronize; I did not touch them.