---
name: local-model-serving
description: Select and run the right local LLM engine (MLX with speculative decoding vs llama.cpp) with the right settings for a task, and enforce the one-engine-at-a-time memory rule. Use whenever a task runs local inference against an OpenAI-compatible endpoint — evals, summarization, code review, content generation — or when choosing between local engines serving the same model.
title: local-model-serving
canonical_url: https://skilld.dev/gh/fiveonecode/agent-skills/local-model-serving
last_updated: 2026-09-28T14:37:59.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> If the user asked to install this Skill, run `npx skilld install fiveonecode/agent-skills/local-model-serving`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/local-model-serving`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/fiveonecode/agent-skills/local-model-serving) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/local-model-serving`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/local-model-serving --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/local-model-serving --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# Local Model Serving

Use this skill whenever a task needs local LLM inference on this machine.
It is engine- and model-generic: the measured numbers come from a
Qwen3.8-27B-class dense model (8-bit, ~28-30 GB resident) on a 128 GB
Apple Silicon Mac, but the decision rules and settings transfer to any
model served by the same two engine families.

## The Two Engine Families (same model, two backends)

| | MLX + speculative decoding (e.g. mlx-dspark) | llama.cpp (e.g. LM Studio) |
| --- | --- | --- |
| Model file | MLX 8-bit (e.g. `mlx-community/…-8bit`) + drafter | GGUF Q8_0 (e.g. `lmstudio-community/…-GGUF`) |
| Port | e.g. `http://127.0.0.1:8080/v1` | e.g. `http://127.0.0.1:1234/v1` |
| Context | model native (e.g. 262,144) | model native |
| Thinking-off knob | `"enable_thinking": false` | `"reasoning_effort": "none"` |
| Short-context decode | **~1.7-2.2× faster** (measured) | baseline |
| Long-context (100k+) | slower (spec-decode verify rounds double the huge-KV cost) | **~1.9× faster decode, ~linear prefill** |

Both are OpenAI-compatible (`/v1/chat/completions`), so the same client code
works against either — only the base URL and the thinking-off parameter
differ.

Drafters (DSpark, DFlash 2, and similar speculative-decoding heads) are
**modes of the MLX family**, not a third engine. Do not install NVIDIA-only
stacks (SGLang, vLLM) or a third MLX GUI to A/B a drafter. A better drafter
can raise short-context decode; it does not remove the long-context
crossover, because every verify round still walks the full KV. Use the
drafter the local serving policy or helper names. llama.cpp may be LM Studio
or `llama-server`; that is still the same family.

## First: The Memory Rule (crash prevention)

**Never run both engines with a model resident at the same time.** On a
128 GB machine, two resident 28 GB models plus the OS drove the system into
~20-46 GB of swap and crushed both engines' throughput (a long run was
aborted, another finished at half speed). The same exclusivity rule applies
on a 64 GB machine that can fit only one ~28 GB model. Each engine fits
alone; both do not.

- Stop the other engine before starting one:
  `lms unload <identifier>` / `lms unload all`, or
  `pkill -f "mlx-dspark serve"` (or the equivalent for your server).
- Wrap `start`/`stop` in a small helper that refuses the second engine
  unless it unloads the first — mechanical enforcement beats discipline.

## Decision Rule

| Prompt | Engine | Why |
| --- | --- | --- |
| Short (≤ ~100k tokens), decode-heavy | **MLX + spec decode** | 1.7-2.2× faster decode, same quality |
| Long (≥ ~100k tokens) | **llama.cpp** | faster decode, ~linear prefill scaling, better retrieval at depth |
| Code review of huge diffs | **llama.cpp** if local; prefer a cloud model for quality-critical | 100k+ contexts; local 27B-class models miss subtle defect classes |

Rule of thumb: **short in, long out → MLX spec-decode; long in → llama.cpp.**

## Settings (pinned, per engine)

- **Context:** use the model's native window (e.g. 262,144) unless the task
  explicitly needs less.
- **Thinking: pin it off** unless the task is reasoning-specific. Default
  thinking produces reasoning-only/truncated output in structured pipelines.
  The knob name differs per engine — using the wrong one silently does
  nothing, so verify with a smoke call.
- **Reproducible runs (evals):** temperature `0` (greedy), and compare runs
  only within one engine + quant — Q8_0 vs int8 and sampler differences
  shift scores.
- **Realistic generation (Qwen3.8 documented defaults):** temp `0.7`,
  top_p `0.80`, top_k `20`, presence_penalty `1.5`.

## Known Workload Mapping

| Task | Engine | Notes |
| --- | --- | --- |
| Eval / judge sweeps (many short prompts) | MLX spec-decode | pin the engine for the whole baseline |
| Summarization of short/mid text (strict JSON) | MLX spec-decode, re-verify the schema first | schema quirks differ per engine |
| Summarization of long documents (100k+) | llama.cpp | long-context winner |
| Code review of huge PRs | cloud (or llama.cpp if local) | token-hungry; local = minutes at best, hours worst-case |
| Content generation / filling objects | MLX spec-decode | decode-heavy short prompts — biggest win |

## Verify The Engine Is Actually Serving

Smoke-test before a batch run — confirm reachability **and** that thinking is
off (the wrong knob is the classic silent failure):

```bash
curl -s http://127.0.0.1:<port>/v1/chat/completions \
  -H 'Content-Type: application/json' \
  -d '{"model":"<model-id>","messages":[{"role":"user","content":"Say OK"}],
       "max_tokens":8,"<thinking-off-knob>":<value>}'
```

## Closeout

- **Unload when done** (`lms unload` / stop the server process) so memory
  returns for the other engine or other workloads on the same machine.
- If a run produced a new measurement or decision (quality delta, throughput,
  engine crossover), record it in your repository's knowledge base with the
  exact setup so it is reproducible — single-run anecdotes are signal, not
  proof.
