From a143a4c4bd49b5ec850ba7481967ce2bae224594 Mon Sep 17 00:00:00 2001 From: SMC17 <173011278+SMC17@users.noreply.github.com> Date: Tue, 17 Nov 2026 18:00:41 -0600 Subject: [PATCH] Build and test from a fresh clone on Zig 0.16 build.zig.zon declared safetensors and tokenizers as path deps under the gitignored deps/ directory, so a fresh clone failed before compiling anything ("unable to open deps/safetensors-zig: FileNotFound"). Both upstream repos are now public, so pin them as url+hash archive deps at the same SHAs scripts/fetch-deps.sh used, and drop the deps/ bootstrap (script, .gitkeep, gitignore entries, CI multi-checkout). The default install step also failed: examples/infer_tinyllama.zig still called the pre-paging KVCache.init signature. Construct the PageManager and BlockAllocator the way the benches do, sized for max_position_embeddings tokens per layer. README test counts updated to the measured 82/91 (9 Linux-only pool tests skip on macOS). Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yml | 23 ++--------------------- .gitignore | 4 ---- AGENTS.md | 14 ++++---------- README.md | 12 +++++++----- build.zig.zon | 6 ++++-- deps/.gitkeep | 0 examples/infer_tinyllama.zig | 9 ++++++++- scripts/fetch-deps.sh | 30 ------------------------------ 8 files changed, 25 insertions(+), 73 deletions(-) delete mode 100644 deps/.gitkeep delete mode 100755 scripts/fetch-deps.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1a3e1cb..8628467 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,8 +1,5 @@ -# Clean-clone CI: sibling private deps checked out into deps/. -# -# Default GITHUB_TOKEN cannot read other private repos. Set repository secret -# CROSS_REPO_PAT (classic PAT or fine-grained with contents:read on -# safetensors-zig + tokenizers-zig) for multi-checkout to work. +# Clean-clone CI: dependencies are fetched by `zig build` from the +# url+hash pins in build.zig.zon. name: CI on: @@ -21,22 +18,6 @@ jobs: with: fetch-depth: 1 - - name: Checkout safetensors-zig into deps/ - uses: actions/checkout@v4 - with: - repository: SMC17/safetensors-zig - path: deps/safetensors-zig - fetch-depth: 1 - token: ${{ secrets.CROSS_REPO_PAT || github.token }} - - - name: Checkout tokenizers-zig into deps/ - uses: actions/checkout@v4 - with: - repository: SMC17/tokenizers-zig - path: deps/tokenizers-zig - fetch-depth: 1 - token: ${{ secrets.CROSS_REPO_PAT || github.token }} - - uses: mlugg/setup-zig@v2 with: version: 0.16.0 diff --git a/.gitignore b/.gitignore index 9d17262..2aa3ae3 100644 --- a/.gitignore +++ b/.gitignore @@ -3,8 +3,4 @@ zig-out/ *.log .DS_Store - -# Local/CI dependency checkouts (see scripts/fetch-deps.sh) -deps/* -!deps/.gitkeep zig-pkg/ diff --git a/AGENTS.md b/AGENTS.md index dfa0119..c54eac4 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -9,16 +9,10 @@ parity with Berkeley vLLM / SGLang. STATUS uses explicit non-claims — keep the 1. Read `README.md` and `STATUS.md` (Type-I notes on benches matter). 2. Run the proof gate before claiming tests green. -3. Dependencies live under `deps/` (gitignored checkouts or symlinks): - -```text -deps/safetensors-zig -> path dep (clone or symlink) -deps/tokenizers-zig -> path dep (clone or symlink) -``` - -Bootstrap: `./scripts/fetch-deps.sh` (uses `gh` or sibling symlinks). -CI checks private siblings into `deps/` via multi-checkout (see `.github/workflows/ci.yml`). -Private GitHub archive `url`+`hash` is not used: unauthenticated fetch 404s. +3. Dependencies (safetensors-zig, tokenizers-zig) are pinned in + `build.zig.zon` as public GitHub archive `url`+`hash` entries, so a + fresh clone fetches them with no extra step. To bump one, run + `zig fetch ` and update both `url` and `hash`. ## Proof gate diff --git a/README.md b/README.md index 37b01e7..9f2ae77 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![CI](https://github.com/SMC17/vllm-zig/actions/workflows/ci.yml/badge.svg)](https://github.com/SMC17/vllm-zig/actions) [![License: AGPL-3.0](https://img.shields.io/badge/License-AGPL_3.0-blue.svg)](LICENSE) [![Zig: 0.16](https://img.shields.io/badge/Zig-0.16-orange.svg)](https://ziglang.org/) -[![Tests: 77/77](https://img.shields.io/badge/tests-77%2F77-success.svg)](#tests) +[![Tests: 82 pass, 9 skip](https://img.shields.io/badge/tests-82%20pass%2C%209%20skip-success.svg)](#tests) ## What ships (v0.0.6) @@ -16,8 +16,8 @@ - PagedAttention KV substrate (`page_manager.zig` + `paged_attention.zig`): K and V planes split, 64-byte-aligned, per-block per-head views - Streaming `generate()` — each decoded token emitted via caller callback -- Parallel BF16→F32 weight load (safetensors-zig as a path dependency) -- 77/77 unit tests pass; SIMD ↔ scalar matmul agreement across 7 +- Parallel BF16→F32 weight load (safetensors-zig as a pinned `url`+`hash` dependency) +- 82/91 unit tests pass, 9 skipped off Linux; SIMD ↔ scalar matmul agreement across 7 `(M, K, N)` shape variants ## What does NOT ship yet @@ -31,7 +31,7 @@ ## Quickstart ```sh -zig build test # 77 unit tests +zig build test # 91 unit tests zig build forward-skeleton # Wiring smoke test zig build bench-matmul # Matmul scalar vs SIMD speedup table zig build bench-pool # Persistent pool vs ad-hoc spawn @@ -168,7 +168,9 @@ cost dominating at M=1) was closed by the persistent worker pool at v0.0.5. ## Tests -77/77 unit tests pass at v0.0.6 (`zig build test`). SIMD ↔ scalar +`zig build test --summary all` on Zig 0.16.0, macOS arm64: 82/91 pass, +9 skipped (the `thread_pool.zig` tests need Linux futex and skip on +other OSes). Measured from a fresh clone on 2026-11-17. SIMD ↔ scalar matmul agreement verified across 7 `(M, K, N)` shape variants. The `forward-skeleton`, `infer-tinyllama`, and `bench-tinyllama-pool` steps exercise the full pipeline end-to-end against real weights. diff --git a/build.zig.zon b/build.zig.zon index 6b98a09..6f4f5c6 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -21,11 +21,13 @@ .dependencies = .{ // Upstream: https://github.com/SMC17/safetensors-zig .safetensors = .{ - .path = "deps/safetensors-zig", + .url = "https://github.com/SMC17/safetensors-zig/archive/17328a3f984ab2b657396302f438a572e8a05be9.tar.gz", + .hash = "safetensors_zig-0.3.0-jWdPYkEIHgDRmmzZ7WK3QsUDZ9AhbWm7yhY1hQg8mscU", }, // Upstream: https://github.com/SMC17/tokenizers-zig .tokenizers = .{ - .path = "deps/tokenizers-zig", + .url = "https://github.com/SMC17/tokenizers-zig/archive/558bfbcaf29319aacf6641ce81c901e571f14a15.tar.gz", + .hash = "tokenizers_zig-0.26.0-bcGp7yR1BwBZpxEKAKwwLkm1r56lGZOBuCieYOvfYUZ8", }, }, } diff --git a/deps/.gitkeep b/deps/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/examples/infer_tinyllama.zig b/examples/infer_tinyllama.zig index e50b906..78b07c6 100644 --- a/examples/infer_tinyllama.zig +++ b/examples/infer_tinyllama.zig @@ -81,7 +81,14 @@ pub fn main(init: std.process.Init) !void { std.debug.print("prompt tokens: {d}\n", .{ids_with_bos.len}); // --- KV cache --- - var kv = try vllm.kv_cache.KVCache.init(alloc, cfg.num_hidden_layers, cfg.max_position_embeddings, cfg.num_key_value_heads, cfg.head_dim); + // Paged KV: enough blocks for max_position_embeddings tokens in every layer. + const BLOCK_SIZE = vllm.page_manager.PageManager.BLOCK_SIZE; + const kv_blocks = cfg.num_hidden_layers * ((cfg.max_position_embeddings + BLOCK_SIZE - 1) / BLOCK_SIZE); + var pm = try vllm.page_manager.PageManager.init(alloc, kv_blocks, cfg.num_key_value_heads, cfg.head_dim); + defer pm.deinit(); + var ba = try vllm.paged_attention.BlockAllocator.init(alloc, kv_blocks); + defer ba.deinit(); + var kv = try vllm.kv_cache.KVCache.init(alloc, cfg.num_hidden_layers, cfg.num_key_value_heads, cfg.head_dim, &pm, &ba); defer kv.deinit(); // --- Generate --- diff --git a/scripts/fetch-deps.sh b/scripts/fetch-deps.sh deleted file mode 100755 index ff27577..0000000 --- a/scripts/fetch-deps.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env bash -# Clone private sibling deps into deps/ for clean-clone builds. -set -euo pipefail -ROOT="$(cd "$(dirname "$0")/.." && pwd)" -cd "$ROOT" -mkdir -p deps -ST_SHA="${SAFETENSORS_SHA:-17328a3f984ab2b657396302f438a572e8a05be9}" -TK_SHA="${TOKENIZERS_SHA:-558bfbcaf29319aacf6641ce81c901e571f14a15}" - -clone_dep() { - local name=$1 sha=$2 - local dest="deps/$name" - if [ -e "$dest/.git" ] || [ -L "$dest" ]; then - echo "deps/$name already present" - return 0 - fi - if [ -d "../$name/.git" ]; then - ln -sfn "../$name" "$dest" - echo "symlinked deps/$name -> ../$name" - return 0 - fi - echo "cloning SMC17/$name @$sha" - gh repo clone "SMC17/$name" "$dest" -- --depth 1 - git -C "$dest" fetch --depth 1 origin "$sha" - git -C "$dest" checkout "$sha" -} - -clone_dep safetensors-zig "$ST_SHA" -clone_dep tokenizers-zig "$TK_SHA" -echo "deps ready"