跳到主内容
@wquguru
精选88Hacker News Best(web_list)技巧与观点

M4 Pro Mac Mini 本地大模型部署实战与 MoE 选型指南

M4 Pro Mac Mini 本地大模型部署实战配置

原文
发到 X
推荐理由

详细拆解了 Apple Silicon 上运行 MoE 模型的显存计算逻辑与具体配置,有完整的工具链和参数对照,Agent 开发者和本地部署玩家可直接照做。

I run a local LLM server on my M4 Pro Mac mini with 48 GB of RAM. It handles everything from my Hermes agent backend to quick chat queries on my phone. The whole thing takes about 30 minutes to set up.

我在配备 48 GB 内存的 M4 Pro Mac mini 上运行本地 LLM 服务器。它处理从我的 Hermes 智能体后端到手机上的快速聊天查询的所有事务。整个设置过程大约需要 30 分钟。

Here is the stack:

以下是技术栈:

  • Qwen3.6-35B-A3B-OptiQ-4bit: my main model for anything that needs reasoning or depth
  • Gemma-4-E4B-it-OptiQ-4bit: lightweight model for simple chats, formatting, and other routine tasks
  • oMLX: the inference server
  • Tailscale: tailnet connecting the Mac mini, my iPhone, and my MacBook
  • Qwen3.6-35B-A3B-OptiQ-4bit:用于需要推理或深度任务的主要模型
  • Gemma-4-E4B-it-OptiQ-4bit:用于简单聊天、格式化和其他常规任务的轻量级模型
  • oMLX:推理服务器
  • Tailscale:连接 Mac mini、iPhone 和 MacBook 的 tailnet

Hermes runs as the agent backend on the Mac mini, with my MacBook running the desktop client and my phone running Telegram. For non-Hermes usage I use Apollo on iOS for quick chats (reads like Claude, good for throwaway questions), Pi as my coding agent (I already wrote about that setup), and Raycast AI on my Mac for random things.

Hermes 在 Mac mini 上作为智能体后端运行,我的 MacBook 运行桌面客户端,手机运行 Telegram。对于非 Hermes 用途,我在 iOS 上使用 Apollo 进行快速聊天(阅读体验类似 Claude,适合提出一次性问题),使用 Pi 作为我的编码智能体(我之前已经写过关于该设置的博文),并在 Mac 上使用 Raycast AI 处理各种杂项任务。

Why bother?

为什么要费这个劲?

The main reason to run local: cloud APIs are rented land. They can change their pricing, hit your usage limits, or swap the model being served behind the scenes whenever they feel like it. I was regularly maxing out two $200/month subscriptions and it felt like I was getting different things from them at different points. Sometimes a model was fine, sometimes it degraded with no notice.

运行本地的主要原因是:云 API 是租来的土地。它们可以随时更改定价、达到使用限制或在幕后更换提供的模型。我经常同时用满两个每月 200 美元的订阅套餐,感觉在不同时期从它们那里得到的东西各不相同。有时某个模型表现良好,有时却会在毫无通知的情况下性能下降。

Data privacy is another issue. You do not know what these companies do with your data once they have it. They might limit how it gets used, they might sell it, they might expose it. Either way, it creates an operational security risk. If you work with sensitive code, client data, or proprietary workflows, sending it to a third-party API is a decision you make once and cannot undo.

数据隐私是另一个问题。你并不知道这些公司在获取你的数据后会做什么。它们可能会限制数据的使用方式,可能会出售数据,也可能会泄露数据。无论如何,这都会带来运营安全风险。如果你处理敏感代码、客户数据或专有工作流,将其发送到第三方 API 是一个一旦做出就无法撤销的决定。

Then there is AI sovereignty. I have been watching how the US government has limited the rollout of various models. That can happen at any point from any government, for any reason, and you have no control over it. If your workflow depends on a cloud model that gets restricted, you have to stop or scramble. The only way to avoid that is to own your compute.

还有 AI 主权问题。我一直在观察美国政府如何限制各种模型的推出。这种情况可能随时由任何政府出于任何原因发生,而你对此无能为力。如果你的工作流依赖于被限制的云模型,你就必须停止或仓促应对。避免这种情况的唯一方法是拥有自己的计算资源。

Other practical advantages:

其他实际优势:

  • Cost predictability. APIs are variable. Your usage spikes and your bill follows. With local hardware, the cost is the hardware purchase plus electricity. Flat. After that, every inference is free.
  • Latency. No network roundtrip means faster responses for everyday tasks. The M4 Pro’s media engine handles inference at speeds that feel instant for most prompts.
  • Offline capability. No internet, still works. For agent workflows that run in the background, this matters more than it sounds.
  • No rate limits. API providers throttle you when you hit usage thresholds. Your own machine does not care how much you run.
  • 成本可预测性。API 费用是波动的。你的使用量激增,账单也随之增加。而使用本地硬件,成本仅为硬件购买费用加上电费。固定不变。此后,每次推理都是免费的。
  • 延迟。没有网络往返意味着日常任务的响应速度更快。M4 Pro 的媒体引擎以近乎即时的速度处理大多数提示词的推理。
  • 离线能力。没有互联网也能正常工作。对于在后台运行的智能体工作流来说,这一点比听起来更重要。
  • 无速率限制。API 提供商会在你达到使用阈值时对你进行节流。你自己的机器则不在乎你运行了多少。

How I actually use it

我实际的使用方式

The Mac mini is always on. It sits on my desk and I barely notice it except when I need it.

Mac mini 始终保持开机状态。它放在我的书桌上,除非我需要用到它,否则我几乎注意不到它的存在。

Hermes runs on the Mac mini as well, using a local model on the same machine. I access my agent through Telegram (on my phone) and the Hermes desktop app on my MacBook. The Hermes desktop app acts as a ‘shell’ and connects to a Hermes backend on another device (in this case the Mac mini). This means I share a backend, conversation history, and skillset across all my devices.

Hermes 也在 Mac mini 上运行,使用的是同一台机器上的本地模型。我通过 Telegram(在手机上)和 MacBook 上的 Hermes 桌面应用来访问我的智能体。Hermes 桌面应用充当一个“外壳”,并连接到另一台设备(在本例中是 Mac mini)上的 Hermes 后端。这意味着我在所有设备上共享同一个后端、对话历史记录和技能集。

Then there is everything else:

然后是其他一切:

  • Apollo on iOS for quick throwaway chats. I want something that reads like Claude but does not require an API key or a subscription. Connect Apollo to http://[mac-mini-tailnet-url]/v1 and you are done. Good for “rewrite this paragraph” or “what does this error mean” type questions.
  • Raycast also on my Mac for random things I don’t want to install anything for.
  • Pi for coding. Already wrote about that setup.
  • iOS 上的 Apollo 用于快速且用完即弃的聊天。我想要一种读起来像 Claude 的体验,但不需要 API 密钥或订阅。将 Apollo 连接到 http://[mac-mini-tailnet-url]/v1 即可搞定。适合“重写这段文字”或“这个错误是什么意思”之类的问题。
  • Mac 上的 Raycast 也用于处理一些我不想安装任何软件的事情。
  • Pi 用于编码。之前已经写过关于该设置的博文。

The point is not to replace API-based models. It is to handle the 80% of requests that do not need GPT-5 or Claude Opus. And when I do need those, they are already available. Local just covers more of my day-to-day for free.

重点不是要取代基于 API 的模型。而是要处理那 80% 不需要 GPT-5 或 Claude Opus 的请求。而当我确实需要那些模型时,它们也已经可用了。本地模型只是免费覆盖了我更多日常需求。

The model breakdown

模型细分

Running a large model locally comes down to one thing: how much RAM it actually needs in memory. Most people look at the parameter count and get the wrong idea, because the difference between dense and mixture-of-experts (MoE) models matters a lot on consumer hardware.

在本地运行大模型归结为一件事:它在内存中实际需要的 RAM 大小。大多数人看参数量会产生误解,因为在消费级硬件上,稠密模型和混合专家(MoE)模型之间的差异非常大。

Here is how to read the identifier:

以下是如何解读标识符:

Qwen3.6-35B-A3B-OptiQ-4bit

Qwen3.6-35B-A3B-OptiQ-4bit

  • Qwen3.6: model family and version
  • 35B: total parameters across all experts
  • A3B: active parameters per token (3 billion, not 35)
  • OptiQ-4bit: mixed-precision quantization (4-bit mostly, 8-bit on sensitive layers)
  • Qwen3.6:模型系列和版本
  • 35B:所有专家的总参数量
  • A3B:每个 token 的激活参数量(30 亿,而非 350 亿)
  • OptiQ-4bit:混合精度量化(主要为 4-bit,敏感层为 8-bit)

gemma-4-e4b-it-4bit

gemma-4-e4b-it-4bit

  • gemma-4: Google’s Gemma 4 family
  • e4b: encoding size, roughly 4 billion parameters total
  • it: instruction-tuned
  • 4bit: uniform 4-bit quantization
  • gemma-4:Google 的 Gemma 4 系列
  • e4b:编码大小,总共约 40 亿参数
  • it:指令微调
  • 4bit:统一的 4-bit 量化

The key difference is the A3B part. A dense 27B model has 27 billion parameters loaded in RAM at all times, for every single token. An MoE model like the Qwen3.6-35B-A3B has 35 billion total parameters spread across 256 experts, but only about 3 billion are actually activated per token. The other 32 billion sit in RAM doing nothing.

关键区别在于 A3B 部分。一个稠密的 27B 模型在所有时间、针对每一个 token 都会在 RAM 中加载 270 亿参数。而像 Qwen3.6-35B-A3B 这样的 MoE 模型拥有分布在 256 个专家中的总共 350 亿参数,但每个 token 实际上只激活约 30 亿参数。其余 320 亿参数闲置在 RAM 中不做任何事情。

On my 48GB Mac mini, the Qwen3.6-35B-A3B in 4-bit takes about 20GB of RAM. That leaves 28GB for context windows, the operating system, and everything else running on the machine. The Gemma-4-E4B is roughly 2.4GB. Small enough to keep around for simple tasks where using the full 20GB model is overkill.

在我的 48GB Mac mini 上,4-bit 量化的 Qwen3.6-35B-A3B 大约占用 20GB 内存。剩下的 28GB 留给上下文窗口、操作系统以及机器上运行的其他所有程序。Gemma-4-E4B 大约为 2.4GB。这个体积足够小,可以保留用于简单任务,因为使用完整的 20GB 模型属于杀鸡用牛刀。

My friend’s MacBook Air had 16GB total. A dense 27B in 4-bit needs roughly 14GB. That is literally everything the machine has, minus room for the OS. So it works for a moment, and then when it does not, it swaps to SSD and becomes painful.

我朋友的 MacBook Air 总共有 16GB 内存。4-bit 量化的密集型 27B 模型大约需要 14GB。这几乎占用了机器所有的内存,只给操作系统留了一点空间。所以它能运行一会儿,但一旦撑不住,就会交换到 SSD 上,变得非常痛苦。

MoE changes this. The 35B model in my identifier would fit on the same MacBook because only 3B of weights are actually active per token, which means the GPU/Media Memory footprint is more like what a 6B dense model would need. The 35 billion total parameter weights all sit in unified memory

MoE(混合专家模型)改变了这一局面。我标识符中的 35B 模型可以在这台 MacBook 上运行,因为每个 token 实际上只有 3B 的权重处于激活状态,这意味着 GPU/媒体内存的占用更像是一个 6B 密集模型所需的水平。总共 350 亿的参数权重都存储在统一内存中。

How to check if a model will work on your hardware:

如何检查模型是否能在你的硬件上运行:

  • Look at the quantized file size first. A 4-bit model is roughly the number of parameters in gigabytes (35B params ≈ 17-20GB depending on the quantization method).
  • Subtract your OS overhead. macOS takes about 6-8GB on Apple Silicon.
  • Leave room for context windows. Every few thousand tokens adds megabytes to the KV cache. Plan for 8-16GB overhead if you expect long conversations.
  • For MoE models, the total parameter count is misleading. Look for the “active parameters” figure to understand actual inference memory.
  • If your model plus context still fits within your available unified memory with a 10-15% buffer, you are good. Anything closer to full will swap to SSD.
  • 首先查看量化后文件的大小。4-bit 模型的参数量大致对应以 GB 为单位的数值(35B 参数 ≈ 17-20GB,具体取决于量化方法)。
  • 减去操作系统的开销。macOS 在 Apple Silicon 芯片上大约占用 6-8GB。
  • 为上下文窗口留出空间。每增加几千个 token,KV 缓存就会增加几 MB。如果你预期会有长对话,请预留 8-16GB 的开销。
  • 对于 MoE 模型,总参数量具有误导性。请查找“激活参数量”数据以了解实际的推理内存需求。
  • 如果你的模型加上上下文仍然能装进可用统一内存中,并留有 10-15% 的缓冲空间,那就没问题。如果接近满载,就会交换到 SSD。

Performance

性能

Qwen averages 325 tok/s in processing prompts, and 34 tok/s in token generation. That isn’t instant, but it’s quick enough that I never really think about it.

Qwen 在处理提示词时平均速度为 325 tok/s,在生成 token 时为 34 tok/s。这不算即时响应,但速度快到我根本不需要在意它。

Memory bandwidth matters too, though it’s not about whether a model will run — it’s about how fast. The M4 Pro has 273 GB/s of unified memory bandwidth. That’s the speed limit for moving model weights from RAM into the compute units during inference. For context, a base M3 is 100 GB/s, an M2 Pro is 200 GB/s, and the M3 Max tops out at 400 GB/s. The M4 Pro sits solidly between the Pro and Max range, which is why the token speeds feel usable but not instant.

内存带宽也很重要,虽然它不决定模型能否运行——而是决定运行速度。M4 Pro 拥有 273 GB/s 的统一内存带宽。这是推理过程中将模型权重从 RAM 移动到计算单元的速度上限。作为参考,基础版 M3 为 100 GB/s,M2 Pro 为 200 GB/s,而 M3 Max 最高可达 400 GB/s。M4 Pro 的性能稳稳处于 Pro 和 Max 系列之间,这就是为什么 token 生成速度感觉可用但并不即时。

Swapping models is easy

切换模型很容易

This is the part nobody talks about. You can swap out your local models every few weeks as new ones drop. It is literally a download and a restart.

这是没人谈论的部分。随着新模型发布,你可以每隔几周就更换本地模型。这 literally 只是一个下载和一个重启的过程。

The workflow:

工作流程:

  • Download the new model into ~/models/
  • oMLX auto-discovers it from the model directory
  • Pick it in the oMLX app or restart the server
  • Done
  • 将新模型下载到 ~/models/
  • oMLX 会自动从模型目录中发现它
  • 在 oMLX 应用中选择它,或者重启服务器
  • 完成

The oMLX admin dashboard has a built-in HuggingFace model browser. Find a model, click download. Change the model in Hermes, Pi, Raycast, and Apollo, and I am all done.

oMLX 管理仪表板内置了 HuggingFace 模型浏览器。找到模型,点击下载。在 Hermes、Pi、Raycast 和 Apollo 中更改模型,我就搞定了。

A lot of this can be done via CLI too, so I can SSH into the Mac mini from any of my devices.

其中很多操作也可以通过 CLI 完成,因此我可以从任何设备 SSH 连接到 Mac mini。

更进一步:量化金融体系

看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力

进入量化体系 →

相似阅读

另一事件,读法相近