Repository navigation
perf(loadtime): split big-MoE quantize + per-layer asyncEval - #216
Merged
Merged
Conversation
Two changes that prevent Metal's GPU command-buffer watchdog (~2s)
from killing model load + first-forward on very large MoE models.
**Load.swift — eval(model.parameters()) after quantize**
`quantize(model:)` walks the module tree and emits a fresh-quantize
op per Quantizable leaf. For DeepSeek-V4 (43 layers × 256 experts ×
{gate,up,down} SwitchLinear ≈ 33K modules) the lazy graph fuses
these into a single Metal command buffer that overruns the watchdog
at first-forward.
Splitting with one `eval(model.parameters())` after the quantize()
walk forces eager materialization of each module's quant op
separately. Cheap on small models (one cheap eval over a graph that
was about to evaluate anyway). Decisive on big MoE.
**DeepseekV4.swift — per-layer asyncEval during prefill**
Same watchdog symptom on the forward path. Per-layer asyncEval
splits the 43-layer graph at layer boundaries so the GPU pipeline
stays fed without any single command buffer exceeding the watchdog.
Mirrors the pattern already used in Qwen35TextModelInner and
NemotronHBackbone.
Owner
|
Nice catch on the watchdog timeout — the per-layer asyncEval extension to DeepseekV4 mirrors the existing Qwen35/NemotronH pattern cleanly, and the post-quantize |
4 tasks done
div0-space
pushed a commit
to LibraxisAI/mlx-swift-lm
that referenced
this pull request
Nov 29, 2026
Integrate an isolated non-serving model correction with its regression assertions. Preserve concurrent main changes and promote the resolved recording checks to ordinary assertions. No deployment or serving dependency update.
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
Two changes that prevent Metal's GPU command-buffer watchdog (~2s) from killing model load + first-forward on very large MoE models — surfaced while bringing up DeepSeek-V4-Flash (43 layers × 256 experts, 90 GB on disk).
`Load.swift` — `eval(model.parameters())` after `quantize(model:)`
`quantize(model:)` walks the module tree and emits a fresh-quantize op per `Quantizable` leaf. For DeepSeek-V4 (43 layers × 256 experts × {gate,up,down} SwitchLinear ≈ 33K modules) the lazy graph fuses these into a single Metal command buffer that overruns the watchdog at first forward.
Splitting with one `eval(model.parameters())` after the `quantize()` walk forces eager materialization of each module's quant op separately. Cheap on small models (one eval over a graph that was about to evaluate anyway). Decisive on big MoE.
`DeepseekV4.swift` — per-layer `asyncEval` during prefill
Same watchdog symptom on the forward path. Per-layer `asyncEval` splits the 43-layer graph at layer boundaries so the GPU pipeline stays fed without any single command buffer exceeding the watchdog. Mirrors the pattern already in `Qwen35TextModelInner` and `NemotronHBackbone`.
Test plan
Notes
Both changes are defensive: they take a code path that was already used for Qwen35/NemotronH on the forward and extend it to the load + DeepseekV4 forward.
🤖 Generated with Claude Code