JOURNAL

Local LLMs on a Mac with MLX: on-demand loading, quantization, LoRA and an API

A hands-on guide to local LLMs on Apple Silicon with MLX: install with uv, raise the GPU memory limit, load models on demand and release them when idle, convert and quantize, LoRA fine-tune from 45% to 100%, serve an OpenAI-compatible API. Measured on an M1 Ultra, sized for an M1 Max 64 GB.

Local LLMs on a Mac with MLX

Read with AI

Choose content to copy and paste into your AI assistant. Nothing is sent automatically. CMS content is converted to Markdown; original Markdown is used when available.

I wanted a local LLM setup on my Macs that I can leave alone: nothing sits in memory while I’m not using it, the first request loads the model, and when I go quiet the memory comes back. On top of that I wanted to do more than chat: convert a model myself, fine-tune it on my own data, and serve it as an API that other tools can call.

This post is the full walkthrough. Every command was run on a Mac Studio with an M1 Ultra and 128 GB of memory, and every number in it comes from a log you can read in the sample repo. I also give a configuration for an M1 Max with 64 GB and a 1 TB SSD, because that is the machine most people I know actually have. I did not have that machine on hand while writing, so its numbers are estimates and labelled as such.

Sample repo: github.com/luonghongthuan/mlx-local-lab. Clone it if you want to follow along; the scripts quoted below are the same files.

What you will have at the end

  • mlx-lm installed cleanly with uv, on Python 3.12, without touching the system Python.
  • The GPU memory limit raised so larger models fit, and kept after a reboot.
  • A model that loads when the first request arrives and unloads after a few idle minutes, so idle RAM use is close to zero.
  • A Hugging Face model you converted and quantized yourself.
  • A LoRA adapter trained on a small dataset, with a before/after accuracy number.
  • An OpenAI-compatible endpoint on localhost that any client can call.

Here are the measured results up front, so you know what to expect:

Test (M1 Ultra, 128 GB)Result
MLX, Qwen3-8B 4-bit, 2048 prompt / 256 generated tokens763 tok/s prompt, 91.2 tok/s generation, 5.6 GB peak
Ollama, qwen3:8b q4_K_M, 1667 prompt / 256 generated~760 tok/s prompt, ~63 tok/s generation, 4.9 s first load
Ollama with keep_alive 10 s8.2 GB loaded right after the call, nothing loaded 20 s later
Convert Qwen/Qwen3-0.6B to 4-bit41 s including the download, 331 MB on disk
LoRA on Qwen3-1.7B 4-bit, 300 iterations93 s of training, exact match 45% → 100% on 22 held-out tickets

How the pieces fit

There are three tools people mix up, so it helps to place them first.

  • MLX is Apple’s array framework for Apple Silicon. mlx-lm is the package on top of it that loads, generates, converts, fine-tunes and serves language models. It is the fastest way I have found to run a model on a Mac, and it is the only one of the three where training is a first-class feature.
  • Ollama runs GGUF models through llama.cpp. It is the easiest to run as a background service and it already knows how to unload a model when idle.
  • LM Studio is a desktop app (with a headless mode) that runs both GGUF and MLX models behind an OpenAI-compatible server, and it can load models just in time and unload them after a TTL.

My split is simple: build and fine-tune with mlx-lm, serve day to day through something that loads on demand.

Pipeline from a Hugging Face model to an MLX model, LoRA adapter and a local API
The whole pipeline: convert, test, fine-tune, then serve on demand.

Step 1: Install mlx-lm with uv

You need an Apple Silicon Mac (M1 or later), the Xcode Command Line Tools (xcode-select --install) and Homebrew. Everything else comes from the setup script.

scripts/setup-mlx.sh

#!/usr/bin/env bash
set -euo pipefail
[ "$(uname -m)" = "arm64" ] || { echo "Apple Silicon (arm64) required" >&2; exit 1; }
command -v brew >/dev/null || { echo "Install Homebrew first: https://brew.sh" >&2; exit 1; }
command -v uv >/dev/null || brew install uv
command -v git-lfs >/dev/null || brew install git-lfs
for tool in mlx-lm mlx-whisper huggingface_hub; do
  uv tool install --python 3.12 "$tool" || uv tool upgrade "$tool"
done
LAB="${MLX_LAB:-$HOME/ai/mlx-lab}"
mkdir -p "$LAB" "$HOME/ai/models"
cd "$LAB"
[ -f pyproject.toml ] || uv init --python 3.12 --no-readme --quiet
uv add --quiet mlx mlx-lm mlx-vlm datasets
uv run python -c "import mlx.core as mx; print('mlx', mx.__version__, mx.default_device())"
ram_gb=$(( $(sysctl -n hw.memsize) / 1073741824 ))
suggest=$(( (ram_gb - (ram_gb >= 96 ? 16 : 8)) * 1024 ))
echo "RAM ${ram_gb} GB; current iogpu.wired_limit_mb=$(sysctl -n iogpu.wired_limit_mb)"
echo "Suggested: sudo sysctl iogpu.wired_limit_mb=${suggest}"
echo "Next: mlx_lm.generate --model mlx-community/Qwen3-1.7B-4bit --prompt hello --max-tokens 50"

Two choices in there are deliberate.

  • uv tool install puts each CLI in its own environment and links the commands into ~/.local/bin. You get mlx_lm.generate, mlx_lm.chat, mlx_lm.convert, mlx_lm.lora, mlx_lm.fuse, mlx_lm.server, mlx_lm.benchmark, mlx_whisper and hf (the Hugging Face CLI, which used to be called huggingface-cli).
  • Python 3.12, not the newest release. Wheels for brand-new Python versions often arrive late, and a missing wheel turns a one-minute install into a compile.

The script also creates a small uv project in ~/ai/mlx-lab for your own Python code. When you write scripts that import mlx_lm, run them with uv run inside that project, never with the global python3.

Check: the script prints a line like mlx 0.32.5 Device(gpu, 0). If it says Device(cpu) or the whole thing is very slow, your Python is running under Rosetta: file $(uv python find 3.12) must say arm64.

Step 2: Let the GPU use more of the memory

Apple Silicon has unified memory, but macOS only lets the GPU wire about 75% of it by default. On a 64 GB machine that is about 48 GB, which is the real ceiling for model plus context. You can raise it with one sysctl. Keep 8 GB for macOS on smaller machines and 16 GB on the big ones; the setup script prints a suggestion for your RAM.

MachineDefault (approx.)Suggested iogpu.wired_limit_mb
M1 Ultra, 128 GB~96 GB114688 (112 GB)
M1 Max, 64 GB~48 GB57344 (56 GB)
32 GB Mac~24 GB26624 (26 GB)
sudo sysctl iogpu.wired_limit_mb=57344

That lasts until the next reboot. To keep it, install a LaunchDaemon. The value in the repo is for a 64 GB Mac; change it before copying if yours is different.

launchd/com.local.iogpu-wired-limit.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key><string>com.local.iogpu-wired-limit</string>
  <key>ProgramArguments</key>
  <array><string>/usr/sbin/sysctl</string><string>iogpu.wired_limit_mb=57344</string></array>
  <key>RunAtLoad</key><true/>
</dict>
</plist>
sudo cp launchd/com.local.iogpu-wired-limit.plist /Library/LaunchDaemons/
sudo launchctl bootstrap system /Library/LaunchDaemons/com.local.iogpu-wired-limit.plist

To undo it: sudo launchctl bootout system/com.local.iogpu-wired-limit, delete the file, and sudo sysctl iogpu.wired_limit_mb=0 to go back to the default.

Check: sysctl iogpu.wired_limit_mb prints your value, also after a reboot.

Step 3: Decide where models live

Models are big, and the easiest way to fill a 1 TB disk is to download the same model three times into three project folders. Keep one cache per machine. By default it is ~/.cache/huggingface/hub; if you want it on an external SSD, set it once in ~/.zshrc:

export HF_HOME=/Volumes/Data/hf

Gated models (Llama, Gemma and a few others) need a free Hugging Face account and a read token: run hf auth login and accept the licence on the model page. The token is stored in the cache folder; don’t paste it anywhere else.

Housekeeping commands you will use more than you expect:

hf cache list
hf cache rm mlx-community/Qwen3-8B-4bit
hf cache prune

Note: I hit this one while writing. On my Mac Studio, ~/.cache/huggingface is a symlink to an external drive. With the drive unplugged, every download failed with Permission denied: '/Volumes/...'. The error says nothing about a missing drive. Either plug it in or point HF_HOME to an internal folder for that session.

Check: hf cache list runs without errors and shows the folder you expect.

Step 4: Run a model and measure it

Start small. A 1.7B model downloads in seconds and tells you whether everything works:

mlx_lm.generate --model mlx-community/Qwen3-1.7B-4bit --prompt "Explain unified memory in two sentences." --max-tokens 120
mlx_lm.chat --model mlx-community/Qwen3-1.7B-4bit

Repos under mlx-community on Hugging Face are already converted and quantized for MLX, so for most popular models you never need to convert anything yourself.

To get numbers you can compare, use the built-in benchmark. It runs several trials with a synthetic prompt of the size you ask for:

mlx_lm.benchmark --model mlx-community/Qwen3-8B-4bit --prompt-tokens 2048 --generation-tokens 256

On the M1 Ultra this printed prompt_tps=763.297, generation_tps=91.191, peak_memory=5.611. Earlier, the 1.7B model with 512 prompt tokens and 128 generated gave about 3,080 tok/s prompt and 238 tok/s generation at 1.7 GB peak. For a single, more realistic run, the repo has scripts/bench.sh, which calls mlx_lm.generate --verbose True with a fixed prompt and prints the speed and peak memory lines.

Two numbers matter and they behave differently:

  • Prompt speed (prefill) is compute bound. It decides how long you wait before the first token when you paste a long document.
  • Generation speed is memory-bandwidth bound: every new token reads the active weights once. Roughly, tokens per second ≈ bandwidth ÷ bytes of active weights.

That second rule explains most of what you will see. My M1 Ultra measured about 596 GB/s in a copy test (the spec says 800). An 8B model at 4-bit is about 5 GB of weights, so ~90 tok/s is in the right range. It is also why Mixture-of-Experts models feel so fast: a 30B MoE that activates about 3B parameters per token reads far less per token than a dense 30B, even though the file is the same size. And it explains why long contexts slow generation down: the KV cache is also read for every token. With Ollama on a large MoE coding model, I saw generation drop from about 60 tok/s at 2.7k tokens of context to 22 tok/s at 32k. If you don’t need the full window, cap it with --max-kv-size.

Check: you have one benchmark line for one model written down. Every later decision (quantization, context, which machine) is easier with a baseline.

Step 5: Load on demand, release when idle

This is the part I care about most. A 30B model at 4-bit holds about 18 GB of memory whether you use it or not. On a 64 GB laptop that is the difference between a fast machine and a swapping one. The goal is a lifecycle like this:

Lifecycle: idle, load on first request, serve, unload after the idle timeout
On-demand loading: the first request pays the load time, the idle timer gives the memory back.

The cost is one slow request after a quiet period: the model has to load from SSD. For an 8B model on the M1 Ultra, Ollama reported a 4.9 s load; for larger models expect tens of seconds. Every request after that is immediate, and each one resets the idle timer.

Option A: Ollama

Ollama already works this way. Two environment variables control it: OLLAMA_KEEP_ALIVE (how long a model stays after its last request) and OLLAMA_MAX_LOADED_MODELS (how many can be in memory together). I run it as a LaunchAgent so the settings are explicit and survive updates:

launchd/ollama-ondemand.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key><string>com.local.ollama</string>
  <key>ProgramArguments</key>
  <array><string>/opt/homebrew/bin/ollama</string><string>serve</string></array>
  <key>EnvironmentVariables</key>
  <dict>
    <key>OLLAMA_HOST</key><string>127.0.0.1:11434</string>
    <key>OLLAMA_KEEP_ALIVE</key><string>5m</string>
    <key>OLLAMA_MAX_LOADED_MODELS</key><string>1</string>
    <key>OLLAMA_FLASH_ATTENTION</key><string>1</string>
  </dict>
  <key>RunAtLoad</key><true/>
  <key>KeepAlive</key><true/>
  <key>StandardOutPath</key><string>/tmp/ollama.log</string>
  <key>StandardErrorPath</key><string>/tmp/ollama.log</string>
</dict>
</plist>
brew services stop ollama 2>/dev/null
cp launchd/ollama-ondemand.plist ~/Library/LaunchAgents/com.local.ollama.plist
launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/com.local.ollama.plist

The KeepAlive key keeps the small ollama serve process running; it is the model that comes and goes. A single request can also override the timeout with a keep_alive field, which is how I tested it quickly: I sent one request with "keep_alive": "10s", then looked at ollama ps.

loaded right after the call:
qwen3:8b    500a1f067a9f    8.2 GB    100% GPU     40960      llamacpp    9 seconds from now
20 s later:
(no model loaded)

8.2 GB back to the system, without anyone touching anything. The one thing to avoid is a “warm-up” job that loads a model at login; it defeats the whole point.

Option B: MLX models through LM Studio

mlx_lm.server is great for testing, but it keeps its model in memory until you stop the process. It has no idle unload. For MLX models on demand I use LM Studio’s server, which has just-in-time loading: a request that names a model loads it, and a TTL unloads it after a period without requests.

  1. Install it with brew install --cask lm-studio and open it once.
  2. In the Developer tab, enable the local server, keep Just-in-time model loading on, and set the idle TTL. The default is 60 minutes; I use 10 minutes on a laptop.
  3. Keep Auto-evict on, so loading a second model through JIT unloads the first one.
  4. Point clients at http://localhost:1234/v1 with the model name.

You can also load from the terminal with a TTL, lms load <model> --ttl 600, or pass a ttl value in seconds in a single API request. If you don’t want the desktop app open, LM Studio has a headless mode (lms server start). I did not benchmark LM Studio for this post, so check its documentation for the current option names; they have changed between releases.

The rule that matters more than either tool

Run one big model at a time. If Ollama holds a 20 GB model and you start a 20 GB MLX job, both fight for unified memory and macOS starts swapping. Before a large MLX run, ollama ps and ollama stop <model>.

Check: wait past your timeout and run ollama ps (or lms ps). It should show nothing loaded. Activity Monitor’s Memory tab should agree.

Step 6: Convert and quantize a model yourself

When the model you want has no mlx-community version, or you want different quantization, convert it. This is what “building” a local model means in practice:

mlx_lm.convert --hf-path Qwen/Qwen3-0.6B -q --q-bits 4 --q-group-size 64 --mlx-path models/qwen3-0.6b-4bit

On the M1 Ultra this took 41 seconds including downloading the original weights, and produced a 331 MB folder. The same command works for 8B or 30B models; it just takes longer and needs the original weights to fit in memory.

How many bits to pick:

BitsWhen I use it
8Code, maths, anything where small errors matter, if it fits
6Close to 8-bit quality, about 25% smaller
4 (group 64)The default trade-off for chat and general tasks
3Only to squeeze a too-large model in; test quality before trusting it

Size rule of thumb: parameters × bits ÷ 8, plus 10–20% overhead. A 30B model at 4-bit is about 17–19 GB, a dense 70B at 4-bit about 40 GB. Then leave room for the KV cache, which grows with context length.

Check: run your converted model with mlx_lm.generate --model models/qwen3-0.6b-4bit --prompt "hello" and compare an answer or two with the mlx-community version of the same model.

Step 7: Fine-tune with LoRA

LoRA trains a small set of extra weights (an adapter) on top of a frozen model. When the base is 4-bit, this is usually called QLoRA. It is cheap in memory, fast on Apple Silicon, and good at one thing in particular: teaching a model a format or a narrow task it gets half right today.

To show that on something you can rerun, I picked a task small models are mediocre at without help: classify a support ticket into a category and a severity, and answer with JSON only.

The dataset

lora/make_dataset.py generates synthetic tickets from templates. The interesting part is the labelling rule, because it is exactly the kind of house rule a base model can’t guess:

lora/make_dataset.py

def severity(category: str, suffix: str) -> str:
    if "blocking" in suffix or "Urgent" in suffix:
        return "high"
    if "No rush" in suffix or category == "feature":
        return "low"
    return "high" if category in ("billing", "login") else "medium"

Each example is in chat format: a system prompt, the ticket, and the expected JSON. One line of train.jsonl looks like this (shortened):

{"messages": [{"role": "system", "content": "You classify customer support tickets. Reply with JSON only: ..."}, {"role": "user", "content": "Charts are blank after the March update."}, {"role": "assistant", "content": "{\"category\": \"bug\", \"severity\": \"medium\"}"}]}

The script keeps only unique tickets and splits them 80/10/10, which gave 172 training, 22 validation and 22 test examples. That is small, and it is synthetic and easy on purpose. It demonstrates the workflow, not what LoRA will do on your data.

uv run python lora/make_dataset.py

Measure before you train

Without a baseline you can’t tell whether the adapter helped. lora/eval.py loads a model (and optionally an adapter), runs every test example and counts exact matches:

lora/eval.py

    model, tokenizer = load(args.model, adapter_path=args.adapter_path)
    rows = [json.loads(line) for line in open(args.data)]
    correct = valid_json = 0
    start = time.time()
    for r in rows:
        messages = r["messages"][:2]
        expected = json.loads(r["messages"][2]["content"])
        prompt = tokenizer.apply_chat_template(
            messages, add_generation_prompt=True, tokenize=False, enable_thinking=False
        )
        out = generate(model, tokenizer, prompt=prompt, max_tokens=40).strip()
uv run python lora/eval.py --model mlx-community/Qwen3-1.7B-4bit

The base Qwen3-1.7B 4-bit returned valid JSON 22 out of 22 times, but only 10 of 22 answers were exactly right (45%). It understood the format and guessed the severity rules.

Train

uv run mlx_lm.lora --model mlx-community/Qwen3-1.7B-4bit --train --data lora/data \
  --iters 300 --batch-size 4 --num-layers 16 --learning-rate 1e-4 \
  --adapter-path adapters --steps-per-eval 100

What the flags mean:

  • --num-layers 16: attach LoRA to the last 16 transformer layers. Fewer layers, less memory and less capacity.
  • --batch-size 4 and --iters 300: with 172 examples, that is about seven passes over the data.
  • --learning-rate 1e-4: on the high side, chosen because the run is short. On a larger dataset with a longer run, start at 1e-5 and go up only if the loss barely moves.
  • --steps-per-eval 100: compute validation loss every 100 steps, so you can see overfitting.

The log, cleaned up:

Trainable parameters: 0.289% (4.981M/1720.575M)
  iter   train_loss     tok/s     tokens
     1    val 5.370
    10    1.354          1,209      3.4k
    20    0.185          1,231      6.8k
   100    val 0.086
   200    val 0.073
   300    val 0.077
   300    0.070          1,246    101.5k
real 92.95

Only 0.29% of the parameters are trained, about 5 million. Validation loss fell from 5.37 to 0.073 at step 200 and ticked up slightly to 0.077 at step 300. That small rise is the first sign of overfitting; on a real dataset I would keep the step-200 checkpoint (--save-every writes intermediate adapters) or stop there.

Measure again

uv run python lora/eval.py --model mlx-community/Qwen3-1.7B-4bit --adapter-path adapters
uv run mlx_lm.lora --model mlx-community/Qwen3-1.7B-4bit --adapter-path adapters --data lora/data --test

After training: 22 of 22 exact matches (100%), test loss 0.074, perplexity 1.077. From 45% to 100% in about a minute and a half of training on a desktop. Again, the task is easy and the data is clean; on real data expect a smaller jump, and spend most of your time on the dataset, not on the flags.

Use or fuse the adapter

You can load the adapter at run time (--adapter-path adapters works with mlx_lm.generate and mlx_lm.server), or merge it into a standalone model:

uv run mlx_lm.fuse --model mlx-community/Qwen3-1.7B-4bit --adapter-path adapters --save-path models/qwen3-1.7b-tickets

The adapter holds only those 5 million trained parameters, so keeping it separate is handy when you have several tasks on one base model.

When you run out of memory during training: lower --batch-size, then --num-layers, cap --max-seq-length, or add --grad-checkpoint, which trades speed for memory.

Check: the eval numbers before and after are written down next to the adapter, with the command that produced them.

Step 8: Serve an OpenAI-compatible API

For testing, mlx_lm.server turns any MLX model (with or without an adapter) into an OpenAI-style endpoint:

mlx_lm.server --model mlx-community/Qwen3-8B-4bit --host 127.0.0.1 --port 8080
curl -s localhost:8080/v1/chat/completions -H 'content-type: application/json' \
  -d '{"messages":[{"role":"user","content":"hello"}],"max_tokens":50}'

Any client that speaks the OpenAI API works by changing the base URL:

from openai import OpenAI

client = OpenAI(base_url="http://127.0.0.1:8080/v1", api_key="local")
reply = client.chat.completions.create(
    model="mlx-community/Qwen3-8B-4bit",
    messages=[{"role": "user", "content": "Summarise LoRA in one sentence."}],
)
print(reply.choices[0].message.content)

Two rules I don’t bend:

  • Bind to 127.0.0.1. If you need the model from another machine, put it behind something with authentication, such as Tailscale (tailscale serve), not 0.0.0.0 on your home network and never a public port.
  • Don’t leave mlx_lm.server running permanently. It holds the model until it stops. For everyday serving, use the on-demand setup from Step 5.

Check: the curl returns a JSON answer, and lsof -iTCP:8080 -sTCP:LISTEN shows the server listening on 127.0.0.1 only.

MLX or Ollama: what the numbers say

Same model family, same machine, similar request size:

MLX (mlx-lm)Ollama (llama.cpp)
ModelQwen3-8B, MLX 4-bit (group 64)qwen3:8b, GGUF q4_K_M
Prompt2048 tokens1667 tokens
Prompt speed763 tok/s749–766 tok/s
Generation speed91.2 tok/s62.9–63.0 tok/s
Unload when idlenot in mlx_lm.serverbuilt in (keep_alive)
Fine-tuningbuilt in (mlx_lm.lora)no

Prompt processing came out the same. Generation was about 45% faster with MLX. The comparison is not perfectly controlled: the 4-bit formats differ (MLX group-wise 4-bit vs GGUF q4_K_M, which keeps some tensors at higher precision) and the prompt sizes differ a little. So read it as “MLX was clearly faster at generation on this Mac”, not as an exact ratio.

One measurement trap I fell into: my first Ollama run generated only 17 tokens, and the second run reused the cached prompt and reported a nonsense prompt speed of 120,767 tok/s. For a fair number, force a fixed output length (num_predict) and make each prompt unique; scripts/ollama-bench.py does both.

My conclusion: Ollama is the most convenient always-available service; MLX is faster, and it is where you build and fine-tune. Using both is fine as long as only one big model is loaded at a time.

Configuration for an M1 Max 64 GB / 1 TB and an M1 Ultra 128 GB

The M1 Ultra numbers above are measured. For the M1 Max, the column is an estimate based on its memory bandwidth (about 400 GB/s by spec, half of the Ultra’s 800 GB/s). Since generation is bandwidth bound, expect roughly half the generation speed for the same model. Run scripts/bench.sh on your own machine and replace my guesses with your numbers.

M1 Max, 64 GB, 1 TBM1 Ultra, 128 GB
Memory bandwidth (spec)~400 GB/s~800 GB/s (~596 GB/s measured)
GPU memory limit57344 MB (56 GB)114688 MB (112 GB)
Comfortable modelsMoE around 30B at 4–8-bit; dense up to ~32B at 4-bitMoE 80–120B at 4-bit; dense 70B at 4–8-bit
Runs, but slowlydense 70B at 4-bit (~40 GB)—
Qwen3-8B 4-bit generationroughly 45 tok/s (estimate)91 tok/s (measured)
LoRA7–14B bases at 4-bit, batch 2–48–32B bases comfortably
Models on diskkeep 3–5, at most 200–300 GB of the 1 TBexternal SSD for the cache
Loading policyon demand, 5–10 min idle timeouton demand, same

On the 64 GB machine I would make a 30B-class MoE coding or chat model the daily driver, keep one small model (1.7B–4B) for quick tasks and experiments, and do LoRA on 4B–8B bases. The 1 TB SSD is the real constraint there, more than the RAM: four or five models and a couple of fused fine-tunes fill 200 GB quickly. Check hf cache list once a month.

Common mistakes

  • Installing into the system Python. pip install mlx-lm into Homebrew’s Python works until it doesn’t. Use uv tool install for the CLIs and uv run inside a project for your code.
  • An x86 Python under Rosetta. Everything runs, on the CPU, slowly. Check mx.default_device().
  • Two big models loaded at once. Ollama keeps a model for 5 minutes by default; start a large MLX job in that window and the Mac swaps. ollama ps first.
  • Leaving mlx_lm.server running. It never unloads. Fine for an afternoon of testing, not as a service.
  • Benchmarking with short outputs or a cached prompt. You get numbers that are either noise or impossible. Fix the output length and change the prompt each run.
  • Trusting training loss alone. Look at validation loss, and run the same eval before and after. The rise from 0.073 to 0.077 above is small, but it is the signal you watch for on real data.
  • Ignoring the disk. Converted models, original weights, GGUF copies in Ollama and fused fine-tunes are all separate files. The same model in both Ollama and MLX is two copies.
  • A cache symlink to an unplugged drive. The error is a confusing Permission denied. Plug the drive in or set HF_HOME.

Checklist for a new Mac

  • Command Line Tools, Homebrew and uv installed
  • scripts/setup-mlx.sh ran and printed Device(gpu, 0)
  • HF_HOME decided: internal disk or external SSD
  • GPU memory limit set for this RAM size, LaunchDaemon installed if you want it permanent
  • One small model runs, then the model you actually want
  • One benchmark line recorded for that model
  • Ollama: OLLAMA_KEEP_ALIVE=5m, OLLAMA_MAX_LOADED_MODELS=1, no warm-up job
  • LM Studio (if you use it for MLX): JIT loading on, idle TTL set, nothing loaded when idle
  • Nothing loads a model at boot; Activity Monitor shows idle memory back to normal

Wrapping up

The setup that stuck for me is short: mlx-lm for anything where I build, convert or fine-tune, an on-demand server for everyday use, and a strict one-big-model-at-a-time rule. The surprise was how cheap LoRA is on a Mac: a minute and a half to take a small model from guessing to exact on a narrow task. The work is in the dataset and the eval, not in the hardware.

If you want to share a local model with a whole team rather than keep it on your desk, I wrote about that in running a self-hosted LLM API server for a team. Everything from this post, including the raw log, is in the sample repo.

Discussion

Comments are reviewed before publication. Your email is kept private.

← Back to allĐọc tiếng Việt