mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-06 00:08:52 +00:00
Made by tools/layout/move_0216.py (the commit before this one) on db8e0be9c, the final code head of 0.2.16:
- 75 git mv (renames, so `git log --follow` and blame keep working; packaging/acceptance_matrix.md shows as delete + add because its links
changed too) and 3 removals: SETUP.bat, UPDATE.bat and update.sh (setup.py --update pulls the code now);
- 1,425 path edits in 307 files: root-relative paths in CI, Docker, .gitignore and the release scripts; Markdown links; Python and
Node joins from a root that moved with its folder; explicit edits for code that computes a root or names a moved path; tables of
repository paths inside tests.
engine/ holds what CMake builds (src, include, cmake, metal, sycl, spark, third_party, the C++ tests and benches). app/ is the desktop
app and its host (was apps/). terminal/ is the Terminal in the layout of the installed one (strata.py, setup.py, strata_cli,
strata_control, serve, bin, data, ref, crates, the Python tools and tests). docs/ has the documentation, docs/lang/ the translated
READMEs, docs/history and docs/bench-results. tools/ has the repository's own checks, packaging, docker, research and nix.
tests/core/test_tqp_ref.py is a pytest file and stays with the Python tests (terminal/tests/core/).
AGENTS.md, README.md, LICENSE, setup.sh and START-HERE.bat stay at the root.
No behaviour change: the same command lines, the same sources. For this head a replay of the script gave the same numbers and the path
scan (tools/layout/checks/path_scan.py) reports no hit; the suites and the builds run on this commit next.
103 lines
6.7 KiB
Bash
103 lines
6.7 KiB
Bash
#!/bin/bash
|
|
# Build the Qwen engine package for Apple Silicon (backend metal): `strata` + `strata-vision` + the Metal sources the engine compiles at start-up.
|
|
# This is the repository's version of the release scripts' Mac stage (phaseA-tests/rel213/scripts/mac_rel213.sh, rel212/scripts/mac_rel212.sh), so a release
|
|
# builds the Mac Qwen package from the tag itself.
|
|
#
|
|
# bash tools/packaging/mac/build_engine.sh --version 0.1.59 [--work DIR] [--build-id ID] [--jobs N] [--stages "engine vision pkg"]
|
|
#
|
|
# Run it in the source tree (a git checkout, or a `git archive` with BUILD_ID beside the sources) on the Mac, under the machine's lock. Stages (default all):
|
|
# engine cmake + ninja: the `strata` target of engine/metal/ vision tools/packaging/build_vision_mac.sh: strata-vision (Metal GPU reader, CPU fallback)
|
|
# pkg stage the files, package_engine.py, --verify, binary_deps.py, `strata --version`
|
|
# It does NOT sign: the package made here is unsigned (tools/packaging/mac/sign-and-notarize.sh --engine signs the folder form; see tools/packaging/ENGINE-COMPONENT.md).
|
|
#
|
|
# ggml's sources are the vendored engine/third_party/strata-ggml (the reader is Strata's own): nothing is downloaded. STRATA_GGML_DIR=<llama.cpp checkout>
|
|
# builds from that checkout instead (an override, kept for two releases). Needs Xcode Command Line Tools, cmake + ninja (a pip venv is enough) and Apple's
|
|
# metal-cpp (METAL_CPP_DIR, default ~/strata-mac/metal-cpp).
|
|
#
|
|
# Layout of the package (the engine finds these beside its executable, engine/metal/src/resource_path.h):
|
|
# strata, strata-vision, BUILD.json
|
|
# metal/kernels/*.metal metal/engine-msl/*.metal metal/data/{expert-profile.bin,draft_vocab.bin}
|
|
# metal/strata-quant-common.h the quant header's TEXT (the runtime reads it: it cannot follow an #include). It is the generated file
|
|
# engine/include/strata/quant/strata-quant-common.h, NOT engine/third_party/ggml/ggml-common.h, which is only a one-line forwarder.
|
|
# metal/ggml-common.h the same text under the old name, kept for two releases (an engine of an earlier release reads this name)
|
|
set -eo pipefail
|
|
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
|
VERSION=""
|
|
WORK="$ROOT/pkg-mac-work"
|
|
BUILD_ID=""
|
|
JOBS=2
|
|
STAGES="engine vision pkg"
|
|
while [ $# -gt 0 ]; do
|
|
case "$1" in
|
|
--version) VERSION="$2"; shift 2;;
|
|
--work) WORK="$2"; shift 2;;
|
|
--build-id) BUILD_ID="$2"; shift 2;;
|
|
--jobs) JOBS="$2"; shift 2;;
|
|
--stages) STAGES="$2"; shift 2;;
|
|
*) echo "usage: $0 --version V [--work DIR] [--build-id ID] [--jobs N] [--stages \"engine vision pkg\"]"; exit 2;;
|
|
esac
|
|
done
|
|
[ -n "$VERSION" ] || { echo "--version is required (the engine version of the release, e.g. 0.1.59)"; exit 2; }
|
|
has() { case " $STAGES " in *" $1 "*) return 0;; esac; return 1; }
|
|
CMAKE=${CMAKE:-$(command -v cmake || echo "$HOME/strata-mac/tools/bin/cmake")}
|
|
NINJA=${NINJA:-$(command -v ninja || echo "$HOME/strata-mac/tools/bin/ninja")}
|
|
METAL_CPP_DIR=${METAL_CPP_DIR:-$HOME/strata-mac/metal-cpp}
|
|
if [ -z "$BUILD_ID" ]; then # the commit the binary is built from: the tree's own git, else a BUILD_ID file beside the sources
|
|
BUILD_ID=$(git -C "$ROOT" rev-parse --short=9 HEAD 2>/dev/null || head -1 "$ROOT/BUILD_ID" 2>/dev/null || echo unknown)
|
|
fi
|
|
[ "$BUILD_ID" != unknown ] || { echo "no build id: build from a git checkout, put the commit in BUILD_ID, or pass --build-id"; exit 2; }
|
|
GGML=""; [ -z "${STRATA_GGML_DIR:-}" ] || GGML="-DSTRATA_GGML_DIR=$STRATA_GGML_DIR" # override only; default the vendored engine/third_party/strata-ggml
|
|
VISION_LLAMA=""; [ -z "${STRATA_GGML_DIR:-}" ] || VISION_LLAMA="--llama $STRATA_GGML_DIR"
|
|
BUILD="$WORK/metal-build"
|
|
STAGE="$WORK/stage-metal"
|
|
OUT="$WORK/pkg-mac"
|
|
PKG="$OUT/$VERSION-macos-arm64-metal"
|
|
mkdir -p "$WORK"
|
|
cd "$ROOT"
|
|
export STRATA_COMMIT=${STRATA_COMMIT:-$BUILD_ID}
|
|
export CMAKE_BUILD_PARALLEL_LEVEL=$JOBS
|
|
|
|
if has engine; then
|
|
echo "== metal engine build (strata)"
|
|
rm -rf "$BUILD"
|
|
# shellcheck disable=SC2086
|
|
nice -n 19 "$CMAKE" -S engine/metal -B "$BUILD" -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_MAKE_PROGRAM="$NINJA" -DMETAL_CPP_DIR="$METAL_CPP_DIR" $GGML \
|
|
-DSTRATA_BUILD_ID="$BUILD_ID" > "$WORK/metal-cfg.log" 2>&1 || { tail -30 "$WORK/metal-cfg.log"; exit 1; }
|
|
nice -n 19 "$NINJA" -j"$JOBS" -C "$BUILD" strata > "$WORK/metal-build.log" 2>&1 || { tail -30 "$WORK/metal-build.log"; exit 1; }
|
|
tail -3 "$WORK/metal-build.log"
|
|
fi
|
|
|
|
if has vision; then
|
|
echo "== strata-vision (Metal GPU reader + CPU fallback)"
|
|
rm -rf "$WORK/vision-out"
|
|
# shellcheck disable=SC2086
|
|
nice -n 19 bash tools/packaging/build_vision_mac.sh $VISION_LLAMA --out "$WORK/vision-out" --build "$WORK/vision-build" --jobs "$JOBS"
|
|
fi
|
|
|
|
if has pkg; then
|
|
echo "== metal engine package (strata + strata-vision)"
|
|
QUANT=engine/include/strata/quant/strata-quant-common.h
|
|
[ -f "$QUANT" ] && grep -q "^#ifndef GGML_COMMON_DECL$" "$QUANT" || { echo "$QUANT is missing or is not the header text"; exit 1; }
|
|
rm -rf "$STAGE"; mkdir -p "$STAGE/metal/kernels" "$STAGE/metal/engine-msl" "$STAGE/metal/data"
|
|
cp "$BUILD/strata" "$STAGE/"
|
|
cp "$WORK/vision-out/strata-vision" "$STAGE/" # BEFORE package_engine.py: it takes strata-vision from --src
|
|
cp engine/metal/kernels/*.metal "$STAGE/metal/kernels/"
|
|
cp engine/metal/src/engine/msl/*.metal "$STAGE/metal/engine-msl/"
|
|
cp "$QUANT" "$STAGE/metal/strata-quant-common.h"
|
|
cp "$QUANT" "$STAGE/metal/ggml-common.h" # the old name, same text, for two releases
|
|
cp terminal/data/expert-profile.bin terminal/data/draft_vocab.bin "$STAGE/metal/data/"
|
|
echo '{"version": "'"$VERSION"'", "source": "tools/packaging/mac/build_engine.sh '"$BUILD_ID"'", "backend": "metal", "kernels": "compiled at start from engine/metal/ beside the binary", "portable": true, "vision": "metal"}' > "$STAGE/BUILD.json"
|
|
rm -rf "$OUT"; mkdir -p "$OUT"
|
|
python3 tools/packaging/package_engine.py --src "$STAGE" --backend metal --version "$VERSION" --out "$OUT" --arch apple-gpu --build-id "$BUILD_ID+metal" --platform macos-arm64 --tree
|
|
python3 tools/packaging/package_engine.py --verify "$PKG"
|
|
python3 tools/packaging/binary_deps.py "$PKG"
|
|
python3 tools/packaging/binary_deps.py --mac-min-os "$PKG" # #4634: strata and strata-vision start on the app's minimum macOS
|
|
test -f "$PKG/strata-vision" || { echo "strata-vision is not in the Mac engine package"; exit 1; }
|
|
# the quant header must be the text in the package, under both names (a forwarder there would leave the Metal kernels without their block layouts)
|
|
for n in strata-quant-common.h ggml-common.h; do
|
|
cmp "$PKG/metal/$n" "$QUANT" || { echo "metal/$n in the package is not the header text"; exit 1; }
|
|
done
|
|
"$PKG/strata" --version
|
|
echo "== done: $PKG (unsigned)"
|
|
fi
|