[Build] CPU extension fails to compile on macOS ARM64 (Apple Silicon)

用户在 macOS ARM64 (Apple Silicon) 上使用 Python 3.12 和 Apple Clang 编译器,运行以下命令从源代码构建 vLLM 的 CPU 后端时触发问题:

[Build] CPU extension fails to compile on macOS ARM64 (Apple Silicon)

[Build] CPU extension fails to compile on macOS ARM64 (Apple Silicon)

快速结论:该报错发生在 macOS ARM64 (Apple Silicon) 环境下从源代码编译 vLLM 的 CPU 后端时,主要原因是 C++20 语法被 Clang 拒绝以及 ARM 平台缺少特定构造函数。优先检查是否已合并 PR #40380(C++20 标准)和 PR #41387(ARM 构造函数桩)。

问题场景

用户在 macOS ARM64 (Apple Silicon) 上使用 Python 3.12 和 Apple Clang 编译器,运行以下命令从源代码构建 vLLM 的 CPU 后端时触发问题:

uv pip install --editable . --torch-backend=auto

报错原文

warning: captured structured bindings are a C++20 extension [-Wc++20-extensions]

error: no matching constructor for initialization of 'vec_op::FP32Vec16'

原因分析

该问题由两个独立的编译错误组成:

  • C++20 结构化绑定 lambda 捕获:csrc/cpu/cpu_attn_vec.hpp:105 中,代码使用了 C++20 的结构化绑定(structured bindings)在 lambda 表达式中捕获变量。GCC 在 C++17 模式下将其作为扩展允许,但 Apple Clang 会将其视为 C++20 扩展并发出警告。
  • 缺少 ARM 平台的 FP32Vec16(const BF16Vec32&, int) 构造函数:csrc/cpu/cpu_attn_vec.hpp:23 中调用 FP32Vec16(bf16_b_reg, 0)FP32Vec16(bf16_b_reg, 1) 时,该双参数构造函数仅存在于 cpu_types_x86.hpp 中,未在 cpu_types_arm.hpp 中实现,导致编译错误。

环境排查

  • 操作系统:macOS ARM64 (Apple Silicon)
  • 编译器:Apple Clang(任意较新版本)
  • Python 版本:3.12
  • PyTorch 版本:torch 2.11.0
  • 构建目标:VLLM_TARGET_DEVICE=cpu

解决步骤

  1. 第一项问题修复(C++20 标准): 确保已合并 PR #40380(提交 d6563d693),该 PR 将 CMakeLists.txtcmake/cpu_extension.cmake 中的 CMAKE_CXX_STANDARD 从 17 提升到 20,从而消除 Clang 对 C++20 扩展的警告。
  2. 第二项问题修复(ARM 构造函数桩): 确保已合并 PR #41387(提交 e47c98ef7),该 PR 在 cpu_types_arm.hpp(以及 cpu_types_scalar.hppcpu_types_vsx.hppcpu_types_vxe.hpp)中添加了缺失的构造函数桩:
    // cpu_types_arm.hpp:491
    explicit FP32Vec16(const BF16Vec32&, int) : Base() {}
  3. 完整重建: 拉取 main 分支最新代码(已验证 5d5fab006 版本),使用以下命令重新编译:
    uv pip install --editable . --torch-backend=auto

验证方法

编译完成后,确认所有目标(包括 _C.abi3.so)均已成功编译且无错误。运行 vLLM CPU 后端推理测试,确保功能正常。

参考来源

vllm-project/vllm #41537

GamsGo AI

AI 工具推荐

想把多个 AI 模型放在一个入口?

GamsGo AI 集成 ChatGPT、DeepSeek、Gemini、Claude、Midjourney、Veo 等常用模型,适合写作、绘图、视频和日常 AI 工作流。

了解 GamsGo AI

推广链接:通过此链接购买,我可能获得佣金,不影响你的价格。

celebrityanime
celebrityanime
文章: 12016

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注