Skip to content

feat(#33): /v1/models/preview, wired limit by default, mlx-swift 0.33, watchdog for long prefills - #276

Merged
goodmai merged 1 commit into
mainfrom
feat/33-preview-wired
Nov 4, 2026
Merged

goodmai merged 1 commit into
mainfrom
feat/33-preview-wired

Conversation

@goodmai

@goodmai goodmai commented Nov 4, 2026 •

Copy link
Copy Markdown
Owner

Part of #33 (part 1; block-sparse attention follows separately).

What

  • GET /v1/models/preview?model_id=&context= reports what loading a model would cost without loading weights: weights, KV per 1k tokens, required/available bytes, fits, fit_level, max context/prompt tokens, warning and recommendation (from MemoryEvaluator).
  • serve and PerformanceBenchmark hold a WiredMemoryTicket of Metal's recommended working set while a model is loaded and release it on unload. MLX renews residency every second (MLX_METAL_RESIDENCY_REFRESH_INTERVAL_MS=1000). --no-wired-limit leaves the system default.
  • mlx-swift 0.33.0 (MLX 0.32.4) through goodmai/mlx-swift-lm@cdfc249, which drops CompiledTrace's shadowing compile overloads, as upstream did.
  • The generation watchdog budgets prefill at 50 tok/s instead of 200. Before this, a 64k prompt on Gemma 4 12B was killed at 300 s.
  • basalt-model-runs skill: every model table includes Gemma 4 of at least 12B.

Why the limit is on by default now

Before MLX 0.32.4, a residency set lost residency after about 2 s of GPU idle (ml-explore/mlx#4609). On that MLX the limit made things worse without memory pressure. The fix is ml-explore/mlx#4633. It works only when the refresh env var is set before the first Metal allocation, so run() sets it first. With the fix, the limit does no harm without pressure and cuts swap by 41% under pressure.

A feedback controller in MemoryCoordinator was considered and skipped. The measurements show one good setting (the full working set) and no case where a smaller limit would win.

Measurements

24 GB Mac, release build, T=0, gemma-4-26B-A4B-it-qat-4bit unless noted. "Ballast" is a competing process holding that much RAM.

MLX 0.32.4 (this PR)

Prompt Ballast Mode pageouts swapouts decode tok/s wall time
~4k, 512 out 4 GB system default — 390,940 52.58 —
~4k, 512 out 4 GB wired — 229,512 (−41%) 52.66 —
~4k, 512 out none system default 13 0 52.73 —
~4k, 512 out none wired 9 0 52.72 —
64k, 16 out none system default 31 0 — 4 m 38 s
64k, 16 out none wired 19 0 — 4 m 38 s

Older MLX, for the record

Model Prompt Ballast Wired vs system default
gemma-4-26B-A4B ~4k 4 GB −24% swapouts, +4% speed
Qwen3.8-27B-3bit ~4k 8 GB −20% swapouts
gemma-4-12B — none pageouts 432 vs 32, 17.3 vs 18.5 tok/s
gemma-4-26B-A4B 64k none 75,360 vs 0 swapouts

Notes:

  • Qwen3.8-27B at 59k was refused by admission (max 53,329 tokens), as expected.
  • The TTFT that PerformanceBenchmark reports on the 64k runs (~0.1 s) leaves out prefill. That bug is filed separately; wall time is shown here instead.
  • Raw outputs (local): pressure033-*, nopress033-*, wired033-* in the session scratchpad.

Checks

  • swift build -Xswiftc -warnings-as-errors passes.
  • scripts/check_no_new_comments.py passes.
  • swift test --parallel passes: 1237/1237.
  • HuihuiAndEx0bitModelTests "registers type aliases" failed once under parallel load and passed on rerun. It is unrelated to this change.

🤖 Generated with Claude Code

https://claude.ai/code/session_012cicgudpVmSKaQgaioocQ1

…, a watchdog that lets long prefills finish

- GET /v1/models/preview?model_id=&context= answers what loading a model
  would cost (weights, KV per 1k tokens, required and available bytes,
  fit, token budgets) from MemoryEvaluator, without loading weights.
- serve and PerformanceBenchmark hold a WiredMemoryTicket of Metal's
  recommended working set while a model is loaded and release it on
  unload, with MLX renewing residency every second
  (MLX_METAL_RESIDENCY_REFRESH_INTERVAL_MS, ml-explore/mlx#4633).
  --no-wired-limit leaves the system default. On Gemma 4 26B-A4B it cut
  swap by 41% under competing memory pressure and changed nothing
  without it.
- mlx-swift 0.33.0 (MLX 0.32.4) via goodmai/mlx-swift-lm@cdfc249, which
  drops CompiledTrace's shadowing compile overloads like upstream.
- The generation watchdog budgets prefill at 50 tok/s instead of 200, so a
  64k prompt on Gemma 4 12B is no longer killed at 300 s.
- basalt-model-runs: every model table includes Gemma 4 of at least 12B.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012cicgudpVmSKaQgaioocQ1
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