Fix Qwen3.5/3.6 SSD expert streaming after the upstream sync (crashes + full weight load) - #69
Merged
Merged
Conversation
Two regressions from the upstream sync (#62) broke --stream-experts on Qwen3.5/3.6 MoE: - The fork-only SSD block in SwitchGLU.projectExperts unsorted its output and still returned inverseOrder, so callers unsorted a second time. Prefill crashed with broadcast_shapes (N,8,8,D) vs (N,8,1). - Decode now runs through compiled traces, but SSD streaming evals mid-layer to load experts, which a trace cannot contain. Skip the compiled MoE block, decoder layer and decode segments while streaming. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The concurrent weight loader from the upstream sync evaluates every tensor, including the experts SSD streaming is meant to page in on demand. On a 32 GB Mac that held ~20 GB resident, grew swap, and cut Qwen3.6-35B-A3B SSD prefill from 315 to 77 tok/s. Keep the per-file lazy load while streaming. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Same failure as the Qwen3.5 decode path: fp16 Qwen3-Next runs SwitchGLU inside compiled decode segments, and the SSD streaming path evals there. Found by code reading (SwiftLM review session); not reproduced, since no fp16 Qwen3-Next checkpoint is on the test machine. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Proposed changes
--stream-experts(SSD expert streaming) on Qwen3.5/3.6 MoE broke with the upstream sync (#62, which reached SwiftLM through SharpAI/SwiftLM#167 and ships in release b769). It crashes on the first request. Three fixes:SwitchGLU.projectExpertsto return the sorted output plusinverseOrder, and callers now unsort it. The fork-only SSD block still unsorted in place and returnedinverseOrder, so callers unsorted a second time:Fatal error: [broadcast_shapes] Shapes (263,8,8,2048) and (263,8,1) cannot be broadcast.Fix: drop the in-place unsort, matching the other SSD early returns. Credit to the SwiftLM review session for spotting this.
decodeStepsegments). SSD streaming evals mid-layer to load experts:Fatal error: [eval] Attempting to eval an array during function transformations like compile or vmap is not allowed.Fix: skip those compiled paths while
ExpertStreamingConfig.shared.isEnabled. GPU mode is unchanged.loadWeightArrays) evaluates every tensor, including the experts that streaming is meant to page in on demand. On a 32 GB Mac that kept ~20 GB resident (server logGPU_MEM=19.9GB,MEM_DEMAND=37GB), grew swap, and cut prefill 4×. Fix: keep the old per-file lazy load while streaming. GPU mode keeps the concurrent loader.Qwen3Next gets the same guard on its compiled
decodeStepsegments, which it only uses for fp16 embeddings. It runsSwitchGLUthere too, so fp16 Qwen3-Next with--stream-expertswould hit the same eval-in-trace crash. This one comes from code reading by the SwiftLM review session and hasn't been reproduced: there's no fp16 Qwen3-Next checkpoint on the test machine.Verification (Mac mini M6, 32 GB,
unsloth/Qwen3.6-35B-A3B-UD-MLX-4bit, SwiftLMscripts/profiling/m6_bench.py, temperature 0, median of 3, needle check)Bisect: SwiftLM 5ae50ec (mlx-swift-lm 50d35c1) works. b769 (7cc37a0) crashes, and so do b769 with the mlx-swift #17 compile change reverted and b769 with SwiftLM ml-explore#189 bypassed.
On a fixed 611-token prompt at temperature 0, SSD output matches GPU output for the opening words, then diverges but stays coherent. SSD and GPU also diverge on 50d35c1 (different kernels), so bit-identity isn't the bar.
A small gap remains at short prompts (prefill −20% at 548 tokens, decode −4%). At 2.3K tokens it's within 3%. I haven't tracked the rest down.
No unit test is added: the SSD path needs real safetensors on disk plus
preadInto, which the unit suite doesn't have. The check above is end to end.Checklist
pre-commit run --all-filesto format my code / installed pre-commit prior to committing changesAI usage
accurately describes the code changes.
🤖 Generated with Claude Code