fix: detect Apple Silicon under Rosetta and use arm64 binaries

install.sh previously set MAC_INTEL=true unconditionally when uname
reported x86_64 on macOS, even after detecting Apple Silicon via
sysctl. This caused ARM Mac users running under Rosetta to get the
Intel llama.cpp prebuilt, skip PyTorch, and use Python 3.12.

Now when Rosetta is detected, _ARCH is overridden to arm64 so the
rest of the installer (Python version, torch, llama.cpp prebuilt)
picks the correct architecture.

Also adds matching Rosetta detection in install_llama_prebuilt.py's
detect_host() so the prebuilt resolver works correctly even when
invoked independently under Rosetta.
This commit is contained in:
Roland Tannous 2026-04-02 15:49:18 +00:00
commit 4fadb05c50
2 changed files with 17 additions and 4 deletions

View file

@ -729,12 +729,13 @@ if [ "$OS" = "macos" ] && [ "$_ARCH" = "x86_64" ]; then
# sysctl hw.optional.arm64 returns "1" on Apple Silicon even in Rosetta.
if [ "$(sysctl -in hw.optional.arm64 2>/dev/null || echo 0)" = "1" ]; then
echo ""
echo " WARNING: Apple Silicon detected, but this shell is running under Rosetta (x86_64)."
echo " Re-run install.sh from a native arm64 terminal for full PyTorch support."
echo " Continuing in GGUF-only mode for now."
echo " NOTE: Apple Silicon detected under Rosetta (x86_64 shell)."
echo " Overriding to arm64 for correct binaries."
echo ""
_ARCH="arm64"
else
MAC_INTEL=true
fi
MAC_INTEL=true
fi
if [ -n "$_USER_PYTHON" ]; then

View file

@ -1993,6 +1993,18 @@ def run_capture(
def detect_host() -> HostInfo:
system = platform.system()
machine = platform.machine().lower()
# macOS Rosetta: platform.machine() reports x86_64 on Apple Silicon.
# Detect the real hardware via sysctl so we download arm64 binaries.
if system == "Darwin" and machine in {"x86_64", "amd64"}:
try:
r = subprocess.run(
["sysctl", "-in", "hw.optional.arm64"],
capture_output=True, text=True, timeout=5,
)
if r.stdout.strip() == "1":
machine = "arm64"
except Exception:
pass
is_windows = system == "Windows"
is_linux = system == "Linux"
is_macos = system == "Darwin"