Bonsai 在 M2 安装
Posted | stdout
有个 1bit 模型最近很火 https://github.com/PrismML-Eng/Bonsai-demo
我本地环境不知道咋回事,搞混了 x86_64 和 arm64 。还有官方默认 python 3.11 我也不太满意,强行升级一波。
diff --git setup.sh setup.sh
index 543fab0..80c1190 100755
--- setup.sh
+++ setup.sh
@@ -13,7 +13,8 @@ cd "$SCRIPT_DIR"
VENV_DIR="$SCRIPT_DIR/.venv"
VENV_PY="$VENV_DIR/bin/python"
-PYTHON_VERSION="3.11"
+# PYTHON_VERSION="3.11"
+PYTHON_VERSION=3.14
# ────────────────────────────────────────────────────
# Helpers
@@ -266,6 +267,10 @@ if [ "$OS" = "Darwin" ]; then
fi
step "Building MLX from source (this takes 2-5 minutes on first install) ..."
+ # Force arm64 so CMake does not pick x86_64 (e.g. universal cc / Rosetta); MLX rejects x86_64+Metal on macOS.
+ if [ "$(uname -m)" = "arm64" ]; then
+ export ARCHFLAGS="${ARCHFLAGS:--arch arm64}"
+ fi
# --no-build-isolation required: MLX's C++/Metal build needs pre-installed setuptools
uv pip install --python "$VENV_PY" -e mlx/ --no-build-isolation
step "Installing MLX Python deps (mlx-lm, torch, transformers, ...) ..."
cd mlx
diff --git CMakeLists.txt CMakeLists.txt
index 041a476c..459ddae2 100644
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -56,7 +56,17 @@ message(
)
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
- if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64")
+ # CMAKE_SYSTEM_PROCESSOR can stay x86_64 on Apple silicon until the toolchain
+ # is fully configured; CMAKE_OSX_ARCHITECTURES reflects the actual target.
+ set(_mlx_macos_targeting_x86 OFF)
+ if(CMAKE_OSX_ARCHITECTURES)
+ if("x86_64" IN_LIST CMAKE_OSX_ARCHITECTURES)
+ set(_mlx_macos_targeting_x86 ON)
+ endif()
+ elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64")
+ set(_mlx_macos_targeting_x86 ON)
+ endif()
+ if(_mlx_macos_targeting_x86)
if(NOT MLX_ENABLE_X64_MAC)
message(
FATAL_ERROR
diff --git setup.py setup.py
index 12505bd1..db0c67c8 100644
--- setup.py
+++ setup.py
@@ -126,6 +126,9 @@ class CMakeBuild(build_ext):
if build_macos:
# Cross-compile support for macOS - respect ARCHFLAGS if set
archs = re.findall(r"-arch (\S+)", os.environ.get("ARCHFLAGS", ""))
+ # Default to native Apple-silicon when ARCHFLAGS is unset (avoids CMAKE_SYSTEM_PROCESSOR=x86_64 with universal toolchains)
+ if not archs and platform.machine() == "arm64":
+ archs = ["arm64"]
if archs:
cmake_args += ["-DCMAKE_OSX_ARCHITECTURES={}".format(";".join(archs))]
然后发现 metal 命令不存在。继续折腾。因为我没升级 macOS 26,还是 Sequoia 15.7.3,XCode从商店安装直接提示
Xcode can’t be installed on “Macintosh HD” because macOS version 26.2 or later is required.
手动:
wget https://download.developer.apple.com/Developer_Tools/Xcode_16/Xcode_16.xip
xip --expand Xcode_16.xip
sudo mv Xcode.app /Applications/
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
sudo xcodebuild -license accept
有AI代为折腾真好。
最后吐槽下,open-webui什么妖魔鬼怪。就tmd一个界面玩意也整出来好几个GB。
Comments