Skip to content

macos: serve on the Apple Silicon GPU through vllm-metal - #43

Merged
DevelopmentCats merged 4 commits into
mainfrom
bpmct/macos-vllm-metal
Nov 2, 2026
Merged

DevelopmentCats merged 4 commits into
mainfrom
bpmct/macos-vllm-metal

Conversation

@bpmct

@bpmct bpmct commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

closes #44

vllm-helper on a Mac assumed vLLM's CPU backend. This makes it serve on the Apple Silicon GPU through vllm-metal (vLLM + MLX), so a Mac Studio works about as well as a DGX Spark does. The CPU backend still works if vllm-metal isn't installed.

What changes

  • Detection. vllm-helper asks the python beside VLLM_BIN if vllm_metal is importable, and reads the Metal working set from MLX. setup and doctor say which backend is in use.
  • Memory. Under vllm-metal, --gpu-memory-utilization is a share of the Metal working set, not RAM. New profiles default to 0.9. The budget and KV plan use the working set. The CPU backend's free-RAM clamp is skipped, since vllm-metal sizes its own cache.
  • Setup. Finds the Homebrew and install-script vllm even when it is not on PATH. A Cellar path is saved as the stable opt path, so brew upgrade does not break VLLM_BIN. The python lookup follows the symlink, so it finds the formula's python and not Homebrew's.
  • Headless Macs. A LaunchAgent needs a GUI login, so over SSH it fails with launchd error 125. That error now explains itself. SERVICE_SCOPE=system installs a LaunchDaemon. It now runs as the installing user (it used to run as root and read root's config and cache), starts at boot, and status reads it without sudo.
  • metal-limit. macOS lets the GPU wire only part of RAM (239 of 256 GiB here). vllm-helper metal-limit --set auto raises iogpu.wired_limit_mb to RAM minus 16 GiB. It also installs a boot daemon to reapply it, because the sysctl resets on reboot. start waits up to 60s for the limit before it starts vLLM. doctor shows the limit and suggests a raise.
  • Doctor. Skips the source-build toolchain under vllm-metal, which ships prebuilt wheels.
  • Docs (docs/macos.md rewritten), CHANGELOG and the CLI reference are updated.

Tested on the Mac Studio

M5 Ultra, 256 GB, macOS 27, vllm-metal 0.32.0 from Homebrew, system-scope LaunchDaemon:

  • setup found /opt/homebrew/opt/vllm-metal/libexec/bin/vllm and reported a 239 GB working set and a ~194 GB budget.
  • vllm-helper new mlx-community/Qwen3-Coder-30B-A3B-Instruct-8bit: served on the GPU (MLX device set to: Device(gpu, 0)), ~85 tok/s single stream. Tool calls work with --tool-call-parser qwen3_coder.
  • metal-limit --set auto raised the working set to 240 GiB. After a reboot with nobody logged in, the limit came back and the server came back healthy.
  • go test ./... passes natively on the Mac. go test -race ./..., both go vets, gofmt and prettier pass on Linux.
  • Since 2026-10-30 the Mac runs a build of providers: serve with vLLM, mlx-lm or llama.cpp, and rename to llm-helper #46 instead, to serve DeepSeek through llama.cpp (below). This branch's build is kept beside it as ~/bin/vllm-helper.pr43. The Qwen profile still serves through vllm-metal from that build, and llm-helper switch between Qwen and DeepSeek took about 20 s each way.

DeepSeek V4 Flash does not run on vllm-metal

I tried this first, since the Spark pair runs it. It is blocked upstream, not by vllm-helper:

  • Stock mlx-lm 0.32 has no deepseek_v4. The model file is in the open Add DeepSeek-V4-Flash without MTP (yet) ml-explore/mlx-lm#1797, which has conflicts.
  • With that file dropped into the venv, mlx-community/DeepSeek-V4-Flash-4bit (151 GB) loads. But the first request fails in vllm-metal's paged attention ('OffsetCache' object has no attribute 'update_and_fetch'). vllm-metal does not handle V4's compressed sparse attention.

So I left it out of vllm-helper. A model-specific patch does not belong here. The docs list it as an example of a model vllm-metal must support first, and now also say that llama.cpp runs it.

It does run on the same Mac through llama.cpp, with #46's llama.cpp provider and no code changes there: unsloth/DeepSeek-V4-Flash-Vision-Exp-GGUF:UD-Q8_K_XL plus its vision file, about 33 tok/s writing and 825 tok/s reading prompts, 161.8 of 240 GiB of GPU memory.

Known issues

  • The API key is on the command line. The vLLM provider passes --api-key <key> to vllm serve, so ps shows the key to every user on the machine. This is how main works today, and this PR doesn't change it. vLLM also reads VLLM_API_KEY from its environment, which start already sets, so the fix looks small. providers: serve with vLLM, mlx-lm or llama.cpp, and rename to llm-helper #46 fixes the same leak for llama.cpp.
  • Qwen3-Coder and several system messages. Its chat template puts only the first system message at the top, and Coder Agents sends five. The rest land just before the user's message, and in a test chat on dogfood the model read them as things the user said and called tools nobody asked for. The docs now say to join them first. Solstice does this today in its router (MERGE_SYSTEM_MODELS_JSON). That is live but not yet approved by @bpmct, and it is not part of this PR.
Decision log
  • Backend is a property of the installed vLLM, not the Mac. Detection probes the configured VLLM_BIN lazily, once per process, and only on darwin. On Linux nothing changes. The Spark budget and plan numbers are the same as before.
  • Two probes. "Is vllm_metal installed" is a cheap find_spec used on every start. The working set imports MLX, and only budget, plan, doctor and metal-limit use it. This way a slow MLX import at boot cannot silently send start into the CPU clamp.
  • 0.9, not vllm-metal's 0.92. This leaves room for vllm-metal's KV commit probe and other processes. An explicit profile value is never capped.
  • No auto-raise of the wired limit. It takes headroom from macOS, so it is opt-in, needs sudo, and asks first. Suggested headroom is 16 GiB (8 GiB under 128 GiB of RAM), the common advice for dedicated LLM Macs.
  • System scope is opt-in. User scope stays the default for desktops. The bootstrap error points headless users at SERVICE_SCOPE=system.
  • Not done: MLX quant names in hf variant labels, and hiding CUDA-only flags from model cards on Metal. Neither blocked an MLX checkpoint in testing.

Generated by Coder Agents on behalf of @bpmct.

vllm-helper assumed a Mac runs vLLM's CPU backend. With the vllm-metal
plugin installed beside VLLM_BIN it now treats the Mac as a GPU box:

- detect vllm_metal and read the Metal working set from MLX
- size the budget, KV plan and the 0.9 profile default against the
  working set, and skip the CPU backend's free-RAM clamp
- find the Homebrew and install-script vllm in setup, keep the stable
  opt path, and follow the symlink to the right python
- run system-scope LaunchDaemons as the installing user, so a headless
  Mac serves at boot without a login session
- add 'metal-limit' to raise iogpu.wired_limit_mb and reapply it at boot

Tested on an M5 Ultra Mac Studio (256 GB, macOS 27, vllm-metal 0.32.0).

Coder Agents generated.
Copilot AI balanced review requested due to automatic review settings October 30, 2026 18:03

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved defects affect Metal memory sizing and reporting, service-scope selection, executable recovery, legacy-daemon migration, and persistence of manually raised wired-memory limits.

7 open issues
What changed in this PR

Adds Apple Silicon GPU serving through vllm-metal to vllm-helper’s existing profile and service management, while preserving the macOS CPU fallback.

Changes:

  • Detects vllm-metal and uses its Metal working set for memory budgets and profile defaults.
  • Improves Homebrew discovery and headless LaunchDaemon support.
  • Adds persistent GPU wired-memory limits, diagnostics, tests, and documentation.
File Description
README.md Advertises Apple Silicon GPU support.
internal/​vllm/​metal.go Probes plugin availability and Metal memory.
internal/​vllm/​metal_internal_test.go Tests probe parsing and interpreter discovery.
internal/​vllm/​capabilities.go Resolves Python beside symlinked vLLM executables.
internal/​service/​service_darwin.go Adds daemon identity settings and headless diagnostics.
internal/​service/​service_darwin_internal_test.go Tests daemon user and home settings.
internal/​profile/​profile.go Selects Metal-specific memory defaults.
internal/​profile/​profile_test.go Tests Metal profile defaults.
internal/​detect/​process_darwin.go Detects system-domain launchd services.
internal/​detect/​procargs_darwin_internal_test.go Tests system-service label parsing.
internal/​detect/​plan.go Plans cache memory against the Metal working set.
internal/​detect/​metal.go Registers and caches lazy backend probes.
internal/​detect/​metal_internal_test.go Tests Metal budgeting, planning, and probe isolation.
internal/​detect/​hardware.go Exposes Metal backend and memory-pool information.
internal/​detect/​budget.go Adds Metal-specific model budgeting.
internal/​control/​gguf.go Reuses shared interpreter discovery.
internal/​cli/​vllmbin.go Discovers vLLM and preserves stable Homebrew paths.
internal/​cli/​vllmbin_other.go Supplies non-macOS discovery behavior.
internal/​cli/​vllmbin_internal_test.go Tests executable-path normalization.
internal/​cli/​vllmbin_darwin.go Adds macOS install locations and hints.
internal/​cli/​toolchain_darwin.go Skips source-build checks under Metal.
internal/​cli/​start.go Waits for the configured wired-memory limit.
internal/​cli/​setup.go Detects the backend before sizing memory.
internal/​cli/​root.go Registers backend probes and metal-limit.
internal/​cli/​root_internal_test.go Updates the expected command set.
internal/​cli/​metallimit.go Defines limit validation, reporting, and polling.
internal/​cli/​metallimit_other.go Rejects limit changes outside macOS.
internal/​cli/​metallimit_other_internal_test.go Tests the platform restriction.
internal/​cli/​metallimit_internal_test.go Tests limits, reports, plist output, and waiting.
internal/​cli/​metallimit_darwin.go Applies and persists macOS wired-memory limits.
internal/​cli/​metal_other.go Leaves backend registration inactive outside macOS.
internal/​cli/​metal_darwin.go Connects configured vLLM to Metal probes.
internal/​cli/​memfit_darwin.go Bypasses CPU memory clamping under Metal.
internal/​cli/​memfit_darwin_internal_test.go Tests preservation of Metal memory settings.
internal/​cli/​detectcmds.go Displays backend and wired-limit diagnostics.
docs/​troubleshooting.md Explains Metal memory behavior and service logs.
docs/​reference/​cli/​metal-limit.md Documents the new command.
docs/​reference/​cli.md Adds metal-limit to the command index.
docs/​README.md Updates the supported-platform overview.
docs/​profiles.md Documents backend-specific memory defaults.
docs/​manifest.json Updates macOS and command navigation.
docs/​macos.md Covers GPU installation, headless serving, and memory limits.
docs/​install.md Documents Metal installation and configuration.
CHANGELOG.md Records GPU support and macOS service fixes.

Review effort: Balanced

Comment thread internal/cli/metallimit_darwin.go Resolved
Comment thread internal/cli/root.go Resolved
Comment thread internal/cli/vllmbin_darwin.go Resolved
Comment thread internal/detect/hardware.go Resolved
Comment thread internal/detect/plan.go Resolved
Comment thread internal/detect/process_darwin.go Resolved
Comment thread internal/service/service_darwin.go Resolved
- metal-limit --set auto persists a live cap that is already high
  enough when config.env or the boot-time daemon does not carry it
- start registers the vllm-metal probe for the VLLM_BIN it execs, which
  a profile can override, not config.env's
- setup fills in an empty VLLM_BIN on a rerun once a vllm is found
- the web panel shows Metal usage as not measured instead of host RAM
  against the smaller working set
- the metal probe reads whether vllm-metal honors
  --kv-cache-memory-bytes (0.32.0 ignores it); without it the plan
  leaves the KV cache to vllm-metal and says so
- adopt compares the scope as well as the name of the unit it finds
- docs: how to replace a LaunchDaemon that an older release installed
  as root, and which vllm-metal builds honor KV_CACHE_MEMORY_BYTES

Coder Agents generated.
bpmct and others added 2 commits October 31, 2026 23:08
Brings in the providers seam and the llm-helper rename (#46) and AGENTS.md
(#49). Resolutions:

- setup: lookBin finds vLLM through findVLLM, so the Homebrew opt path and
  the install-script venv are kept; lookVLLM is gone. The Metal probe and
  vllmInstallHint apply only to the vllm provider, and fillMissingVLLMBin
  leaves a config whose PROVIDER names another server alone.
- start: only a vllm profile's binary is probed for vllm-metal, so
  mlx_lm.server and llama-server are never asked; awaitWiredLimit still
  runs for every provider, since the wired limit is the GPU's.
- doctor: the backend line, with its install-vllm-metal hint, shows only
  when new profiles use vLLM.
- root: keeps the Metal probe pre-run, with main's cmdName version template.
- docs: #43's text under the llm-helper name, with main's provider rows and
  entries kept; CLI reference and manifest regenerated.
@DevelopmentCats
DevelopmentCats merged commit 272b931 into main Nov 2, 2026
4 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.

serve on the Apple Silicon GPU (vllm-metal) on macOS

3 participants