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

Apple Silicon 虚拟机 GPU 直通加速 LLM 推理 11-16

Apple Silicon 上 GPU 直通加速 macOS 虚拟机 LLM

原文
发到 X
推荐理由

做 macOS 虚拟化或本地 LLM 推理的同学必看,这个进程级 shim 直接把 VM 里的推理速度拉满到接近裸机,赶紧拿你的 M 系列芯片复现一遍。

Apple Silicon and macOS VMs: 11–16× Faster LLM Inference with llama.cpp

Apple Silicon 与 macOS 虚拟机:llama.cpp 推理速度提升 11–16 倍

Published on August 11, 2026 by Francesco Bonacci and Johnny Franks

发布于 2026 年 8 月 11 日,作者:Francesco Bonacci 和 Johnny Franks

If you've been following Cua from the start, you may remember that it began with a Show HN launch for Lume, our macOS virtualization stack.

如果你从一开始就关注 Cua,你可能还记得它始于 Lume 的 Show HN 发布,Lume 是我们的 macOS 虚拟化栈。

A macOS guest running through Apple's Virtualization.framework uses a virtual GPU backed by the host's Apple GPU. In our stock Tahoe VM, that device reported a conservative Metal capability profile. Applications use those answers to select kernels and rendering paths, which left llama.cpp running much slower GPU code.

通过 Apple 的 Virtualization.framework 运行的 macOS 客户机使用由宿主机 Apple GPU 支持的虚拟 GPU。在我们标准的 Tahoe 虚拟机中,该设备报告了保守的 Metal 能力配置文件。应用程序使用这些答案来选择内核和渲染路径,这导致 llama.cpp 运行速度慢得多的 GPU 代码。

We built a small, process-scoped compatibility layer that changes selected capability answers for one guest process, allowing llama.cpp to select newer Metal kernels. This is the first result from our broader effort to connect Lume's virtualization foundation to the local computer-use environments behind Cua Driver and the infrastructure behind Cua Cloud and Fleets.

我们构建了一个小的、进程作用域的兼容层,它改变了一个客户机进程的某些能力答案,使 llama.cpp 能够选择更新的 Metal 内核。这是我们更广泛努力的首个成果,旨在将 Lume 的虚拟化基础连接到 Cua Driver 背后的本地计算机使用环境以及 Cua Cloud 和 Fleets 背后的基础设施。

We're releasing this work today as a research release under the same permissive license as Lume and Cua, so others can reproduce the results and help map which Apple Silicon chips, macOS releases, and Metal workloads benefit.

我们今天以研究发布的形式发布这项工作,采用与 Lume 和 Cua 相同的宽松许可证,以便其他人可以复现结果,并帮助绘制哪些 Apple Silicon 芯片、macOS 版本和 Metal 工作负载受益。

On an M1 Ultra, TinyLlama 1.1B running through llama.cpp processed prompts 11.08× faster and generated tokens 16.36× faster than the same workload in the same stock VM. Prompt processing reached 98% of our bare-metal result. The source, build scripts, capability probe, and raw benchmark logs are included so you can inspect and reproduce the result.

在 M1 Ultra 上,通过 llama.cpp 运行的 TinyLlama 1.1B 处理提示词的速度比同一标准虚拟机中的相同工作负载快 11.08 倍,生成令牌的速度快 16.36 倍。提示词处理达到了我们裸机结果的 98%。源代码、构建脚本、能力探测器和原始基准测试日志都包含在内,以便你可以检查和复现结果。

We repeated the experiment with Google's Gemma 4 12B QAT Q4_0, a 6.98 GB model released this year. The same layer improved prompt processing 7.20× and token generation 14.54×. The unlocked VM reached 99.59% of bare-metal prompt speed and 94.82% of bare-metal generation speed.

我们使用 Google 的 Gemma 4 12B QAT Q4_0(今年发布的 6.98 GB 模型)重复了实验。相同的层将提示词处理速度提高了 7.20 倍,令牌生成速度提高了 14.54 倍。解锁的虚拟机达到了裸机提示词速度的 99.59% 和裸机生成速度的 94.82%。

We then tested Meta's official Muse Glimmer 30B Q4_K-M GGUF in a 64 GiB guest. Through llama.cpp b10359, the unlocked VM processed a 512-token prompt 7.55× faster and generated 128 tokens 8.87× faster than the stock guest. This was a text-only llama.cpp test; it did not use Ollama, a multimodal projector, or a drafter.

然后,我们在 64 GiB 客户机中测试了 Meta 官方的 Muse Glimmer 30B Q4_K-M GGUF。通过 llama.cpp b10359,解锁的虚拟机处理 512 令牌提示词的速度比标准客户机快 7.55 倍,生成 128 个令牌的速度快 8.87 倍。这是一个纯文本的 llama.cpp 测试;它没有使用 Ollama、多模态投影仪或草稿模型。

The same capability gap has surfaced in other Virtualization.framework frontends. Tart, another macOS virtualization CLI, has an open “No GPU passthrough in macOS guest?” issue covering graphics and LLM performance inside macOS guests.

同样的能力差距也出现在其他 Virtualization.framework 前端中。Tart,另一个 macOS 虚拟化 CLI,有一个开放的“macOS 客户机中没有 GPU 直通?”问题,涵盖 macOS 客户机内的图形和 LLM 性能。

The cap inside a macOS VM

macOS 虚拟机内的上限

Apple's Virtualization.framework presents a macOS guest with a virtual graphics device. The guest submits Metal work through a purpose-built GPU driver, and Apple's host stack executes it on the physical GPU. This arrangement is paravirtualization, where the host keeps control of the hardware and the guest uses a virtualization-aware device.

Apple 的 Virtualization.framework 为 macOS 客户机提供了一个虚拟图形设备。客户机通过一个专门构建的 GPU 驱动程序提交 Metal 工作,而 Apple 的主机栈在物理 GPU 上执行它。这种安排是半虚拟化,其中主机保持对硬件的控制,客户机使用一个支持虚拟化的设备。

This differs from other virtualization stacks built on QEMU and KVM, which can use a different architecture. On x86 Linux hosts, VFIO can assign a compatible physical PCI device or hardware function to a VM through an IOMMU, giving the guest direct access to that device. This is the model usually meant by GPU passthrough.

这不同于其他基于 QEMU 和 KVM 构建的虚拟化栈,它们可能使用不同的架构。在 x86 Linux 主机上,VFIO 可以通过 IOMMU 将兼容的物理 PCI 设备或硬件功能分配给虚拟机,使客户机直接访问该设备。这通常是 GPU 直通所指的模型。

In our stock Tahoe VM, the paravirtualized device reported roughly an Apple 5-era family, 32 KB of maximum threadgroup memory, and SIMD-group matrix support as unavailable. Modern Metal software uses those answers to select kernels, so llama.cpp took a slower path even though the device could execute newer kernels.

在我们标准的 Tahoe 虚拟机中,半虚拟化设备报告了大约 Apple 5 代系列、最大线程组内存 32 KB,以及 SIMD 组矩阵支持不可用。现代 Metal 软件使用这些答案来选择内核,因此 llama.cpp 采取了较慢的路径,即使设备可以执行更新的内核。

Apple documents GPU capability through GPU families and feature tables and recommends querying the device at runtime. That makes the reported capability boundary consequential: applications are doing exactly what the platform tells them to do.

Apple 通过 GPU 系列和功能表记录了 GPU 能力,并建议在运行时查询设备。这使得报告的能力边界变得重要:应用程序完全按照平台告诉它们的去做。

The solution: a process-scoped Metal capability shim

解决方案:进程范围的 Metal 能力垫片

We built a small Metal capability shim (a compatibility layer inserted between an application and an API) that runs inside one guest process. It intercepts selected Metal capability queries and changes the answers returned to that process. Metal applications use those answers to select kernels, so returning the tested Apple-family and threadgroup-memory values lets llama.cpp choose its newer GPU paths. For our tested profile, the shim:

我们构建了一个小的 Metal 能力垫片(一个插入在应用程序和 API 之间的兼容层),它在一个客户机进程内运行。它拦截选定的 Metal 能力查询,并更改返回给该进程的答案。Metal 应用程序使用这些答案来选择内核,因此返回经过测试的 Apple 系列和线程组内存值可以让 llama.cpp 选择其更新的 GPU 路径。对于我们测试的配置文件,垫片:

  • answers supportsFamily: through Apple family 9 (1009); and
  • raises the reported maximum threadgroup memory from 32 KB to 64 KB.
  • 通过 Apple 系列 9 (1009) 回答 supportsFamily:;以及
  • 将报告的最大线程组内存从 32 KB 提高到 64 KB。

That was enough for the tested llama.cpp build to select newer SIMD-group reduction, SIMD-group matrix, and bfloat16 paths:

这足以让测试的 llama.cpp 构建选择更新的 SIMD 组归约、SIMD 组矩阵和 bfloat16 路径:

CapabilityStock guestTested profile
supportsFamily:1009falsetrue
SIMD-group matrixoffon
SIMD-group reductionoffon
bfloat16offon
Maximum threadgroup memory32 KB64 KB
能力标准客户机测试配置文件
supportsFamily:1009falsetrue
SIMD 组矩阵关闭开启
SIMD 组归约关闭开启
bfloat16关闭开启
最大线程组内存32 KB64 KB

The tested profile changes two reported values: Apple-family answers and the threadgroup-memory limit. Common, Mac, Metal, and working-set-size values keep their stock settings during the benchmark. We removed the original research hook's private feature-profile hook, clock and timing interposition, mesh substitution, ray-tracing override, argument-layout guard, and pipeline-compilation fallback. Its source is small enough to audit, and malformed or missing configuration keeps the process on its stock capability path.

测试的配置文件更改了两个报告值:Apple 系列答案和线程组内存限制。在基准测试期间,Common、Mac、Metal 和工作集大小值保持其默认设置。我们移除了原始研究钩子的私有功能配置文件钩子、时钟和计时插入、网格替换、光线追踪覆盖、参数布局保护和管道编译回退。其源代码足够小,便于审计,格式错误或缺失的配置会使进程保持在其默认能力路径上。

The workload stays on Apple's Virtualization.framework graphics path and executes on the host's Apple GPU. The capability changes are scoped to the injected guest process.

工作负载保持在 Apple 的 Virtualization.framework 图形路径上,并在主机的 Apple GPU 上执行。能力更改仅限于注入的客户机进程。

Physical GPU assignment, raw PCI or VFIO passthrough, and kernel changes sit outside this mechanism. A reported family describes the paths covered by our tests; each additional Metal API requires separate validation.

物理 GPU 分配、原始 PCI 或 VFIO 直通以及内核更改不在此机制范围内。报告的家庭描述了我们的测试覆盖的路径;每个额外的 Metal API 都需要单独验证。

The shim unlocks Metal capabilities on Apple's existing virtual GPU path. VM users often encounter the broader limitation under the name “GPU passthrough.”

该垫片在 Apple 现有的虚拟 GPU 路径上解锁了 Metal 功能。虚拟机用户通常以“GPU 直通”的名称遇到更广泛的限制。

Fresh result from the minimal artifact

来自最小工件的新结果

We tested on one Apple M1 Ultra with a 48-core GPU and macOS 26.6.1. The guest was the current public Tahoe Cua image (macOS 26.5.2, 8 vCPU, and 16 GiB) running in Lume 0.5.1. All three runs used the official llama.cpp b10167 release and the same TinyLlama 1.1B Chat Q4_K_M model.

我们在配备 48 核 GPU 和 macOS 26.6.1 的 Apple M1 Ultra 上进行了测试。客户机是 Lume 0.5.1 中运行的当前公共 Tahoe Cua 映像(macOS 26.5.2,8 个 vCPU,16 GiB)。所有三次运行都使用了官方 llama.cpp b10167 版本和相同的 TinyLlama 1.1B Chat Q4_K_M 模型。

The command was:

命令是:

代码 · 2 行
llama-bench -m tinyllama-1.1b-chat-v1.0.Q4_K_M.gguf \
  -p 512 -n 128 -r 10 -t 8 -ngl -1 -o json

Values below are medians of the ten samples emitted for each benchmark row:

以下值是每个基准测试行发出的十个样本的中位数:

WorkloadBare-metal hostStock guestUnlocked guestGuest speedupUnlocked / host
Prompt processing, 512 tokens4,871.99 tok/s431.86 tok/s4,786.70 tok/s11.08×98.25%
Token generation, 128 tokens286.71 tok/s12.63 tok/s206.60 tok/s16.36×72.06%
工作负载裸机主机默认客户机解锁客户机客户机加速解锁/主机
提示处理,512 个令牌4,871.99 tok/s431.86 tok/s4,786.70 tok/s11.08×98.25%
令牌生成,128 个令牌286.71 tok/s12.63 tok/s206.60 tok/s16.36×72.06%

Prompt processing nearly reached the host result. Generation reached 72.06% of host speed, leaving a measurable VM gap. The gain depends on the host GPU, guest version, application, and workload shape.

提示处理几乎达到了主机结果。生成速度达到了主机速度的 72.06%,留下了可测量的虚拟机差距。收益取决于主机 GPU、客户机版本、应用程序和工作负载形状。

The TinyLlama raw results and environment record include the exact image digest, model and binary hashes, commands, JSON output, stderr, and checksums. These release-candidate results certify the reduced shim used in this post.

TinyLlama 原始结果和环境记录包括确切的映像摘要、模型和二进制哈希、命令、JSON 输出、stderr 和校验和。这些候选发布结果证明了本文中使用的简化垫片。

A current 12B model

当前的 12B 模型

TinyLlama makes a useful controlled benchmark because it runs quickly and exposes the Metal path clearly. We also wanted a larger model that developers might choose today, so we ran Google's official Gemma 4 12B instruction-tuned QAT Q4_0 GGUF through the same llama.cpp binary.

TinyLlama 是一个有用的受控基准,因为它运行速度快,并且清晰地暴露了 Metal 路径。我们还想要一个开发者今天可能选择的更大模型,因此我们通过相同的 llama.cpp 二进制文件运行了 Google 官方的 Gemma 4 12B 指令调优 QAT Q4_0 GGUF。

The host, VM, shim, benchmark shape, and ten-sample method stayed the same. We disabled speculative decoding and left the multimodal projector unloaded, keeping the comparison on the same Metal inference path:

主机、虚拟机、shim、基准测试形状和十样本方法保持不变。我们禁用了推测解码,并保持多模态投影仪未加载,使比较保持在相同的Metal推理路径上:

WorkloadBare-metal hostStock guestUnlocked guestGuest speedupUnlocked / host
Prompt processing, 512 tokens517.88 tok/s71.66 tok/s515.76 tok/s7.20×99.59%
Token generation, 128 tokens52.38 tok/s3.41 tok/s49.67 tok/s14.54×94.82%
工作负载裸机主机标准客户机解锁客户机客户机加速解锁/主机
提示处理,512个令牌517.88令牌/秒71.66令牌/秒515.76令牌/秒7.20倍99.59%
令牌生成,128个令牌52.38令牌/秒3.41令牌/秒49.67令牌/秒14.54倍94.82%

更进一步:量化金融体系

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

进入量化体系 →

相似阅读

关联信息,但可能不是同一事件