diff --git a/.github/workflows/backends.yml b/.github/workflows/backends.yml index add8c8cdd6..61dbfa1b12 100644 --- a/.github/workflows/backends.yml +++ b/.github/workflows/backends.yml @@ -6,7 +6,7 @@ name: Backend compile checks # HIP (ROCm 7.2) rocm/dev container target strata (CMake preset hip-compile) # SYCL (oneAPI 2026.1) ubuntu + Intel's apt repo target strata of sycl/ (the commands of packaging/build_sycl_linux.sh) # Metal macOS runner targets strata and strata_ds4 (metal/; metal-build.yml keeps its own strata build) -# llama.cpp (ggml) comes at the commit pinned in setup.py (LLAMA_CPP_COMMIT), the same one the release builds use. +# ggml comes from the vendored third_party/strata-ggml (frozen at llama.cpp's pin), the same tree the release builds use: nothing is downloaded. # Architectures are fewer than the release package's (compile time); the flags that decide which sources and defines are built are the release's. on: @@ -76,12 +76,6 @@ jobs: - uses: actions/checkout@v4 with: persist-credentials: false - - name: llama.cpp (ggml) at the pinned commit - run: | - commit=$(sed -n 's/^LLAMA_CPP_COMMIT = "\(.*\)"/\1/p' setup.py) - mkdir llama.cpp && cd llama.cpp && git init -q - git remote add origin https://github.com/ggml-org/llama.cpp.git - git fetch -q --depth 1 origin "$commit" && git checkout -q FETCH_HEAD - uses: actions/cache@v4 with: path: .ccache @@ -90,7 +84,7 @@ jobs: - name: Configure (preset cuda-compile) run: | nvcc --version | tail -2 - cmake --preset cuda-compile -B build -DSTRATA_GGML_DIR="$PWD/llama.cpp" \ + cmake --preset cuda-compile -B build \ "-DCMAKE_CUDA_ARCHITECTURES=${{ matrix.archs }}" -DSTRATA_EXPERIMENTAL_SM60=${{ matrix.sm60 }} \ -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_CUDA_COMPILER_LAUNCHER=ccache - name: Build strata and strata_kq @@ -112,12 +106,6 @@ jobs: - uses: actions/checkout@v4 with: persist-credentials: false - - name: llama.cpp (ggml) at the pinned commit - run: | - commit=$(sed -n 's/^LLAMA_CPP_COMMIT = "\(.*\)"/\1/p' setup.py) - mkdir llama.cpp && cd llama.cpp && git init -q - git remote add origin https://github.com/ggml-org/llama.cpp.git - git fetch -q --depth 1 origin "$commit" && git checkout -q FETCH_HEAD - uses: actions/cache@v4 with: path: .ccache @@ -126,7 +114,7 @@ jobs: - name: Configure (preset hip-compile) run: | /opt/rocm/llvm/bin/clang++ --version | head -1 - cmake --preset hip-compile -B build -DSTRATA_GGML_DIR="$PWD/llama.cpp" \ + cmake --preset hip-compile -B build \ -DCMAKE_HIP_COMPILER=/opt/rocm/llvm/bin/clang++ -DCMAKE_HIP_COMPILER_ROCM_ROOT=/opt/rocm -DCMAKE_PREFIX_PATH=/opt/rocm \ -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_HIP_COMPILER_LAUNCHER=ccache - name: Build strata @@ -155,12 +143,6 @@ jobs: - uses: actions/checkout@v4 with: persist-credentials: false - - name: llama.cpp (ggml) at the pinned commit - run: | - commit=$(sed -n 's/^LLAMA_CPP_COMMIT = "\(.*\)"/\1/p' setup.py) - mkdir llama.cpp && cd llama.cpp && git init -q - git remote add origin https://github.com/ggml-org/llama.cpp.git - git fetch -q --depth 1 origin "$commit" && git checkout -q FETCH_HEAD - uses: actions/cache@v4 with: path: .ccache @@ -172,7 +154,7 @@ jobs: . /opt/intel/oneapi/setvars.sh --force >/dev/null icpx --version | head -1 cmake -S sycl -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx \ - -DSTRATA_SYCL_PARITY=OFF -DSTRATA_SYCL_IQ_DECODE_FAST=ON -DSTRATA_GGML_DIR="$PWD/llama.cpp" \ + -DSTRATA_SYCL_PARITY=OFF -DSTRATA_SYCL_IQ_DECODE_FAST=ON \ -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache cmake --build build --target strata -j "$(nproc)" - name: Cache statistics @@ -198,12 +180,6 @@ jobs: curl -fsSL "$METAL_CPP_URL" -o metal-cpp.zip echo "$METAL_CPP_SHA256 metal-cpp.zip" | shasum -a 256 -c - unzip -q metal-cpp.zip -d _mcpp - - name: llama.cpp (ggml) at the pinned commit - run: | - commit=$(sed -n 's/^LLAMA_CPP_COMMIT = "\(.*\)"/\1/p' setup.py) - mkdir llama.cpp && cd llama.cpp && git init -q - git remote add origin https://github.com/ggml-org/llama.cpp.git - git fetch -q --depth 1 origin "$commit" && git checkout -q FETCH_HEAD - uses: actions/cache@v4 with: path: .ccache @@ -212,7 +188,7 @@ jobs: - name: Configure run: | cmake -S metal -B build-metal -G Ninja -DCMAKE_BUILD_TYPE=Release \ - -DMETAL_CPP_DIR="$PWD/_mcpp/metal-cpp" -DSTRATA_GGML_DIR="$PWD/llama.cpp" \ + -DMETAL_CPP_DIR="$PWD/_mcpp/metal-cpp" \ -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache - name: Build and link strata and strata_ds4 run: cmake --build build-metal --target strata strata_ds4 diff --git a/.github/workflows/metal-build.yml b/.github/workflows/metal-build.yml index a4f7d99704..14371e2c6e 100644 --- a/.github/workflows/metal-build.yml +++ b/.github/workflows/metal-build.yml @@ -25,8 +25,7 @@ jobs: runs-on: macos-26 timeout-minutes: 45 env: - # setup.py's LLAMA_CPP_COMMIT and metal/setup_mac.py's metal-cpp pin - LLAMA_CPP_COMMIT: 3cf03257f219afbe7334045ff7c6a06ac68c627d + # metal/setup_mac.py's metal-cpp pin (ggml is the vendored third_party/strata-ggml) METAL_CPP_URL: https://developer.apple.com/metal/cpp/files/metal-cpp_26.zip METAL_CPP_SHA256: 4df3c078b9aadcb516212e9cb03004cbc5ce9a3e9c068fa3144d021db585a3a4 steps: @@ -38,16 +37,8 @@ jobs: curl -fsSL "$METAL_CPP_URL" -o metal-cpp.zip echo "$METAL_CPP_SHA256 metal-cpp.zip" | shasum -a 256 -c - unzip -q metal-cpp.zip -d _mcpp - - name: llama.cpp (ggml) at the pinned commit - run: | - mkdir llama.cpp && cd llama.cpp - git init -q - git remote add origin https://github.com/ggml-org/llama.cpp.git - git fetch -q --depth 1 origin "$LLAMA_CPP_COMMIT" - git checkout -q FETCH_HEAD - name: Configure run: | cmake -S metal -B build-metal -G Ninja -DCMAKE_BUILD_TYPE=Release \ - -DMETAL_CPP_DIR="$PWD/_mcpp/metal-cpp" -DSTRATA_GGML_DIR="$PWD/llama.cpp" - - name: Build and link the engine + -DMETAL_CPP_DIR="$PWD/_mcpp/metal-cpp" - name: Build and link the engine run: cmake --build build-metal --target strata diff --git a/CMakePresets.json b/CMakePresets.json index a53f5dbe4d..5c463caa5e 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -24,7 +24,7 @@ { "name": "cuda-compile", "displayName": "CUDA compile-only (the release flags of packaging/build_cuda_linux.sh, no tests)", - "description": "Builds the strata and strata_kq targets for the given CUDA architectures. No GPU is needed to compile; nothing is run. ggml is the vendored third_party/strata-ggml; -DSTRATA_GGML_DIR= overrides it (CI still passes one).", + "description": "Builds the strata and strata_kq targets for the given CUDA architectures. No GPU is needed to compile; nothing is run. ggml is the vendored third_party/strata-ggml; -DSTRATA_GGML_DIR= overrides it.", "generator": "Ninja", "binaryDir": "${sourceDir}/build/${presetName}", "cacheVariables": { diff --git a/Dockerfile b/Dockerfile index eba34a0112..509f9ed8ee 100644 --- a/Dockerfile +++ b/Dockerfile @@ -32,8 +32,9 @@ ARG CUDA_ARCHITECTURES="75;80;86;89;120" ARG BUILD_VISION=1 ARG ENGINE_VERSION= RUN python3 -m venv /venv && /venv/bin/pip install --no-cache-dir -r requirements.txt -r requirements-build.txt -# llama.cpp at the pinned commit (ggml for the engine, mtmd for pictures), exactly as setup.py fetches it -RUN /venv/bin/python -c "import setup; print(setup.get_llama_cpp())" +# ggml comes from the vendored third_party/strata-ggml (nothing is downloaded). strata-vision still builds from llama.cpp's own tree until it is +# vendored: fetched only for that +RUN if [ "$BUILD_VISION" = "1" ]; then /venv/bin/python -c "import setup; print(setup.get_llama_cpp())"; fi RUN set -e; \ real=""; for a in $(echo "$CUDA_ARCHITECTURES" | tr ';,' ' '); do real="$real;${a}-real"; done; real=${real#;}; \ last=$(echo "$CUDA_ARCHITECTURES" | tr ';,' ' ' | awk '{print $NF}'); \ @@ -41,7 +42,7 @@ RUN set -e; \ /venv/bin/cmake -G Ninja -S . -B build -DCMAKE_BUILD_TYPE=Release -DSTRATA_ENABLE_CUDA=ON -DSTRATA_BUILD_TESTS=OFF \ -DSTRATA_EXPERIMENTAL_SM60=$sm60 \ -DSTRATA_NATIVE_EXPERTS=ON -DSTRATA_PORTABLE=ON -DSTRATA_Q6K_EXPERTS=ON -DSTRATA_MMQ_KQUANTS=ON \ - "-DCMAKE_CUDA_ARCHITECTURES=${real};${last}-virtual" -DSTRATA_GGML_DIR=/src/third_party/llama.cpp; \ + "-DCMAKE_CUDA_ARCHITECTURES=${real};${last}-virtual"; \ /venv/bin/cmake --build build --target strata strata_kq -j "$(nproc)"; \ if [ "$BUILD_VISION" = "1" ]; then \ /venv/bin/cmake -G Ninja -S tools/vision -B build-vision -DCMAKE_BUILD_TYPE=Release -DLLAMA_DIR=/src/third_party/llama.cpp \ @@ -78,15 +79,9 @@ RUN python3 /src/packaging/package_terminal.py --out /out --cache /cache \ && tar -xzf /out/strata-terminal-*-linux-x86_64.tar.gz -C /opt/strata \ && mv /opt/strata/strata-terminal-* /opt/strata/terminal \ && /opt/strata/terminal/bin/strata --version -# llama.cpp at the commit setup.py pins: fetched here, so the first start does not depend on GitHub. Only gguf-py (the model preparation -# tools) and the file setup.py looks for (ggml/CMakeLists.txt) are kept: 170 MB become a few -RUN cd /opt/strata/terminal && STRATA_CONTROL_INSTALL=1 STRATA_INSTALL_DIR=/opt/strata/seed PYTHONNOUSERSITE=1 \ - /opt/strata/terminal/python/bin/python3 -c "import setup; print(setup.get_llama_cpp())" \ - && rm -rf /opt/strata/seed/third_party/*.zip* \ - && cd /opt/strata/seed/third_party/llama.cpp \ - && find . -mindepth 1 -maxdepth 1 ! -name gguf-py ! -name ggml ! -name 'LICENSE*' -exec rm -rf {} + \ - && find ggml -mindepth 1 -depth ! -type d ! -name CMakeLists.txt -delete && find ggml -mindepth 1 -type d -empty -delete \ - && du -sh /opt/strata/seed +# gguf-py (the model preparation tools) is part of the Terminal archive (third_party/strata-gguf-py), so the first start fetches nothing from +# GitHub and the image needs no llama.cpp: check that it is there +RUN test -f /opt/strata/terminal/third_party/strata-gguf-py/gguf/__init__.py # ---- 3. the runtime image (the same as docker/Dockerfile's, FLAVOR=cuda) FROM ${RUNTIME_BASE} @@ -95,7 +90,6 @@ ENV DEBIAN_FRONTEND=noninteractive RUN apt-get update && apt-get install -y --no-install-recommends tini ca-certificates libgomp1 libatomic1 libnuma1 zlib1g \ && rm -rf /var/lib/apt/lists/* /var/cache/apt/* COPY --from=terminal /opt/strata/terminal /opt/strata/terminal -COPY --from=terminal /opt/strata/seed /opt/strata/seed COPY --from=engine-build /engine/ /opt/strata/components/engine/ COPY docker/entrypoint.sh docker/healthcheck.sh /opt/strata/ COPY docker/strata-wrapper.sh /usr/local/bin/strata diff --git a/docker/Dockerfile b/docker/Dockerfile index 44efa5f4cd..548999fc9e 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -39,15 +39,9 @@ RUN python3 /src/packaging/package_terminal.py --out /out --cache /cache \ && tar -xzf /out/strata-terminal-*-linux-x86_64.tar.gz -C /opt/strata \ && mv /opt/strata/strata-terminal-* /opt/strata/terminal \ && /opt/strata/terminal/bin/strata --version -# llama.cpp at the commit setup.py pins: fetched here, so the first start does not depend on GitHub. Only gguf-py (the model preparation -# tools) and the file setup.py looks for (ggml/CMakeLists.txt) are kept: 170 MB become a few -RUN cd /opt/strata/terminal && STRATA_CONTROL_INSTALL=1 STRATA_INSTALL_DIR=/opt/strata/seed PYTHONNOUSERSITE=1 \ - /opt/strata/terminal/python/bin/python3 -c "import setup; print(setup.get_llama_cpp())" \ - && rm -rf /opt/strata/seed/third_party/*.zip* \ - && cd /opt/strata/seed/third_party/llama.cpp \ - && find . -mindepth 1 -maxdepth 1 ! -name gguf-py ! -name ggml ! -name 'LICENSE*' -exec rm -rf {} + \ - && find ggml -mindepth 1 -depth ! -type d ! -name CMakeLists.txt -delete && find ggml -mindepth 1 -type d -empty -delete \ - && du -sh /opt/strata/seed +# gguf-py (the model preparation tools) is part of the Terminal archive (third_party/strata-gguf-py), so the first start fetches nothing from +# GitHub and the image needs no llama.cpp: check that it is there +RUN test -f /opt/strata/terminal/third_party/strata-gguf-py/gguf/__init__.py # ---- 2. the engine package, checked before it is allowed into the image: every file's hash, and every library it imports is # bundled or belongs to the OS / GPU driver (packaging/binary_deps.py, the check the packager runs) @@ -82,7 +76,6 @@ RUN set -e; \ rm -rf /var/lib/apt/lists/* /var/cache/apt/* COPY --from=terminal /opt/strata/terminal /opt/strata/terminal -COPY --from=terminal /opt/strata/seed /opt/strata/seed COPY --from=verify /engine/ /opt/strata/components/engine/ COPY docker/entrypoint.sh docker/healthcheck.sh /opt/strata/ COPY docker/strata-wrapper.sh /usr/local/bin/strata diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 767480cbb0..64297e224b 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -56,10 +56,6 @@ if [ "$#" -gt 0 ] && [ "$1" != "run" ] && [ "$1" != "serve" ]; then fi mkdir -p /data/state /data/home /data/install /data/Strata-data /run 2>/dev/null || die "/data is not writable. Mount a volume there: -v strata-data:/data" -# llama.cpp at the pinned commit is part of the image: link it into the install folder, so the first start fetches nothing from GitHub -if [ -d /opt/strata/seed/third_party/llama.cpp ] && [ ! -e /data/install/third_party/llama.cpp ]; then - mkdir -p /data/install/third_party && ln -s /opt/strata/seed/third_party/llama.cpp /data/install/third_party/llama.cpp -fi if ! grep -q " /data " /proc/self/mountinfo 2>/dev/null; then warn "/data is not a volume, so the model and your settings are lost when this container is removed. Add: -v strata-data:/data" fi diff --git a/metal/setup_mac.py b/metal/setup_mac.py index 2e725ca3f5..ee9ad788be 100644 --- a/metal/setup_mac.py +++ b/metal/setup_mac.py @@ -7,7 +7,7 @@ What it does, each step skipped when it is already done: 1. checks the Mac: Apple Silicon, the chip, unified memory, macOS version, the Command Line Tools, free disk 2. recommends a model by memory (recommend, never force: an explicit --model is kept, with what it risks) 3. installs the Python packages into .venv (cmake and ninja come from pip, just before step 4: no Homebrew, no sudo) - 4. builds the Metal engine from source: metal-cpp (Apple's headers) and llama.cpp's ggml at the pinned commit + 4. builds the Metal engine from source: metal-cpp (Apple's headers) and the vendored ggml (third_party/strata-ggml) 5. downloads the model (setup.py's downloader: resumable, the pinned revision) 6. prepares the model: the native pack (tools/iq_pack.py) and the MTP draft layer (tools/mtp_fetch.py, mtp_pack.py) 7. writes strata-.json and run-.sh with the Metal defaults (--spec 2, the Q8_0 hyper-connection @@ -115,9 +115,9 @@ def engine_current() -> bool: def source_digest() -> str: """What the engine is built from: every source file's path, size and modification time (src/, include/, metal/, - third_party/ggml). A git pull, an unzipped update or a local edit changes it; nothing else does.""" + third_party/ggml, third_party/strata-ggml). A git pull, an unzipped update or a local edit changes it; nothing else does.""" h = hashlib.sha256() - for d in ("src", "include", "metal", "third_party/ggml"): + for d in ("src", "include", "metal", "third_party/ggml", "third_party/strata-ggml"): for f in sorted((ROOT / d).rglob("*")): if f.is_file() and f.suffix in (".cpp", ".cu", ".h", ".hpp", ".mm", ".metal", ".inc", ".txt", ".cuh"): st = f.stat() @@ -137,7 +137,7 @@ def build_engine(llama: Path, jobs: int | None = None) -> Path: log = BUILD_DIR / "build.log" env = dict(os.environ, PATH=str(Path(sys.executable).parent) + os.pathsep + os.environ.get("PATH", "")) cfg = [tool("cmake"), "-S", str(ROOT / "metal"), "-B", str(BUILD_DIR), "-G", "Ninja", "-DCMAKE_BUILD_TYPE=Release", - f"-DCMAKE_MAKE_PROGRAM={tool('ninja')}", f"-DMETAL_CPP_DIR={mcpp}", f"-DSTRATA_GGML_DIR={llama}"] + f"-DCMAKE_MAKE_PROGRAM={tool('ninja')}", f"-DMETAL_CPP_DIR={mcpp}", *S.ggml_defs(llama)] build = [tool("ninja"), "-C", str(BUILD_DIR), "strata"] + (["-j", str(jobs)] if jobs else []) with open(log, "w", encoding="utf-8") as f: for cmd in (cfg, build): @@ -182,7 +182,7 @@ def build_vision(llama: Path) -> Path: log = ROOT / "build-vision.log" with open(log, "w", encoding="utf-8") as f: for cmd in ([tool("cmake"), "-S", str(ROOT / "tools" / "vision"), "-B", str(ROOT / "build-vision"), "-G", "Ninja", - "-DCMAKE_BUILD_TYPE=Release", f"-DCMAKE_MAKE_PROGRAM={tool('ninja')}", f"-DLLAMA_DIR={llama}", + "-DCMAKE_BUILD_TYPE=Release", f"-DCMAKE_MAKE_PROGRAM={tool('ninja')}", f"-DLLAMA_DIR={S.vision_llama(llama)}", "-DSTRATA_VISION_CUDA=OFF", "-DSTRATA_VISION_METAL=ON", "-DSTRATA_PORTABLE=OFF"], [tool("ninja"), "-C", str(ROOT / "build-vision"), "strata-vision"]): if subprocess.call(cmd, stdout=f, stderr=subprocess.STDOUT, env=env) != 0: @@ -473,7 +473,7 @@ def main(argv=None) -> int: # ---- 4. the engine S.step(4, "the Strata engine (Metal)") - llama = S.get_llama_cpp() + llama = S.llama_override() # None: ggml is the vendored third_party/strata-ggml (STRATA_GGML_DIR overrides) S.ok(f"llama.cpp {S.LLAMA_CPP_COMMIT[:7]} (ggml, gguf-py)") if a.build: (BUILD_DIR / "BUILD.json").unlink(missing_ok=True) @@ -524,7 +524,7 @@ def main(argv=None) -> int: # ---- 6. the pack and the MTP draft layer S.step(6, "preparing the model for Strata") pack = S.find_in(roots, f"packs/{tag.lower()}") or data / "packs" / tag.lower() - env = dict(os.environ, STRATA_GGUF_PY=str(llama / "gguf-py")) + env = dict(os.environ, STRATA_GGUF_PY=str(S.gguf_py_dir())) # The repack and the pack move 100+ GB through the disk and the pack's python holds up to 20 GB: no engine may run beside # them (an engine of 70-90 GB with a repack froze the 128 GB M5 Max twice). A lock beside the GPU's file tells the engine # and start() to wait; a running engine stops setup here. diff --git a/packaging/build_cuda_linux.sh b/packaging/build_cuda_linux.sh index 69728ad602..2ada299029 100644 --- a/packaging/build_cuda_linux.sh +++ b/packaging/build_cuda_linux.sh @@ -4,8 +4,9 @@ # VARIANT=cuda12 packaging/build_cuda_linux.sh # CUDA 12.9: GTX 10 (Pascal), Tesla P100, V100, and the newer cards up to sm_89 # VARIANT=cuda13 packaging/build_cuda_linux.sh # CUDA 13: RTX 20 and newer (sm_75 .. sm_120) # -# Run it on a Linux x86_64 box with the CUDA toolkit of that variant on PATH (nvcc), a Python 3 venv with requirements.txt and -# requirements-build.txt, and the pinned llama.cpp in third_party/llama.cpp (python -c "import setup; setup.get_llama_cpp()"). +# Run it on a Linux x86_64 box with the CUDA toolkit of that variant on PATH (nvcc) and a Python 3 venv with requirements.txt and +# requirements-build.txt. ggml comes from the vendored third_party/strata-ggml: nothing is downloaded. STRATA_GGML_DIR= +# builds from that checkout instead (an override, kept for two releases). # The package lands in $OUT (default ./out-engine-). Nothing is uploaded. # # The cuda12 package is the one the feed and docs/DOCKER.md offer to Pascal and Volta cards, so it needs machine code for sm_60, @@ -31,12 +32,13 @@ esac real=""; for a in $(echo "$archs" | tr ';,' ' '); do real="$real;${a}-real"; done; real=${real#;} last=$(echo "$archs" | tr ';,' ' ' | awk '{print $NF}') cd "$repo" +ggml=""; [ -z "${STRATA_GGML_DIR:-}" ] || ggml="-DSTRATA_GGML_DIR=$STRATA_GGML_DIR" # STRATA_CMAKE_EXTRA: more configure arguments for the engine build, e.g. the model shape of a new family: # STRATA_CMAKE_EXTRA="-DSTRATA_GEOMETRY_FILE=/abs/path/geometry.hpp" (or -DSTRATA_GEOMETRY=) # shellcheck disable=SC2086 cmake -G Ninja -S . -B "$build" -DCMAKE_BUILD_TYPE=Release -DSTRATA_ENABLE_CUDA=ON -DSTRATA_BUILD_TESTS=OFF \ -DSTRATA_EXPERIMENTAL_SM60=$sm60 -DSTRATA_NATIVE_EXPERTS=ON -DSTRATA_PORTABLE=ON -DSTRATA_Q6K_EXPERTS=ON -DSTRATA_MMQ_KQUANTS=ON \ - "-DCMAKE_CUDA_ARCHITECTURES=${real};${last}-virtual" -DSTRATA_GGML_DIR="$repo/third_party/llama.cpp" ${STRATA_CMAKE_EXTRA:-} + "-DCMAKE_CUDA_ARCHITECTURES=${real};${last}-virtual" $ggml ${STRATA_CMAKE_EXTRA:-} cmake --build "$build" --target strata strata_kq -j "$(nproc)" # The picture reader is built for the SAME architectures as the engine (#3669: a reader reused from an older build had no sm_60, and on diff --git a/packaging/build_dsv41_cuda.sh b/packaging/build_dsv41_cuda.sh index 9a82b28df7..bac7267a8a 100644 --- a/packaging/build_dsv41_cuda.sh +++ b/packaging/build_dsv41_cuda.sh @@ -3,7 +3,7 @@ # beside `strata` (setup.py dsv41_exe() looks for strata-dsv41 in the engine folder). Same toolchain and RUNPATH rule as the # engine build: the result finds cudart/cublas beside itself ($ORIGIN), never the toolkit it was built with. # -# SRC= B= CUDA=/usr/local/cuda-13.0 GG= [ARCH="86-real;89-real;120"] [JOBS=6] packaging/build_dsv41_cuda.sh +# SRC= B= CUDA=/usr/local/cuda-13.0 [GG=] [ARCH="86-real;89-real;120"] [JOBS=6] packaging/build_dsv41_cuda.sh # # ARCH defaults to the 0.2.7 release shape: SASS for sm_86 (RTX 3090 / 3060), sm_89 (RTX 40, #3935) and sm_120 (RTX Blackwell) + PTX sm_120, i.e. # the package lists sm_86, sm_89, sm_120, compute_120 (the Windows twin built and ran on an RTX 5070; the Linux sm_86 build is the one tested on the @@ -14,7 +14,8 @@ set -eu SRC=${SRC:-$(cd "$(dirname "$0")/.." && pwd)} B=${B:?B=} CUDA=${CUDA:?CUDA=} -GG=${GG:?GG=} +GG=${GG:-} # optional override (kept for two releases): a llama.cpp checkout to take ggml from; empty: the vendored third_party/strata-ggml +ggml=""; [ -z "$GG" ] || ggml="-DSTRATA_GGML_DIR=$GG" ARCH=${ARCH:-86-real;89-real;120} JOBS=${JOBS:-6} export PATH=$CUDA/bin:$PATH @@ -27,7 +28,7 @@ fi rm -f "$B/CMakeCache.txt" "$B/strata-dsv41" cmake -G Ninja -S "$SRC" -B "$B" -DCMAKE_BUILD_TYPE=Release -DSTRATA_ENABLE_CUDA=ON -DSTRATA_BUILD_TESTS=OFF -DSTRATA_BUILD_DSV41=ON \ -DSTRATA_NATIVE_EXPERTS=ON -DSTRATA_PORTABLE=ON "-DCMAKE_CUDA_ARCHITECTURES=$ARCH" -DCMAKE_CUDA_COMPILER="$CUDA/bin/nvcc" \ - -DCUDAToolkit_ROOT="$CUDA" -DSTRATA_GGML_DIR="$GG" -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON -DCMAKE_SKIP_BUILD_RPATH=OFF \ + -DCUDAToolkit_ROOT="$CUDA" $ggml -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON -DCMAKE_SKIP_BUILD_RPATH=OFF \ '-DCMAKE_INSTALL_RPATH=$ORIGIN' ninja -j "$JOBS" -C "$B" strata-dsv41 [ -x "$B/strata-dsv41" ] || { echo "no $B/strata-dsv41" >&2; exit 1; } diff --git a/packaging/build_dsv41_hip_linux.sh b/packaging/build_dsv41_hip_linux.sh index cceb8e3ace..5815c6ca3e 100644 --- a/packaging/build_dsv41_hip_linux.sh +++ b/packaging/build_dsv41_hip_linux.sh @@ -5,7 +5,7 @@ # # VARIANT=rx7900 rx9070 (gfx1200 gfx1201) | rx7900 (gfx1100 gfx1101 gfx1102: built, NOT tested on a real RX 7000 card) | a name + ARCHS= # ARCHS="gfx1100;gfx1101;gfx1102" the code objects (default: the variant's); BUILD.json "archs" and the manifest list exactly these -# SRC= LLAMA= HP= CORE= LIBW= +# SRC= [LLAMA=] HP= CORE= LIBW= # OUT= PKGVER=0.1.58 COMMIT= JOBS=16 # NO_PACKAGE=1 stop after the stage folder # @@ -14,7 +14,8 @@ set -u V=${VARIANT:?VARIANT=rx9070|rx7900| with ARCHS=} SRC=${SRC:-$(cd "$(dirname "$0")/.." && pwd)} -LLAMA=${LLAMA:?LLAMA=} +LLAMA=${LLAMA:-} # optional override (kept for two releases): a llama.cpp checkout to take ggml from; empty: the vendored third_party/strata-ggml +ggml=""; [ -z "$LLAMA" ] || ggml="-DSTRATA_GGML_DIR=$LLAMA" HP=${HP:?HP=} CORE=${CORE:-$HP} LIBW=${LIBW:-$HP} @@ -44,7 +45,7 @@ st "start dsv41 $V ($ARCHS) commit $COMMIT" cd "$SRC" || exit 1 rm -f "$OUT/bd/CMakeCache.txt" "$OUT/bd/strata-dsv41" # (the build id is baked in at configure time: always configure again) cmake -G Ninja -S . -B "$OUT/bd" -DCMAKE_BUILD_TYPE=Release -DSTRATA_ENABLE_HIP=ON -DSTRATA_ENABLE_CUDA=OFF -DSTRATA_BUILD_TESTS=OFF \ - -DSTRATA_BUILD_DSV41=ON -DSTRATA_NATIVE_EXPERTS=ON "-DCMAKE_HIP_ARCHITECTURES=$ARCHS" "${HIPDEFS[@]}" -DSTRATA_GGML_DIR="$LLAMA" -DSTRATA_PORTABLE=ON \ + -DSTRATA_BUILD_DSV41=ON -DSTRATA_NATIVE_EXPERTS=ON "-DCMAKE_HIP_ARCHITECTURES=$ARCHS" "${HIPDEFS[@]}" $ggml -DSTRATA_PORTABLE=ON \ "-DCMAKE_EXE_LINKER_FLAGS=-Wl,-rpath,'\$ORIGIN' -Wl,--enable-new-dtags" > "$OUT/cfg-dsv41.log" 2>&1 chk $? "dsv41 configured" nice -n 10 cmake --build "$OUT/bd" --target strata-dsv41 -j "$JOBS" > "$OUT/build-dsv41.log" 2>&1 diff --git a/packaging/build_dsv41_windows.bat b/packaging/build_dsv41_windows.bat index 8faea6518d..0f4995cf73 100644 --- a/packaging/build_dsv41_windows.bat +++ b/packaging/build_dsv41_windows.bat @@ -2,7 +2,7 @@ rem strata-dsv41.exe (the DeepSeek-V4.1 engine) for NVIDIA on Windows, built next to the release engine so package_engine.py ships it rem beside strata.exe (setup.py dsv41_exe() looks for it in the engine folder). cudart is static; the only extra DLL is cublas64_13.dll, rem which package_engine.py copies from CUDA_PATH like it does for strata.exe. -rem build_dsv41_windows.bat [source dir] env: STRATA_GGML_DIR (llama.cpp), CUDA_ROOT (default CUDA 13.0), BUILD_JOBS (default 4), +rem build_dsv41_windows.bat [source dir] env: STRATA_GGML_DIR (optional override: a llama.cpp checkout, kept for two releases; default the vendored third_party/strata-ggml), CUDA_ROOT (default CUDA 13.0), BUILD_JOBS (default 4), rem DSV41_ARCH (default "86-real;89-real;120" = sm_86 + sm_89 + sm_120 SASS, PTX sm_120) rem Result: \strata-dsv41.exe (about 66 MB). Windows: only the cuda13 variant gets it (sm_120 needs CUDA 13). setlocal @@ -13,11 +13,12 @@ if "%SRCD%"=="" set "SRCD=%~dp0.." if "%CUDA_ROOT%"=="" set "CUDA_ROOT=C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v13.0" if "%DSV41_ARCH%"=="" set "DSV41_ARCH=86-real;89-real;120" if "%BUILD_JOBS%"=="" set "BUILD_JOBS=4" -if "%STRATA_GGML_DIR%"=="" ( echo set STRATA_GGML_DIR to the llama.cpp checkout & exit /b 2 ) +set "GGML=" +if defined STRATA_GGML_DIR set "GGML=-DSTRATA_GGML_DIR=%STRATA_GGML_DIR:\=/%" call "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvars64.bat" >nul 2>&1 rem configure every time: cmake bakes the build id (the commit) in at configure, so a build dir left from an older commit would print the old one if exist "%SRCD%\CMakeLists.txt" ( - cmake -G Ninja -S "%SRCD%" -B "%BD%" -DCMAKE_BUILD_TYPE=Release -DSTRATA_ENABLE_CUDA=ON -DSTRATA_BUILD_TESTS=OFF -DSTRATA_BUILD_DSV41=ON -DSTRATA_PORTABLE=ON "-DCMAKE_CUDA_ARCHITECTURES=%DSV41_ARCH%" "-DCMAKE_CUDA_COMPILER=%CUDA_ROOT%/bin/nvcc.exe" "-DCUDAToolkit_ROOT=%CUDA_ROOT%" "-DSTRATA_GGML_DIR=%STRATA_GGML_DIR%" + cmake -G Ninja -S "%SRCD%" -B "%BD%" -DCMAKE_BUILD_TYPE=Release -DSTRATA_ENABLE_CUDA=ON -DSTRATA_BUILD_TESTS=OFF -DSTRATA_BUILD_DSV41=ON -DSTRATA_PORTABLE=ON "-DCMAKE_CUDA_ARCHITECTURES=%DSV41_ARCH%" "-DCMAKE_CUDA_COMPILER=%CUDA_ROOT%/bin/nvcc.exe" "-DCUDAToolkit_ROOT=%CUDA_ROOT%" %GGML% if errorlevel 1 exit /b 1 ) rem a stale exe must not pass for this build, and the build id is baked in when cmake configures (a git checkout gives it; a tarball needs BUILD_ID) diff --git a/packaging/build_hip_linux.sh b/packaging/build_hip_linux.sh index 5cc881d1ab..af05c8174d 100644 --- a/packaging/build_hip_linux.sh +++ b/packaging/build_hip_linux.sh @@ -7,7 +7,7 @@ # VARIANT=rx9070 rx9070 (gfx1200 gfx1201) | rx7900 (gfx1100 gfx1101 gfx1102) | rx6000 (gfx1030 gfx1031) | halo (gfx1151) | igpu (gfx1103 gfx1150) | a name + ARCHS= # ARCHS="gfx1200;gfx1201" the code objects (default: the variant's) # SRC= the Strata source (default: the checkout this script is in) -# LLAMA= at the pinned commit (setup.py LLAMA_CPP_COMMIT); mtmd and ggml come from it +# LLAMA= optional override (kept for two releases): ggml (and strata-vision) come from that checkout instead of the vendored third_party/ # HP= CORE= LIBW= (TheRock: _rocm_sdk_devel, _rocm_sdk_core, _rocm_sdk_libraries_*) # OUT= PKGVER=0.1.58 COMMIT= JOBS=16 # VISION_ONLY=1 build only the two readers (no engine, no package) @@ -22,7 +22,8 @@ set -u V=${VARIANT:?VARIANT=rx9070|rx7900|rx6000|halo|igpu| with ARCHS=} SRC=${SRC:-$(cd "$(dirname "$0")/.." && pwd)} -LLAMA=${LLAMA:?LLAMA=} +LLAMA=${LLAMA:-} # an override: a llama.cpp checkout to take ggml from (kept for two releases); empty: the vendored third_party/strata-ggml +GGML=(); [ -z "$LLAMA" ] || GGML=("-DSTRATA_GGML_DIR=$LLAMA") HP=${HP:?HP=} CORE=${CORE:-$HP} LIBW=${LIBW:-$HP} @@ -61,7 +62,7 @@ if [ -z "${VISION_ONLY:-}" ]; then # STRATA_CMAKE_EXTRA: more configure arguments for the engine build, e.g. -DSTRATA_GEOMETRY_FILE=/abs/path/geometry.hpp (a new model shape) # shellcheck disable=SC2086 cmake -G Ninja -S . -B "$OUT/b" -DCMAKE_BUILD_TYPE=Release -DSTRATA_ENABLE_HIP=ON -DSTRATA_ENABLE_CUDA=OFF -DSTRATA_BUILD_TESTS=OFF \ - -DSTRATA_PREFILL_MMQ=ON "-DCMAKE_HIP_ARCHITECTURES=$ARCHS" "${HIPDEFS[@]}" -DSTRATA_GGML_DIR="$LLAMA" -DSTRATA_PORTABLE=ON \ + -DSTRATA_PREFILL_MMQ=ON "-DCMAKE_HIP_ARCHITECTURES=$ARCHS" "${HIPDEFS[@]}" ${GGML[@]+"${GGML[@]}"} -DSTRATA_PORTABLE=ON \ "-DCMAKE_EXE_LINKER_FLAGS=-Wl,-rpath,'\$ORIGIN' -Wl,--enable-new-dtags" ${STRATA_CMAKE_EXTRA:-} > "$OUT/cfg.log" 2>&1 chk $? "engine configured" nice -n 10 cmake --build "$OUT/b" --target strata -j "$JOBS" > "$OUT/build.log" 2>&1 @@ -69,7 +70,7 @@ if [ -z "${VISION_ONLY:-}" ]; then [ -x "$OUT/b/strata" ] || { st "ABORT no strata"; exit 1; } if [ "$DSV41" = 1 ]; then # own build tree: the engine's flags stay as they were; STRATA_NATIVE_EXPERTS=ON is what the DeepSeek path was built with rm -f "$OUT/bd/CMakeCache.txt" "$OUT/bd/strata-dsv41" # (the build id is baked in at configure time: always configure again) - cmake -G Ninja -S . -B "$OUT/bd" -DCMAKE_BUILD_TYPE=Release -DSTRATA_ENABLE_HIP=ON -DSTRATA_ENABLE_CUDA=OFF -DSTRATA_BUILD_TESTS=OFF -DSTRATA_BUILD_DSV41=ON -DSTRATA_NATIVE_EXPERTS=ON "-DCMAKE_HIP_ARCHITECTURES=$ARCHS" "${HIPDEFS[@]}" -DSTRATA_GGML_DIR="$LLAMA" -DSTRATA_PORTABLE=ON "-DCMAKE_EXE_LINKER_FLAGS=-Wl,-rpath,'\$ORIGIN' -Wl,--enable-new-dtags" > "$OUT/cfg-dsv41.log" 2>&1 + cmake -G Ninja -S . -B "$OUT/bd" -DCMAKE_BUILD_TYPE=Release -DSTRATA_ENABLE_HIP=ON -DSTRATA_ENABLE_CUDA=OFF -DSTRATA_BUILD_TESTS=OFF -DSTRATA_BUILD_DSV41=ON -DSTRATA_NATIVE_EXPERTS=ON "-DCMAKE_HIP_ARCHITECTURES=$ARCHS" "${HIPDEFS[@]}" ${GGML[@]+"${GGML[@]}"} -DSTRATA_PORTABLE=ON "-DCMAKE_EXE_LINKER_FLAGS=-Wl,-rpath,'\$ORIGIN' -Wl,--enable-new-dtags" > "$OUT/cfg-dsv41.log" 2>&1 chk $? "dsv41 configured" nice -n 10 cmake --build "$OUT/bd" --target strata-dsv41 -j "$JOBS" > "$OUT/build-dsv41.log" 2>&1 chk $? "dsv41 built" @@ -77,6 +78,8 @@ if [ -z "${VISION_ONLY:-}" ]; then [ -x "$OUT/bd/strata-dsv41" ] || { st "ABORT no strata-dsv41 (DSV41=0 leaves it out)"; tail -20 "$OUT/build-dsv41.log" >> "$S"; exit 1; } fi fi +# strata-vision still builds from llama.cpp's own tree until it is vendored (the next commit) +[ -n "$LLAMA" ] || { st "ABORT strata-vision needs LLAMA= until it is vendored"; exit 1; } # the CPU reader: portable (AVX2), the fallback that runs on any PC cmake -G Ninja -S tools/vision -B "$OUT/bv" -DCMAKE_BUILD_TYPE=Release -DLLAMA_DIR="$LLAMA" -DSTRATA_VISION_CUDA=OFF \ -DSTRATA_PORTABLE=ON > "$OUT/cfg-vision.log" 2>&1 diff --git a/packaging/build_split_cuda.sh b/packaging/build_split_cuda.sh index e495006bc9..4f3b35165d 100644 --- a/packaging/build_split_cuda.sh +++ b/packaging/build_split_cuda.sh @@ -3,7 +3,7 @@ # so package_engine.py can ship it with `--include 'strata-split-*'` beside `strata`. One executable per card count and one architecture # (the engine refuses a card of any other architecture). RUNPATH $ORIGIN: it finds cudart/cublas beside itself. # -# SRC= B= CUDA=/usr/local/cuda-13.1 GG= [ARCH=86] [CARDS="2"] [JOBS=8] packaging/build_split_cuda.sh +# SRC= B= CUDA=/usr/local/cuda-13.1 [GG=] [ARCH=86] [CARDS="2"] [JOBS=8] packaging/build_split_cuda.sh # # ARCH is one compute capability; 86 is the one that has been run (2 RTX A6000). CARDS lists the counts to build; 3 and 4 build but have # not been run with the host exchange, and the launcher keeps them off unless a tester allows them (strata_control/split_engine.py). @@ -13,7 +13,8 @@ set -eu SRC=${SRC:-$(cd "$(dirname "$0")/.." && pwd)} B=${B:?B=} CUDA=${CUDA:?CUDA=} -GG=${GG:?GG=} +GG=${GG:-} # optional override (kept for two releases): a llama.cpp checkout to take ggml from; empty: the vendored third_party/strata-ggml +ggml=""; [ -z "$GG" ] || ggml="-DSTRATA_GGML_DIR=$GG" ARCH=${ARCH:-86} CARDS=${CARDS:-2} JOBS=${JOBS:-8} @@ -21,7 +22,7 @@ export PATH=$CUDA/bin:$PATH rm -f "$B/CMakeCache.txt" cmake -G Ninja -S "$SRC" -B "$B" -DCMAKE_BUILD_TYPE=Release -DSTRATA_ENABLE_CUDA=ON -DSTRATA_BUILD_TESTS=OFF -DSTRATA_BUILD_SPLIT=ON \ "-DSTRATA_SPLIT_CARDS=${CARDS// /;}" -DSTRATA_SPLIT_ARCH="$ARCH" "-DCMAKE_CUDA_ARCHITECTURES=$ARCH" -DCMAKE_CUDA_COMPILER="$CUDA/bin/nvcc" \ - -DCUDAToolkit_ROOT="$CUDA" -DSTRATA_GGML_DIR="$GG" -DSTRATA_NATIVE_EXPERTS=ON -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON \ + -DCUDAToolkit_ROOT="$CUDA" $ggml -DSTRATA_NATIVE_EXPERTS=ON -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON \ -DCMAKE_SKIP_BUILD_RPATH=OFF '-DCMAKE_INSTALL_RPATH=$ORIGIN' out="" for n in $CARDS; do diff --git a/packaging/build_split_hip.sh b/packaging/build_split_hip.sh index a19fa930ba..14ad70372c 100644 --- a/packaging/build_split_hip.sh +++ b/packaging/build_split_hip.sh @@ -7,7 +7,7 @@ # Which counts run which model is the launcher's rule (strata_control/split_engine.py: all the experts must fit in the cards' memory), not the binary's. RUNPATH $ORIGIN: it finds the ROCm libraries the engine package bundles (libamdhip64, hipblas, rocblas and its # Tensile data for gfx1201) beside itself, the same set `strata` uses. # -# SRC= B= HP= [LIBW=] [ARCHS="gfx1201;gfx1200;gfx11-generic"] GG= [CARDS="2 3 4"] [JOBS=12] packaging/build_split_hip.sh +# SRC= B= HP= [LIBW=] [ARCHS="gfx1201;gfx1200;gfx11-generic"] [GG=] [CARDS="2 3 4"] [JOBS=12] packaging/build_split_hip.sh # # After the build the script FAILS if the binary # - links librccl (RCCL is loaded at run time with dlopen when FNX_PF_RCCL=1 and is optional: the split must start without it), @@ -19,7 +19,8 @@ SRC=${SRC:-$(cd "$(dirname "$0")/.." && pwd)} B=${B:?B=} HP=${HP:?HP=} LIBW=${LIBW:-$HP} -GG=${GG:?GG=} +GG=${GG:-} # optional override (kept for two releases): a llama.cpp checkout to take ggml from; empty: the vendored third_party/strata-ggml +ggml=""; [ -z "$GG" ] || ggml="-DSTRATA_GGML_DIR=$GG" CARDS=${CARDS:-2 3 4} JOBS=${JOBS:-12} ARCHS=${ARCHS:-gfx1201;gfx1200;gfx11-generic} @@ -28,7 +29,7 @@ SYSDEPS=""; [ -d "$HP/lib/rocm_sysdeps" ] && SYSDEPS=";$HP/lib/rocm_sysdeps" BC=$HP/lib/llvm/amdgcn/bitcode; [ -d "$BC" ] || BC=$HP/amdgcn/bitcode rm -f "$B/CMakeCache.txt" cmake -G Ninja -S "$SRC" -B "$B" -DCMAKE_BUILD_TYPE=Release -DSTRATA_ENABLE_HIP=ON -DSTRATA_ENABLE_CUDA=OFF -DSTRATA_BUILD_TESTS=OFF -DSTRATA_BUILD_SPLIT=ON \ - "-DSTRATA_SPLIT_CARDS=${CARDS// /;}" "-DCMAKE_HIP_ARCHITECTURES=gfx1201" "-DSTRATA_SPLIT_HIP_ARCHS=$ARCHS" -DSTRATA_PREFILL_MMQ=ON -DSTRATA_NATIVE_EXPERTS=ON -DSTRATA_GGML_DIR="$GG" \ + "-DSTRATA_SPLIT_CARDS=${CARDS// /;}" "-DCMAKE_HIP_ARCHITECTURES=gfx1201" "-DSTRATA_SPLIT_HIP_ARCHS=$ARCHS" -DSTRATA_PREFILL_MMQ=ON -DSTRATA_NATIVE_EXPERTS=ON $ggml \ -DCMAKE_HIP_COMPILER="$HP/llvm/bin/clang++" -DCMAKE_HIP_COMPILER_ROCM_ROOT="$HP" "-DCMAKE_PREFIX_PATH=$HP;$LIBW$SYSDEPS" \ "-DCMAKE_HIP_FLAGS=--rocm-path=$HP --rocm-device-lib-path=$BC" -DSTRATA_PORTABLE=ON \ "-DCMAKE_EXE_LINKER_FLAGS=-Wl,-rpath,'\$ORIGIN' -Wl,--enable-new-dtags" diff --git a/packaging/mac/build_dsv41_engine.sh b/packaging/mac/build_dsv41_engine.sh index e082e22e77..7b6214b568 100644 --- a/packaging/mac/build_dsv41_engine.sh +++ b/packaging/mac/build_dsv41_engine.sh @@ -10,7 +10,7 @@ # # The package is text-only on purpose (--no-picture-reader): DeepSeek reads pictures with its own tower, which the Metal engine has not run. # Needs: Xcode Command Line Tools, cmake + ninja (a pip venv is enough: python3 -m venv v && v/bin/pip install cmake ninja), Apple's -# metal-cpp (METAL_CPP_DIR) and the llama.cpp tree setup pins (STRATA_GGML_DIR). Defaults: ~/strata-mac/metal-cpp, ~/strata-mac/llamacpp. +# metal-cpp (METAL_CPP_DIR; default ~/strata-mac/metal-cpp). ggml comes from the vendored third_party/strata-ggml; STRATA_GGML_DIR= is an override. # # Layout (strata-dsv41 finds these beside its own executable, metal/src/resource_path.h): # /metal/kernels/*.metal the shared Qwen kernels the DeepSeek host also compiles @@ -34,14 +34,14 @@ done 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} -STRATA_GGML_DIR=${STRATA_GGML_DIR:-$HOME/strata-mac/llamacpp} +GGML=""; [ -z "${STRATA_GGML_DIR:-}" ] || GGML="-DSTRATA_GGML_DIR=$STRATA_GGML_DIR" # an override (kept for two releases); default the vendored third_party/strata-ggml 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=12 HEAD 2>/dev/null || head -1 "$ROOT/BUILD_ID" 2>/dev/null || echo unknown) fi EXE="$BUILD/strata_ds4" if [ ! -x "$EXE" ]; then "$CMAKE" -S "$ROOT/metal" -B "$BUILD" -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_MAKE_PROGRAM="$NINJA" \ - -DMETAL_CPP_DIR="$METAL_CPP_DIR" -DSTRATA_GGML_DIR="$STRATA_GGML_DIR" -DSTRATA_BUILD_ID="$BUILD_ID" \ + -DMETAL_CPP_DIR="$METAL_CPP_DIR" $GGML -DSTRATA_BUILD_ID="$BUILD_ID" \ -DSTRATA_DS4_VERSION="$VERSION-metal" || exit 1 fi "$NINJA" -C "$BUILD" strata_ds4 || exit 1 # (always: a no-op when current; an existing build folder must not package a stale binary) diff --git a/spark/build_engine.sh b/spark/build_engine.sh index 0b9a7f736e..3980affea6 100755 --- a/spark/build_engine.sh +++ b/spark/build_engine.sh @@ -22,7 +22,8 @@ vision_dir=${BUILD_VISION_DIR:-$repo/build-vision-spark} jobs=${JOBS:-$(nproc)} py=${PYTHON:-python3} cmake=${CMAKE:-cmake} -llama=${STRATA_GGML_DIR:-$repo/third_party/llama.cpp} +llama=${STRATA_GGML_DIR:-} # an override: a llama.cpp checkout to take ggml from (kept for two releases); empty: the vendored third_party/strata-ggml +ggml=""; [ -z "$llama" ] || ggml="-DSTRATA_GGML_DIR=$llama" case "$(uname -s)-$(uname -m)" in Linux-aarch64|Linux-arm64) ;; @@ -41,10 +42,13 @@ case "$cudafull" in 13.*) echo "build_engine.sh: note: CUDA $cudafull has not been tried for this build; 13.0 is the release toolkit" >&2 ;; *) echo "build_engine.sh: needs the CUDA 13 toolkit (nvcc here: ${cudafull:-missing})" >&2; exit 2 ;; esac -if [ ! -f "$llama/ggml/CMakeLists.txt" ]; then - # llama.cpp at the pinned commit (ggml for the engine, mtmd for pictures), exactly as setup.py fetches it - (cd "$repo" && "$py" -c "import setup; print(setup.get_llama_cpp())") - [ -f "$llama/ggml/CMakeLists.txt" ] || { echo "build_engine.sh: no llama.cpp tree at $llama after fetching it (STRATA_GGML_DIR= names another)" >&2; exit 2; } +if [ "${BUILD_VISION:-1}" = 1 ] && [ -z "$llama" ]; then + # strata-vision still builds from llama.cpp's own tree until it is vendored (the next commit): the pinned one, as setup.py fetches it + llama=$repo/third_party/llama.cpp + if [ ! -f "$llama/ggml/CMakeLists.txt" ]; then + (cd "$repo" && "$py" -c "import setup; print(setup.get_llama_cpp())") + [ -f "$llama/ggml/CMakeLists.txt" ] || { echo "build_engine.sh: no llama.cpp tree at $llama after fetching it (STRATA_GGML_DIR= names another)" >&2; exit 2; } + fi fi # the commit the DeepSeek engine prints with --version: a checkout gives it to CMake itself; a tree copy without .git needs COMMIT= want_dsv41=OFF; [ "${BUILD_DSV41:-1}" = 1 ] && want_dsv41=ON @@ -59,7 +63,7 @@ cd "$repo" "$cmake" -G Ninja -S . -B "$build" -DCMAKE_BUILD_TYPE=Release -DSTRATA_ENABLE_CUDA=ON -DSTRATA_BUILD_TESTS=OFF \ -DSTRATA_NATIVE_EXPERTS=ON -DSTRATA_PORTABLE=ON -DSTRATA_Q6K_EXPERTS=ON -DSTRATA_MMQ_KQUANTS=ON \ -DSTRATA_BUILD_DSV41="$want_dsv41" -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON -DCMAKE_SKIP_BUILD_RPATH=OFF '-DCMAKE_INSTALL_RPATH=$ORIGIN' \ - "-DCMAKE_CUDA_ARCHITECTURES=${real};${last}-virtual" -DSTRATA_GGML_DIR="$llama" + "-DCMAKE_CUDA_ARCHITECTURES=${real};${last}-virtual" $ggml rm -f "$build/strata-dsv41" if [ "$want_dsv41" = ON ]; then "$cmake" --build "$build" --target strata strata_kq strata-dsv41 -j "$jobs" diff --git a/tools/hip/build_windows.bat b/tools/hip/build_windows.bat index 567905945f..98dc7adfe2 100644 --- a/tools/hip/build_windows.bat +++ b/tools/hip/build_windows.bat @@ -17,7 +17,7 @@ rem The release packages are built one per card family: r rem rdna2 (0.2.2, RX 6000: built, not tested on a real card) = gfx1030;gfx1031; each then goes through package_engine.py --variant rem STRATA_ROCM_VERSION 10.2.0a20260930 STRATA_ROCM_INDEX https://nightly.repo.amd.com/rocm/whl-next/ rem ROCM_VENV \.rocm-win BUILD_DIR \build-hip-win DIST_DIR \dist -rem STRATA_GGML_DIR a llama.cpp checkout at the pinned commit (default: CMake fetches it) +rem STRATA_GGML_DIR optional override (kept for two releases): a llama.cpp checkout to take ggml from; default: the vendored third_party/strata-ggml rem STRATA_ROCM_KEEP 1 = use the ROCM_VENV as it is (no pip install, even when its archs differ from STRATA_HIP_ARCHS) rem STRATA_VISION_HIP_ARCHS the GPU reader's archs (default: STRATA_HIP_ARCHS; about 70 MB of the zip per arch) rem STRATA_NO_VISION 1 = skip the two picture readers (strata-vision.exe for the CPU, strata-vision-hip.exe for the GPU) diff --git a/tools/test_setup_llama_archive.py b/tools/test_setup_llama_archive.py deleted file mode 100644 index 9a7bda52b1..0000000000 --- a/tools/test_setup_llama_archive.py +++ /dev/null @@ -1,173 +0,0 @@ -"""#1797: a damaged llama.cpp source zip must not be kept as an already-downloaded source. - - python tools/test_setup_llama_archive.py - -Only tiny local zip files and the standard library are used; no GPU, model or network is needed. -""" -from __future__ import annotations - -import contextlib -import io -import sys -import tempfile -import unittest -import zipfile -from pathlib import Path -from unittest import mock - -ROOT = Path(__file__).resolve().parents[1] -sys.path.insert(0, str(ROOT)) -import setup # noqa: E402 - - -class LlamaSourceArchive(unittest.TestCase): - def setUp(self): - tmp = tempfile.TemporaryDirectory() - self.addCleanup(tmp.cleanup) - self.root = Path(tmp.name) - self.source = self.root / "source.zip" - self.prefix = "llama.cpp-" + setup.LLAMA_CPP_COMMIT - with zipfile.ZipFile(self.source, "w", compression=zipfile.ZIP_STORED) as z: - z.writestr(self.prefix + "/ggml/CMakeLists.txt", "ggml fixture") - z.writestr(self.prefix + "/gguf-py/fixture.txt", "gguf fixture") - z.writestr(self.prefix + "/tools/ui/not-needed.txt", "unused web UI") - self.archive = self.root / "third_party" / f"llama.cpp-{setup.LLAMA_CPP_COMMIT[:7]}.zip" - self.marker = self.archive.with_name(self.archive.name + ".done") - self.llama = self.archive.parent / "llama.cpp" - self.archive.parent.mkdir() - self.unrelated = self.archive.parent / "user-notes.txt" - self.unrelated.write_text("keep this", encoding="utf-8") - stack = contextlib.ExitStack() - self.addCleanup(stack.close) - stack.enter_context(mock.patch.object(setup, "ROOT", self.root)) - # a plain path: download() copies it (file:// plus a Windows drive letter is not one) - stack.enter_context(mock.patch.object(setup, "LLAMA_CPP_ZIP", str(self.source))) - stack.enter_context(mock.patch.object(setup.urllib.request, "urlopen", - side_effect=AssertionError("test must not use the network"))) - stack.enter_context(contextlib.redirect_stdout(io.StringIO())) - - def cached(self, data): - self.archive.write_bytes(data) - setup.mark(self.archive) - - def assert_cache_removed(self): - self.assertFalse(self.archive.exists()) - self.assertFalse(self.marker.exists()) - self.assertEqual(self.unrelated.read_text(encoding="utf-8"), "keep this") - - def assert_installed(self, result): - self.assertEqual(result, self.llama) - self.assertEqual((result / "ggml/CMakeLists.txt").read_text(), "ggml fixture") - self.assertEqual((result / "gguf-py/fixture.txt").read_text(), "gguf fixture") - self.assertFalse((result / "tools/ui").exists()) - self.assertFalse((self.archive.parent / "_unpack").exists()) - self.assert_cache_removed() - - def test_success_uses_local_source_and_removes_archive_and_mark(self): - self.assert_installed(setup.get_llama_cpp()) - - def test_installed_source_is_reused_without_downloading(self): - self.assert_installed(setup.get_llama_cpp()) - with mock.patch.object(setup, "download", side_effect=AssertionError("already installed")): - self.assertEqual(setup.get_llama_cpp(), self.llama) - - def test_bad_cached_zip_is_removed_and_the_next_call_recovers(self): - self.cached(b"not a zip") - with self.assertRaises(zipfile.BadZipFile): - setup.get_llama_cpp() - self.assert_cache_removed() - self.assert_installed(setup.get_llama_cpp()) - - def test_a_bad_new_download_is_also_removed(self): - self.source.write_bytes(b"not a zip") - with self.assertRaises(zipfile.BadZipFile): - setup.get_llama_cpp() - self.assert_cache_removed() - - def test_truncated_cached_zip_is_removed(self): - self.cached(self.source.read_bytes()[:-22]) # missing the end-of-central-directory record - with self.assertRaises(zipfile.BadZipFile): - setup.get_llama_cpp() - self.assert_cache_removed() - self.assert_installed(setup.get_llama_cpp()) - - def test_crc_failure_during_extraction_is_removed_and_the_next_call_recovers(self): - # Keep the ZIP directory intact; the second member fails its CRC after the first was extracted. - self.cached(self.source.read_bytes().replace(b"gguf fixture", b"BAD! fixture", 1)) - self.llama.mkdir() - user_file = self.llama / "user-file.txt" - user_file.write_text("keep until a source was unpacked", encoding="utf-8") - with self.assertRaisesRegex(zipfile.BadZipFile, "Bad CRC-32"): - setup.get_llama_cpp() - self.assert_cache_removed() - self.assertTrue((self.archive.parent / "_unpack" / self.prefix / "ggml/CMakeLists.txt").is_file()) - self.assertEqual(user_file.read_text(), "keep until a source was unpacked") - self.assert_installed(setup.get_llama_cpp()) - - def test_original_bad_zip_exception_is_preserved(self): - for target in ("ZipFile", "ZipFile.extractall"): - with self.subTest(target=target): - self.cached(self.source.read_bytes()) - error = zipfile.BadZipFile("original error") - with mock.patch("setup.zipfile." + target, side_effect=error), \ - self.assertRaises(zipfile.BadZipFile) as caught: - setup.get_llama_cpp() - self.assertIs(caught.exception, error) - self.assert_cache_removed() - - def test_missing_archive_or_mark_during_cleanup_is_harmless(self): - for absent in (self.archive, self.marker): - with self.subTest(absent=absent.name): - self.cached(b"not a zip") - error = zipfile.BadZipFile("original error") - - def fail_after_removal(*args, **kwargs): - absent.unlink() - raise error - - with mock.patch.object(zipfile, "ZipFile", side_effect=fail_after_removal), \ - self.assertRaises(zipfile.BadZipFile) as caught: - setup.get_llama_cpp() - self.assertIs(caught.exception, error) - self.assert_cache_removed() - - def test_cleanup_failure_does_not_replace_the_bad_zip_error(self): - real_unlink = Path.unlink - for blocked in (self.archive, self.marker): - with self.subTest(blocked=blocked.name): - self.cached(b"not a zip") - error = zipfile.BadZipFile("original error") - - def deny_unlink(path, *args, **kwargs): - if path == blocked: - raise PermissionError("held open") - return real_unlink(path, *args, **kwargs) - - with mock.patch.object(zipfile, "ZipFile", side_effect=error), \ - mock.patch.object(Path, "unlink", deny_unlink), mock.patch.object(setup, "warn") as warn, \ - self.assertRaises(zipfile.BadZipFile) as caught: - setup.get_llama_cpp() - self.assertIs(caught.exception, error) - self.assertEqual(self.archive.exists(), blocked == self.archive) - self.assertTrue(self.marker.exists()) - self.assertEqual(self.unrelated.read_text(), "keep this") - warn.assert_called_once() - self.assertIn("held open", warn.call_args.args[0]) - - def test_permission_and_disk_errors_do_not_discard_a_valid_archive(self): - for target in ("ZipFile", "ZipFile.extractall"): - for error in (PermissionError("access denied"), OSError("disk full")): - with self.subTest(target=target, error=type(error).__name__): - data = self.source.read_bytes() - self.cached(data) - with mock.patch("setup.zipfile." + target, side_effect=error), \ - self.assertRaises(OSError) as caught: - setup.get_llama_cpp() - self.assertIs(caught.exception, error) - self.assertEqual(self.archive.read_bytes(), data) - self.assertTrue(self.marker.exists()) - self.assertEqual(self.unrelated.read_text(), "keep this") - - -if __name__ == "__main__": - unittest.main()