Skip to content

About

在Mac上本地部署llm,并将它们与Claude Code等Harnesses一起使用 Deploy LLMs Locally on Mac & Put Them to Work with Harnesses like Claude Code 🦆🚲

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

7 Commits

Folders and files

Repository files navigation

🍎 mac-llm-deploy

Deploy LLMs Locally on Mac & Put Them to Work with Claude Code

platform chip framework runtime client license

In one sentence: Deploy a local large language model on your Mac and make it actually work — by the end, you'll have a duck riding a bicycle in SVG.

This repo is the full companion guide for the talk "How to Deploy an LLM Locally on a Mac". You don't need to watch the video — just follow the steps below and you'll have a working local model on your Mac.

🔒 Why local? — Privacy is the #1 reason, not just saving money. With local deployment, your data never leaves your computer: your private code, business documents, customer data, personal conversations — they stay on your Mac. They're never uploaded to any cloud, never used for training, never leaked. For scenarios involving trade secrets, compliance, or privacy, local inference is the way to go. See §8 · Privacy & Data Security.

  • 📺 Slides: docs/slides.html (open in browser, press ← → to navigate, F for fullscreen)
  • 🎯 Final result: Local model + Claude Code → riding-duck.svg
  • 🎨 Duck Gallery: See what each model actually drew → docs/results/
  • 🇨🇳 中文版:README_zh-CN.md

Quick Start

In a hurry? Here's the shortest path to a working local model:

  1. Check hardware: Apple Silicon Mac (M-series), ≥16GB unified memory. (→ details in §2)
  2. Install oMLX:
    brew tap jundot/omlx https://github.com/jundot/omlx
    brew install omlx
  3. Start & pick a model in the oMLX menu-bar app (UI, recommended): run omlx start, then click the oMLX icon in the macOS menu bar to start/select a model (e.g. unsloth/Qwen3.6-35B-A3B-UD-MLX-3bit).
  4. Connect Claude Code: omlx launch claude → ask it to "draw a duck riding a bicycle" 🦆🚲.

💡 Want the full explanation? Read on ↓


Table of Contents


1. Mental model: What does "deploying an LLM locally" actually mean?

Deploying an LLM locally is not just downloading a model. It consists of four independent layers:

┌─────────────────────────┐
│ 1. Mac hardware         │   ← CPU & GPU (determine model size & speed)
└────────────┬────────────┘
             ▼
┌─────────────────────────┐
│ 2. Suitable model + quantized version │   ← Pick from HuggingFace community
└────────────┬────────────┘
             ▼
┌─────────────────────────┐
│ 3. Local inference engine │   ← We use oMLX (based on Apple MLX; LM Studio is an alternative)
└────────────┬────────────┘
             ▼
┌─────────────────────────┐
│ 4. Chat / coding client │   ← We use Claude Code
└─────────────────────────┘

🔑 Key distinction: The model is just files (weights). The inference engine loads and runs them. The client consumes the inference service. They are decoupled and swappable.


2. Requirements & hardware assessment

2.1 Hardware minimums

Item Minimum Recommended (demo)
Model Apple Silicon Mac (M1 / M2 / M3 / M4) MacBook Pro M3 Max
Unified Memory 16 GB (small models only) 36 GB
CPU 8-core 14-core
GPU 8-core 30-core
GPU Backend Metal Metal

⚠️ This setup is native to Apple Silicon. Intel Macs are not supported (no Metal / unified memory advantage).

2.2 Assess first: What can YOUR machine run?

Don't guess. Use llmfit — a tool that auto-detects your hardware and recommends models that actually fit.

# Install & usage per llmfit README:
# https://github.com/AlexsJones/llmfit

💡 llmfit is also packaged as a Claude Code skill (llmfit-hardware-model-matcher) — call it directly in Claude Code.

Tools used in this guide:

Tool Purpose Required
Apple MLX Apple's official AI framework, the recommended base for Apple Silicon ✅ (built into oMLX)
Homebrew macOS package manager, for installing oMLX ✅
oMLX MLX-based inference engine, optimized for Apple Silicon ✅
Claude Code Coding / chat client ✅
llmfit Hardware → model selection Recommended

3. Choosing a model for your machine

3.1 Where to find models?

  • HuggingFace community: Look for MLX / mlx-community tags (converted for Apple Silicon).
  • Cross-check with llmfit recommendations.

3.2 Understanding MoE: What does A3B / A4B in model names mean?

Imagine a company with 35 experts (35B total parameters), but for each question, the router only dispatches 3 most relevant experts (3B activated).

  • Benefit: Large knowledge base (35B capacity) but only a small portion is active → fast and power-efficient.
  • Trade-off: All 35B parameters must live in memory → memory depends on "total parameters", speed depends on "activated parameters".

So 35B-A3B = 35B total / 3B activated, 26B-A4B = 26B total / 4B activated. This is the key to "big yet fast".

3.3 Memory calculation (selection formula)

Available memory ≈ Unified memory − System overhead (~6GB) − Inference runtime (~1–2GB)

Model footprint ≈ Weights + KV Cache (grows with context) + activation temporaries
         Weights ≈ Total parameters × quantization bits ÷ 8   ← use "total" for MoE
         KV Cache ≈ 0.5–1.5GB per 8k context (depends on layers & precision)

Rule of thumb: Always keep ≥20% memory headroom. When memory is tight, lower quantization first, then shorten context.

3.4 Four candidate models

The four models from the demo. Each entry lists: what / quantization / memory estimate / HuggingFace link / best for. ⚠️ Model versions iterate quickly — links are subject to the actual HuggingFace page.


⭐ Model 1: unsloth/Qwen3.6-35B-A3B-UD-MLX-3bit (default for this guide)

  • What: Alibaba Qwen 3.6, MoE architecture, 35B total / 3B activated. UD = Unsloth Dynamic quantization: adapts bits per layer based on sensitivity to quantization, better quality at the same size.
  • Quantization: 3bit (MLX).
  • Memory: Weights ≈ 35B × 3 ÷ 8 ≈ 13 GB; on a 36GB Mac, with KV + runtime ≈ 20–23 GB, plenty of headroom.
  • Link: https://huggingface.co/unsloth/Qwen3.6-35B-A3B-UD-MLX-3bit (4bit sibling ...-UD-MLX-4bit also exists)
  • Best for: The default pick — best balance of capability, speed, and memory.

Model 2: mlx-community/gemma-4-26b-a4b-it-4bit

  • What: Google Gemma 4, MoE 26B total / 4B activated; it = instruction-tuned (conversation-ready).
  • Quantization: 4bit (MLX).
  • Memory: Weights ≈ 26B × 4 ÷ 8 ≈ 13 GB; runs easily on 36GB.
  • Link: https://huggingface.co/mlx-community/gemma-4-26b-a4b-it-4bit
  • Best for: Google ecosystem fans / multilingual scenarios.

✅ Model 3: mlx-community/gpt-oss-20b-MXFP4-Q8 (real, downloadable)

  • What: OpenAI's open-source gpt-oss-20b, MoE ~20.8B total / 3.6B activated, native 128k context. MXFP4 = main body 4-bit float; Q8 = precision-sensitive parts (attention / shared experts) kept at 8-bit.
  • Quantization: MXFP4 + Q8 hybrid.
  • Memory: Weights ≈ 10–11 GB; runs on 16GB Mac with short context, very comfortable on 36GB.
  • Link: https://huggingface.co/mlx-community/gpt-oss-20b-MXFP4-Q8
  • Best for: OpenAI-style quality + long context + low memory threshold.

Model 4: MLX-Qwen3.5-35B-A3B-Claude-4.6-Opus-Reasoning-Distilled-4bit

  • What: Community creation — Qwen3.5-35B-A3B as base, trained with knowledge distillation from Claude Opus reasoning traces. Small model learns the large model's reasoning style.
  • Quantization: 4bit.
  • Memory: Same architecture as Model 1 but 4bit, weights ≈ 35B × 4 ÷ 8 ≈ 17.5 GB; runnable on 36GB but tighter than 3bit.
  • Link: https://huggingface.co/Jackrong/MLX-Qwen3.5-35B-A3B-Claude-4.6-Opus-Reasoning-Distilled-4bit (base Qwen3.x-35B-A3B, reasoning-distilled from Claude Opus)
  • Best for: "Claude-like" reasoning style, willing to accept higher memory cost.

4. Extending: Test more models (model registry)

We encourage you to add more models to test. Below is a "model registration table" pre-filled with the four above. To add a new model, copy the row template below and fill it in — PRs welcome.

4.1 Model registry

# Model (click → HF) Quant Weights~ 36GB fit? Key params Observed quality Status
1 unsloth/Qwen3.6-35B-A3B-UD-MLX-3bit 3bit ~13GB ✅ plenty ctx 32k 🦆 4.9KB ⭐ default
2 mlx-community/gemma-4-26b-a4b-it-4bit 4bit ~13GB ✅ ctx 128k 🦆 1.7KB backup
3 mlx-community/gpt-oss-20b-MXFP4-Q8 MXFP4+Q8 ~11GB ✅✅ comfortable ctx 128k 🦆 1.9KB backup
4 Jackrong/...-Distilled-4bit 4bit ~17.5GB ✅ tight ctx 32k 🦆 3.4KB backup

🦆 The "🦆 size" = each model's actual "duck on a bike" SVG output. Open them in docs/results/ to compare.

4.2 How to run a model (run parameters)

✅ Recommended — oMLX menu-bar app (UI): the simplest, most intuitive way. Click the oMLX icon in the macOS menu bar → pick a model → it downloads, loads, and serves automatically. No CLI flags, no config — this is exactly how the demo runs. Run omlx launch claude to wire the model straight into Claude Code.

Advanced — run any MLX model from the command line (if you prefer the terminal, or want scriptable control), use Apple's mlx-lm:

# Install
pip install mlx-lm

# A) Start an OpenAI-compatible local server (for Claude Code / other clients)
mlx_lm.server --model mlx-community/gpt-oss-20b-MXFP4-Q8 --host 127.0.0.1 --port 8080

# B) One-shot generation test (quick verification)
mlx_lm.generate --model mlx-community/gpt-oss-20b-MXFP4-Q8 \
                --prompt "draw a duck riding a bicycle" --max-tokens 512

Common parameters:

Parameter Purpose
--model <org/name> HuggingFace model ID
--max-tokens N Max generation length (longer = more memory / slower)
--host / --port Service listen address (for client connections)
--temp / --top-p Sampling temperature / diversity (affects creativity)
--cache-limit-gb KV Cache upper limit, prevents OOM

4.3 How to add a new model (contribution template)

  1. Use llmfit / HuggingFace to confirm your machine can run it (see §3.3 formula).
  2. Pick a MLX quantized version, note the HF link and weight size.
  3. Run it per §4.2, record local memory usage, tok/s, quality.
  4. Add a row to §4.1 registry (copy the template below).
  5. Open a PR.
| N | [org/model-name](https://huggingface.co/org/model-name) | <quant> | ~<weights>GB | ✅/⚠️ | ctx <k> | <tok/s, quality> | <status> |

5. Installing the inference framework oMLX

5.1 What is oMLX?

Models are just files; oMLX is the "local model service" that runs them.

  • Based on Apple's official MLX framework (the recommended base for AI on Apple Silicon).
  • Specifically optimized for Apple Silicon.
  • Responsible for loading models, running inference, exposing interfaces.
  • Manage model services via the menu bar app (recommended) or command line.

5.2 Prerequisite: Install Homebrew

Skip if already installed:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

5.3 Install oMLX (three steps)

# 1. Add oMLX tap
brew tap jundot/omlx https://github.com/jundot/omlx

# 2. Install
brew install omlx

# 3. Start the model service
omlx start

5.4 Key features of oMLX

  • ⚡ Native MLX inference — calls Apple's MLX directly, maxing out Apple Silicon.
  • 🤝 Built for Claude Code — scales token usage so Claude Code's auto-compaction triggers correctly on smaller-context models.
  • 💽 SSD offloading for non-hot data — lets larger models run within limited unified memory.
  • …more at oMLX repo.

6. Starting the model service

omlx start

Once the service is up, manage it two ways:

  • ✅ Recommended — Menu bar app (UI): click the oMLX icon in the macOS menu bar for visual start / switch / stop. Easiest for most users.
  • Advanced — Command line: use omlx ... commands to manage (scripting, headless, etc.).

Once running, it exposes a local endpoint for Claude Code or other clients to connect.


7. Connecting to Claude Code

7.1 Prerequisite: Install Claude Code

Follow the official docs.

7.2 One command to bridge local model to Claude Code

omlx launch claude

7.3 Full workflow (the three steps from the demo)

Step 1 →  $ omlx launch claude               # Start and bridge to Claude Code
Step 2 →  Select model                        # Pick unsloth/Qwen3.6-35B-A3B-UD-MLX-3bit
Step 3 →  Draw a duck riding a bicycle SVG, save file   # 🦆 → riding-duck.svg

Done. The local model generates riding-duck.svg — that's the finish line.


8. Glossary (quick reference)

8.1 Apple Silicon & Unified Memory

  • Unified Memory: In M-series chips, CPU and GPU share the same physical memory. For LLMs, model weights don't need to copy between CPU↔GPU — fast loading, efficient inference.
  • Metal: Apple's graphics/compute API, used as the GPU backend for accelerated inference.

8.2 Precision & Quantization

Model "precision" has two layers:

Layer Meaning Typical
Training precision Model's 出厂 (factory) weight bits FP32 / BF16 / FP16
Inference quantization Compression at deployment INT8 / INT4 / 3bit
  • Quantization: Compress weights from high to low precision — trading a bit of quality for big memory/speed gains.
  • Rule: Lower bits → less memory, faster, but potentially lower quality (reasoning/math tasks are more sensitive).

Common tags:

Tag Meaning
4bit / 3bit Average weight bits
MXFP4 4-bit float format (slightly better quality than integer 4bit)
Q8 8-bit quantization (higher quality, larger size)
UD Unsloth Dynamic quantization (adaptive bits per layer)

8.3 Fine-tuning & LoRA / QLoRA

  • Fine-tuning: Continue training on your own data to specialize the model (your codebase, industry terms, writing style).
  • Full fine-tuning is too expensive; light fine-tuning is standard:
    • LoRA: Freeze the original model, train only a small "adapter" matrix — less VRAM, swappable.
    • QLoRA: LoRA + quantization — even less VRAM, fine-tune on an ordinary Mac.
  • Unsloth is the most popular tool in this space (hence all those unsloth/ model prefixes).

8.4 Knowledge Distillation

  • Distillation: Use a large, powerful "teacher" model (e.g., Claude Opus) to generate high-quality reasoning traces, then train a small, fast "student" model to learn the teacher's ability and style.
  • Model 4 (...-Claude-4.6-Opus-Reasoning-Distilled-...) is exactly this: Qwen is the student, learning Claude's reasoning patterns. Small size, cheap inference, with a touch of "big model smarts".

8.5 Apple MLX Framework

  • MLX is Apple's official open-source array computing framework (like NumPy / PyTorch), designed for Apple Silicon — the recommended base for AI on Mac.
  • Features: native unified memory (CPU/GPU share, zero-copy), lazy evaluation, Metal GPU backend.
  • mlx-lm: High-level library for LLMs on MLX (loading, inference, quantization, serving — see §4.2).
  • oMLX and mlx-community models all build on MLX.

8.6 KV Cache & SSD Offloading

  • KV Cache: Cached history from inference, grows with conversation length — the main memory consumer for context windows.
  • SSD offloading: oMLX can move infrequently accessed non-hot KV data to SSD, enabling larger context / larger models within limited unified memory, at the cost of extra disk reads on cache misses.

8.7 Token Scaling & Claude Code Auto-Compaction

  • Auto-compaction: Claude Code automatically summarizes and compresses history when context is near full.
  • On smaller-context local models, if the trigger timing is wrong, it can cause issues; oMLX fixes this by scaling reported token usage, ensuring auto-compaction triggers at the right time for stable long tasks.

8.8 Inference Engine vs Model vs Client

Concept In this project Responsibility
Model Qwen3.6-35B-MLX-3bit Weight files (knowledge)
AI Framework Apple MLX Low-level array / Metal compute
Inference Engine oMLX (built on MLX) Load weights, run inference, expose API
Client Claude Code Consume API, interact with human

8.9 Privacy & Data Security: Why Local?

Local LLM deployment, privacy is the #1 reason:

  • 🔒 Data stays local: Private code, business docs, customer data, personal conversations — inference runs entirely on your Mac, never uploaded to any cloud.
  • 🚫 Never used for training: No risk of "vendor trains on your prompts".
  • ✅ Compliance-friendly: Natural fit for data residency requirements (classified, GDPR, healthcare, finance).
  • 📴 Offline capable: Works without internet — great for intranets, travel, no-external-network environments.
  • 💰 Zero per-token cost: Run as many tokens as you want for free (trade-off: capability ceiling is typically below top cloud models, and it eats local compute).

One liner: Cloud models give you the strongest capability; local models give you the most control and privacy. This project proves "local can run, and it can work".


9. Troubleshooting

Symptom Fix
brew install omlx fails Run brew update first; confirm brew tap jundot/omlx ... succeeded
omlx: command not found Run brew link omlx; check Homebrew PATH in ~/.zshrc
Slow / failed model download Set mirror: export HF_ENDPOINT=https://hf-mirror.com then retry
OOM on startup / crash Lower quantization (4bit → 3bit) or pick a smaller model; re-check selection with llmfit; shorten context
Claude Code can't connect Confirm omlx start is running; bridge with omlx launch claude
Garbled output Set terminal to UTF-8; export LANG=en_US.UTF-8
Weird behavior in long conversations Check if context limit was reached; rely on oMLX token scaling + auto-compaction

10. Project structure

mac-llm-deploy/
├── README.md            # This guide (English, primary)
├── README_zh-CN.md      # 中文文档
├── LICENSE              # MIT
├── .gitignore
└── docs/
    ├── slides.html      # Companion talk slides (open in browser, ← → navigate, F fullscreen)
    └── results/         # 🦆 Each model's actual "duck on a bike" SVG output (+ gallery README)

11. Related resources


12. FAQ

Q: Must I have an M3 Max? Do M1 / M2 work? Yes. As long as unified memory is sufficient (≥16GB recommended), any M-series chip works; more memory = more model choices and longer context.

Q: Must I use oMLX? No. oMLX is our pick for this demo (MLX-based, Apple Silicon optimized, easy Claude Code integration). You can also use LM Studio, Ollama, or raw mlx-lm, but the Claude Code integration steps will differ.

Q: How does a local model differ from a cloud model (e.g., Claude)? Local models keep data on your machine, work offline, have no per-token billing, and are privacy-controlled; but the capability ceiling is typically below top cloud models. This project shows "local can run, and it can work".

Q: Why emphasize privacy? Sending private code / business docs / customer data to cloud models carries leakage and training risks; local inference keeps data entirely on your Mac — the gold standard for compliance and security.

Q: What's the difference between quantization / fine-tuning / distillation?

  • Quantization: Compress an existing model's bit count (doesn't change ability, saves memory).
  • Fine-tuning: Continue training with your data (makes the model understand your domain).
  • Distillation: A big model teaches a small model (small model learns big model's ability/style).

Q: Will quantization make it noticeably dumber? 4bit / 3bit still works well for most tasks; tasks sensitive to reasoning/math may benefit from 8bit or a larger model.


License

MIT

About

在Mac上本地部署llm,并将它们与Claude Code等Harnesses一起使用 Deploy LLMs Locally on Mac & Put Them to Work with Harnesses like Claude Code 🦆🚲

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors