Skip to content

spike(s5): llama.cpp packaging, offline build and signed LLM packs — go with conditions - #32

Merged
billlyzhaoyh merged 10 commits into
mainfrom
spike/s5-llm-packaging
Nov 25, 2026
Merged

billlyzhaoyh merged 10 commits into
mainfrom
spike/s5-llm-packaging

Conversation

@billlyzhaoyh

@billlyzhaoyh billlyzhaoyh commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Spike S5 from docs/spikes/next-phase-spikes.md: can llama.cpp and a 4B model ship inside Folio, statically linked, with no build-time download, as a signed model pack under a licence we can redistribute? Write-up: docs/spikes/s5-llm-packaging.md.

Verdict: GO-WITH-CONDITIONS

Pass criterion Result
Zero-egress gate green Pass. It now also scans spikes/s5-llama on all targets.
Reproducible static build, no build-time download Pass. On the Mac: a clean build with the network denied, and two builds are bit-identical. CI is green on Linux (built with no network), macOS and Windows (built with real MSVC, and the self-check runs).
Signed pack verifies and loads Pass on a real Qwen3-4B pack. It is rejected after one byte is flipped, and older apps reject LLM packs outright.
Weights licence Pass. Qwen3-4B-Instruct-2507 and Qwen3.5-4B are Apache-2.0, ungated, with no use policy and no NOTICE.

Conditions for P2:

  1. Patch llama-cpp-2 so it doesn't build llama.cpp's common library, which contains the model downloader and an HTTP client. None of it reaches the binary (checked), but cargo tree can't see it. Also add a binary-level check to the gate.
  2. Windows needs llama.cpp on the static CRT (LLAMA_STATIC_CRT=1 plus CMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded) to match sherpa-onnx's /MT. The first CI run caught that the cross-build had hidden the CMake half; fixed in e20dad0.
  3. Keep the CI job green. It now passes on Linux (built with no network), macOS and Windows (where the self-check runs).
  4. Check prompt length before calling llama.cpp. It aborts the whole process on misuse.
  5. Decide the LLM pack layout. The zip format plus extraction costs twice the disk (2.4 GB + 2.4 GB). Consider making weights.bin the GGUF itself.

What changes

Pack support for LLMs (product code):

  • New values: the llm task and the llama.cpp engine (version 0.6.0), across the Rust crate, the TypeScript oracle, the signer, the fixtures and the app.
  • Streaming: signing and verifying stream the hash. GGUFs are zipped with Stored, not Deflate, and extraction streams to disk.
    • Signing a 2.4 GB pack: 4.66 GB → 3.7 MB peak RAM.
    • Verifying it: 2.28 GB → 2.6 MB peak RAM.
  • Resolver: resolve_verified_llm in app/src-tauri/src/models.rs returns a verified GGUF path and fails closed. Nothing calls it yet. The speech resolver now skips llm packs.

Spike crate: spikes/s5-llama/ is a throwaway binary that runs llama.cpp generation and a sherpa-onnx VAD in one process. Its .cargo/config.toml holds the build settings: GGML_METAL=OFF, LLAMA_STATIC_CRT=1, CMAKE_DISABLE_FIND_PACKAGE_OpenSSL=TRUE.

CI: a new s5-llama job for Linux, macOS and Windows. scripts/check-no-network.sh now also scans the spike crate.

Docs:

  • docs/model-packs.md: the llm task.
  • docs/assurance/third-party-components.md: llama.cpp, the binding crates and the Qwen weights. The sherpa-onnx version drift (1.13.2 → 2.0.1) is fixed too.
  • next-phase-spikes.md: the S5 row.

Numbers on the Mac:

  • Binary size grows by 3.6 MB on macOS and 4.4 MB on Windows (cross-built).
  • Qwen3-4B Q4_0 on 4 threads: 28–34 tok/s generation, 92–102 tok/s prompt, 2.77 GB peak footprint.

Tests (only the approved list)

  1. Conformance: a valid-llm case, plus the existing unknown-task rejection, in both the Rust and TS suites.
  2. Signer: modelpack-sign --task llm produces a pack the verifier accepts.
  3. App resolver: an LLM pack resolves to its GGUF, a tampered weights.bin is rejected, and a speech pack is never returned as an LLM.
  4. Streamed hash: a file of 1 MiB + 4,097 bytes hashes to a literal SHA-256.

All suites pass locally: modelpack, modelpack-sign, the app backend (59), the engine (48), core (102), app vitest (111), tsc, and the network gate.

Not covered

  • No reference-laptop timings.
  • On Windows the binary has run its self-check in CI, but no model has been loaded there yet.
  • No installer was built.
  • MSI doesn't apply: there is no MSI target yet.

…tion

- modelpack + TS oracle accept task "llm" and engine "llama.cpp"; new
  valid-llm conformance case (engine version 0.6.0 in context.json).
- modelpack hashes weights from a stream in 1 MiB chunks
  (verify_model_pack_reader, sha256_hex_file).
- modelpack-sign: --task llm; zips straight to weights.bin, streaming each
  file in (.gguf Stored, the rest Deflated, zip64 when >= 4 GiB); hashes and
  self-verifies by streaming; knows llama.cpp 0.6.0.
- app: verify and extract packs as streams; speech resolution skips llm
  packs; resolve_verified_llm(_in) returns the GGUF of the newest verified
  llm pack and fails closed (not called by the app yet).
- llm-tiny fixture pack signed with the test key.
spikes/s5-llama pins llama-cpp-2 =0.1.161 (llama.cpp v0.6.0) next to the
engine. --self-check starts onnxruntime and the llama.cpp CPU backend in one
process; --model loads a GGUF and reports load time, tokens/s and peak RSS.
.cargo/config.toml keeps Metal and OpenSSL out of the CMake build and builds
llama.cpp with the static CRT to match sherpa-onnx on Windows.

The zero-egress gate also scans the spike (all targets), and a new CI job
builds and self-checks it on Linux, macOS and Windows, the Linux build in a
network namespace with no network.
GO-WITH-CONDITIONS. Adds the Qwen weights and llama.cpp rows to the
third-party inventory (and fixes sherpa-onnx 1.13.2 -> 2.0.1), documents llm
packs in model-packs.md, and marks S5 in the spike plan.
…c CRT on real MSVC

windows-latest CI failed with the RuntimeLibrary MD/MT mismatch: LLAMA_STATIC_CRT
only adds /MT flags, and llama.cpp's CMake (policy CMP0091) takes the runtime from
CMAKE_MSVC_RUNTIME_LIBRARY instead.
Both validators (Rust and TS) accepted task "llm" with engine "sherpa-onnx",
so a pack could pass the engine-version gate for one runtime and be handed to
another. New conformance case malformed-llm-wrong-engine.
…es no LLM pack

- Speech resolution verified every pack, LLM included, before dropping LLM
  packs: a 2.4 GB pack added ~6 s of hashing to every recording start. The
  manifest's declared task now decides which packs are verified at all (a
  forged task can only make a pack be skipped).
- engine_versions() no longer lists llama.cpp, which this build doesn't link,
  so a signed LLM pack shows as "engine not supported by this build" instead
  of verified.
… an out-dir inside the model dir

Streaming into weights.bin (S5) truncated an existing pack before the source
was read, so a failed rebuild left a broken pack, and an out-dir inside the
model dir zipped its own partial output. The pack is now built as
.weights.bin.partial / .manifest.json.partial, self-verified, then renamed into
place; an out-dir inside the model dir is refused up front.
…t.py; reject --threads < 1

- --vad dropped its sherpa-onnx session before llama.cpp loaded, so the two
  runtimes never held sessions at once. The session now stays open and runs
  again after generation.
- The documented benchmark used an uncommitted prompt.py; it is committed
  (byte-identical output: the 730-token housing-visit prompt).
- ggml silently replaces --threads 0 with 4, mislabelling runs.
…cks unsupported in this build, VAD kept open (runs 7-9), CI status
@billlyzhaoyh
billlyzhaoyh merged commit 7993e15 into main Nov 25, 2026
14 checks passed
@billlyzhaoyh
billlyzhaoyh deleted the spike/s5-llm-packaging branch November 26, 2026 00:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant