Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio installer (macOS): start the Unsloth Studio.app shortcut natively on Apple Silicon (#13305)

Daniel Han26400845c6c3
diff --git a/install.sh b/install.sh
index ce438452785..84c813e7c53 100755
--- a/install.sh
+++ b/install.sh
@@ -2308,6 +2308,11 @@ DESKTOP_EOF
<string>1.0</string>
<key>LSMinimumSystemVersion</key>
<string>10.15</string>
+ <key>LSArchitecturePriority</key>
+ <array>
+ <string>arm64</string>
+ <string>x86_64</string>
+ </array>
<key>NSHighResolutionCapable</key>
<true/>
</dict>
@@ -2317,8 +2322,12 @@ PLIST_EOF
# Single-quoted heredoc + sed so $-vars in $_css_data_dir do not expand at launch.
_css_sq_dir=$(printf '%s' "$_css_data_dir" | sed "s/'/'\\\\''/g")
_css_sed_dir=$(printf '%s' "$_css_sq_dir" | sed 's/[\\&|]/\\&/g')
+ # A script-only bundle may be started under Rosetta (#9467), and a translated shell hands the x86_64 slice of a universal2 venv python its arm64 wheels. LSArchitecturePriority asks Launch Services for arm64, and arch -arm64 also covers a bundle id whose Rosetta choice Launch Services already cached. hw.optional.arm64 is absent on Intel, so Intel keeps the plain exec.
cat > "$_css_macos_dir/launch-studio" << 'STUB_EOF'
#!/bin/sh
+if [ "$(/usr/sbin/sysctl -in hw.optional.arm64 2>/dev/null)" = "1" ] && [ -x /usr/bin/arch ]; then
+ exec /usr/bin/arch -arm64 '@@DATA_DIR@@/launch-studio.sh' "$@"
+fi
exec '@@DATA_DIR@@/launch-studio.sh' "$@"
STUB_EOF
sed "s|@@DATA_DIR@@|$_css_sed_dir|g" "$_css_macos_dir/launch-studio" \
diff --git a/tests/studio/test_macos_app_native_arch.py b/tests/studio/test_macos_app_native_arch.py
new file mode 100644
index 00000000000..063622c767f
--- /dev/null
+++ b/tests/studio/test_macos_app_native_arch.py
@@ -0,0 +1,158 @@
+# SPDX-License-Identifier: AGPL-3.0-only
+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+"""The macOS "Unsloth Studio.app" shortcut must start the launcher natively on Apple Silicon (#9467).
+
+Its executable is a shell script, which Launch Services may run under Rosetta; a translated shell
+then runs the x86_64 slice of a universal2 venv python against arm64 wheels and `unsloth` dies on
+`incompatible architecture (have 'arm64', need 'x86_64')`. The live tests rebuild the bundle from
+install.sh's own heredocs and compare it with the pre-fix shape, which must still come up
+translated on the same host, or the run proves nothing and skips.
+"""
+
+import os
+import platform
+import plistlib
+import re
+import shutil
+import subprocess
+import sys
+import time
+import uuid
+from pathlib import Path
+
+import pytest
+
+REPO_ROOT = Path(__file__).resolve().parents[2]
+INSTALL_SH = REPO_ROOT / "install.sh"
+
+ON_APPLE_SILICON = (
+ sys.platform == "darwin"
+ and subprocess.run(
+ ["/usr/sbin/sysctl", "-in", "hw.optional.arm64"], capture_output = True, text = True
+ ).stdout.strip()
+ == "1"
+)
+
+
+def _heredoc(tag: str) -> str:
+ text = INSTALL_SH.read_text(encoding = "utf-8")
+ match = re.search(rf"<< '{tag}'\n(.*?)\n{tag}\n", text, re.S)
+ assert match, f"install.sh lost its {tag} heredoc"
+ return match.group(1) + "\n"
+
+
+def _plist() -> dict:
+ return plistlib.loads(_heredoc("PLIST_EOF").encode())
+
+
+def _old_stub() -> str:
+ return "#!/bin/sh\nexec '@@DATA_DIR@@/launch-studio.sh' \"$@\"\n"
+
+
+def _old_plist() -> dict:
+ plist = _plist()
+ plist.pop("LSArchitecturePriority", None)
+ return plist
+
+
+def test_plist_asks_for_arm64_first() -> None:
+ assert _plist()["LSArchitecturePriority"][0] == "arm64"
+
+
+def test_stub_keeps_a_plain_exec_for_intel() -> None:
+ stub = _heredoc("STUB_EOF")
+ assert "/usr/bin/arch -arm64 '@@DATA_DIR@@/launch-studio.sh'" in stub
+ assert stub.rstrip().endswith("exec '@@DATA_DIR@@/launch-studio.sh' \"$@\"")
+
+
[email protected](shutil.which("sh") is None, reason = "no POSIX sh on this runner")
+def test_stub_parses(tmp_path: Path) -> None:
+ (tmp_path / "stub").write_text(_heredoc("STUB_EOF"), encoding = "utf-8")
+ subprocess.run(["sh", "-n", "stub"], cwd = tmp_path, check = True)
+
+
+def _rosetta_available() -> bool:
+ return (
+ subprocess.run(
+ ["/usr/bin/arch", "-x86_64", "/usr/bin/true"], capture_output = True
+ ).returncode
+ == 0
+ )
+
+
+needs_rosetta = pytest.mark.skipif(
+ not ON_APPLE_SILICON or not _rosetta_available(),
+ reason = "needs an Apple Silicon Mac with Rosetta 2 installed",
+)
+
+
+def _data_dir(tmp_path: Path, name: str) -> Path:
+ data = tmp_path / name
+ data.mkdir()
+ probe = data / "launch-studio.sh"
+ # proc_translated reads 1 only inside a Rosetta-translated process.
+ probe.write_text(
+ "#!/bin/bash\n"
+ 'printf "%s %s\\n" "$(/usr/sbin/sysctl -in sysctl.proc_translated)" "$(uname -m)" '
+ f"> '{data}/arch.txt'\n",
+ encoding = "utf-8",
+ )
+ probe.chmod(0o755)
+ return data
+
+
+def _write_stub(path: Path, stub: str, data: Path) -> None:
+ path.write_text(stub.replace("@@DATA_DIR@@", str(data)), encoding = "utf-8")
+ path.chmod(0o755)
+
+
+def _read_arch(data: Path, timeout: float = 30.0) -> str:
+ out = data / "arch.txt"
+ deadline = time.monotonic() + timeout
+ while time.monotonic() < deadline:
+ if out.exists() and out.read_text(encoding = "utf-8").strip():
+ return out.read_text(encoding = "utf-8").strip()
+ time.sleep(0.25)
+ pytest.fail(f"launcher never wrote {out}")
+
+
+@needs_rosetta
+def test_stub_returns_a_translated_launch_to_arm64(tmp_path: Path) -> None:
+ results = {}
+ for name, stub in (("old", _old_stub()), ("new", _heredoc("STUB_EOF"))):
+ data = _data_dir(tmp_path, name)
+ stub_path = tmp_path / f"{name}-stub"
+ _write_stub(stub_path, stub, data)
+ subprocess.run(["/usr/bin/arch", "-x86_64", "/bin/sh", str(stub_path)], check = True)
+ results[name] = _read_arch(data)
+ assert results["old"].startswith("1 "), f"control did not run translated: {results}"
+ assert results["new"] == "0 arm64", results
+
+
+def _build_app(tmp_path: Path, name: str, plist: dict, stub: str) -> tuple[Path, Path]:
+ data = _data_dir(tmp_path, name)
+ app = tmp_path / f"{name}.app"
+ (app / "Contents" / "MacOS").mkdir(parents = True)
+ # A fresh bundle id per run: Launch Services caches its architecture choice per id.
+ plist = dict(plist, CFBundleIdentifier = f"ai.unsloth.studio.test.{name}.{uuid.uuid4().hex}")
+ (app / "Contents" / "Info.plist").write_bytes(plistlib.dumps(plist))
+ _write_stub(app / "Contents" / "MacOS" / plist["CFBundleExecutable"], stub, data)
+ return app, data
+
+
+@needs_rosetta
+def test_app_bundle_launches_natively(tmp_path: Path) -> None:
+ old_app, old_data = _build_app(tmp_path, "old", _old_plist(), _old_stub())
+ new_app, new_data = _build_app(tmp_path, "new", _plist(), _heredoc("STUB_EOF"))
+ subprocess.run(["open", "-n", str(old_app)], check = True)
+ old = _read_arch(old_data)
+ subprocess.run(["open", "-n", str(new_app)], check = True)
+ new = _read_arch(new_data)
+ print(f"pre-fix bundle: {old!r}, fixed bundle: {new!r}, macOS {platform.mac_ver()[0]}")
+ assert new == "0 arm64", f"fixed bundle ran {new!r} (pre-fix bundle ran {old!r})"
+ if not old.startswith("1 "):
+ pytest.skip(
+ reason = f"Launch Services ran the pre-fix bundle natively here ({old!r}): "
+ "this host does not reproduce the Rosetta launch, only the fixed result is shown"
+ )