Skip to content

native: Qwen3.5-2B on Metal attests the execution witness's path, every weight byte with the kernel sources this OS compiles - #4908

Merged
ashhart merged 3 commits into
ashhart:mainfrom
kotevcode:execution-witness-metal
Nov 25, 2026
Merged

ashhart merged 3 commits into
ashhart:mainfrom
kotevcode:execution-witness-metal

Conversation

@kotevcode

@kotevcode kotevcode commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

With --execution-witness, native Qwen3.5-2B on a Mac attests its path, qwen3_5-2b/metal/tp1/mlx-q4g64/text, instead of reading unsupported_path. The engine stamps the checkpoint's files before the load and reads every shard byte once the server is ready, as on CUDA. In place of kernel images and the GPU's facts, it binds the Metal sources the load compiles, this OS's compile options, the OS build and chip, tensor units, the resolved profile and the served shape. Without the flag nothing changes: the witness is never opened.

Checks on this head

  • Head commit: 7d8bf41
  • Lean checker and python3 tools/pr_check.py --base upstream/main --pr 4908: lean 164 and 164 on the base and this head, 0 new; 0 errors.
  • Tests run, with the command and pass, fail and skip counts (macOS 26.6 build 25G72, Apple M5 Max, Xcode 27.2, Metal toolchain 27B47):
    • zig build test-execution-witness-metal-host: 6 passed, 0 failed, 0 skipped.
      • The path's conditions.
      • Every library's functions add up to q.kernels.total, and the kernel digest is stable.
      • Any one of these changes the digest: a shard byte rewritten at the same size and header, the kernel digest, the GPU, tensor units, the compile options, the lane rows, KV pages, or a resolved profile value.
      • A moved shard reads files_changed; a reload hashes again to the same digest.
      • Unstampable files read hash_failed and the load goes on.
    • zig build test-execution-witness-cuda-host: 22 passed. test-execution-witness-host: 55. test-disk-identity-host: 40. test-metal-residency-host: 11. test-metal-residency-owners-host: 84. compile-metal-residency-host and compile-disk-identity-metal-host build.
    • zig build test -Dcpu=apple_m1, on the previous head 5bcc339 (main ea57d96 with native: the execution witness's stamps, weight read and hash thread move to weights_witness.zig, and CUDA keeps its kernels, GPU and components #4907's commit; this head has the same diff on current main): 1029 of 1033 steps; 16742 passed, 2 failed, 128 skipped in the steps that ran (steps cached from an earlier run aren't counted). The same 4 steps fail on main at ea57d96: uocr/serve.zig:288's std.mem.zeroes on a Decoder with a non-nullable pointer (76200b6); qwen27/mtp_pick.zig's bf16_topk import; info's Qwen3.8-27B pricing test, which expects "not priced" where this Mac fits it; and the start CLI's managed-log tests (one KR67 test here, three of them on main). This PR touches none of them.
  • CI: runs on this head.
  • Not run, and why: other Macs and macOS builds (one M5 Max here); the 0.8B and 9B, which q.config refuses on this path.

Receipt

  • Main against branch: below, on one Mac, main 8e0548f against this head. Raw results, the driver and the analysis: https://gist.github.com/kotevcode/54b2d0bd8f14f51e0d47891c924a1b3b
  • Boxes it reaches: Apple silicon Macs serving native Qwen3.5-2B with --execution-witness.
  • New switch? No. It uses the existing --execution-witness flag and execution_witness request field; there's no new profile row.
  • Environment: base 8e0548f; branch 7d8bf41; Zig 0.17.0; Xcode 27.2 (27B52), Metal toolchain 27B47; macOS 26.6 (25G72); Apple M5 Max, 128 GB; zig build native -Doptimize=ReleaseFast -Dcpu=apple_m1 for both; mlx-community/Qwen3.5-2B-MLX-4bit@93760be4f1f69842a46bc13dbdc0f19e291392a3, serve --context 8192 --no-thinking --api-key, a fresh process per start.
  • Paths and platforms the change reaches: native Qwen3.5-2B on Metal, which I ran. Not run: other Apple chips, other macOS builds.
  • Arms: A main; B branch; C branch with --execution-witness and "execution_witness": true on every request, measured after known; D branch with the flag and no field. Order rotated ABCD, BCDA, CDAB, DABC. C's field goes through a small proxy that adds it and records each object, since the repo's tools have no extra-body option; D measures the same server without the proxy. Each cell is the median of its runs.
2B on Metal A B C D
Start to /health 200, s (n=4) 0.472 0.551 0.568 0.488
Start to known, s (n=4) 1.87–2.00 1.85–2.11
Cold first token, 7,680 tokens, ttft_s (n=4) 3.057 3.081 2.687 2.892
Decode, 1 stream, chat, tok/s (bench_openai, n=4) 133.2 138.5 135.6 137.4
Decode, 1 stream, code, tok/s (bench_openai, n=4) 275.9 268.8 280.0 297.6
Decode, 8 streams aggregate, code / chat, tok/s 767.1 / 517.3 748.7 / 484.5 756.4 / 505.0 743.5 / 524.7
Decode, 8 streams per stream, code / chat, tok/s 97.5 / 65.8 95.2 / 61.7 95.8 / 64.1 94.6 / 66.3

Another process used about two cores of this Mac during the run, so the four-arm medians spread wider than in earlier runs: chat's 1-stream runs read A 125.1–137.7, B 87.4–141.0, C 117.9–141.2, D 130.2–141.2, and the drafted code prompt A 261.1–330.1, B 104.7–341.7, C 259.6–364.4, D 280.1–339.8. The alternating runs compare A and B under the same load:

  • Decode, 8 rounds of A and B (bench_openai, greedy): chat 135.3 and 136.5 tok/s, code 320.8 and 294.5 (medians), with the same tokens. Chat's lower of each pair is A in six rounds and B in two; code's is A in four and B in four.
  • Startup with the flag off, 20 starts of each, alternating (startup.py): spawn to /health 200 is 0.538 s on A and 0.539 s on B (ranges 0.524–0.560 and 0.524–0.583), and spawn to the first streamed token 0.548 s and 0.549 s. The four-arm table's B reads later at /health in every run so far, and D, the same binary with more work, doesn't; head to head the gap is 0.6 ms.
  • Exactness: bench_concurrent.py --levels 1,8 --tokens 256 --alone --serial, sampled at 1.0 with seeds and greedy, code and chat. All 4 arms passed: 108/108 alone and 36/36 serial equal each, 0 unequal, 0 failed, and every 8-stream cell overlapped. Chat's serial cells accepted no draft, so the drafted-against-plain check is code's. Each prompt gave one token_sha across A, B, C and D: code bc1513a7f13c, chat f5c2a018d77d, the cold 7,680-token prompt 4fe11ea07e60…. At 1 and 8 streams, a 128-token greedy reply was ca9f285b473f… on A, B and C.
  • Witness, on C and D:
    • Every check read known on the path; 348 objects through C's proxy, all known, each token_sha256 equal to tensorfold.token_sha256.
    • pending at ready.
    • A restart gives the same content and components with a new instance.
    • Touching model.safetensors while the hash runs: the snapshot and replies read files_changed.
    • --idle-unload 5: parked; the next request reloads at epoch 2 and reads pending, then known with the same content.
    • --recall: feature_excluded, feature --recall.
  • Fresh and resumed, on the branch with the flag and --prompt-cache-gib 4 (this model keeps prompt states only with it): a second turn resumed from 7,552 of 7,738 tokens gives the same prompt_sha256, request_sha256 and token_sha256 as the same turn on a fresh server, and the same binding when repeated. The bindings differ only through the witness (a new instance).
  • Prompt speed before and after: tools/bench_cache.py --require-cold --expected-prompt-tokens 7680, above; every run cold (0 cached) and qualified.
  • Licence of any new weights or drafter: n/a.

Checklist

  • The title and description match the head commit, including the receipt and the stack.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency.
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.
  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off.
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo.
  • No precision traded for speed. The bits don't change.
  • Decode and prompt processing are no slower than main at one stream and the widest admitted.

@AIFlowML

Copy link
Copy Markdown
Contributor

I checked the stack at 5bcc339106ef86c353d380cf3e0ef0954ffeb857, including #4907, against main 4c79cfe346d3c239ff7dfd7aa694df799755bafa. The trial merge was clean. On macOS ARM64, zig build test-execution-witness-metal-host test-execution-witness-cuda-host test-execution-witness-host test-disk-identity-host -Dfixed-cpu --summary all passed all 123 tests.

I also applied Ash's overlapping build-fixture PR #4987 (7a156856dce85bc201577167b95e4e257713908b) after this stack. That merge was clean and zig build test-execution-witness-metal-host compile-metal-residency-host test-metal-residency-owners-host -Dfixed-cpu --summary all passed all 21 steps, including the residency compile and 87 tests. This verifies that landing order for the shared host build wiring. I did not rerun model serving or the live Metal witness receipt.

Igor Lessio - AIFLOW LABS

@ashhart

ashhart commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Thank you, @kotevcode. The Metal path keeps hashing behind the flag and binds the libraries the loader actually compiles, including the page-header concatenation. The public receipt still contains the fixed path and opaque digests rather than private input values.

This is ready for controlled comparisons. Final-tree token parity, off-path startup cost, and live receipt/reload checks remain before landing; the supplied host results are recorded.

  • Synthena

@kotevcode
kotevcode force-pushed the execution-witness-metal branch from 5bcc339 to 7d8bf41 Compare November 25, 2026 16:13
@ashhart

ashhart commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Thank you, @kotevcode. The Metal-witness patch is unchanged from the reviewed version; the shared extraction is now on main, and this head merges cleanly. The flag gate, source bindings and ownership remain intact.

Still ready for controlled comparisons. Final-tree token parity, flag-off startup cost and live receipt/reload checks remain before landing.

  • Synthena

@kotevcode

Copy link
Copy Markdown
Contributor Author

Thanks @ashhart. I rebased this onto main after #4907 landed: it's one commit now, 7d8bf41 on 8e0548f, with the same diff. I ran the three remaining checks on that tree, main 8e0548f against 7d8bf41, on an M5 Max with macOS 26.6 (25G72). The description and the gist have the full numbers.

  • Final-tree token parity: every alone, serial and 8-stream check from bench_concurrent.py --levels 1,8 --alone --serial is equal in all four arms (108/108 alone and 36/36 serial each). Each prompt gives one token_sha across main, flag off, and flag on with and without the field. A 128-token greedy reply at 1 and 8 streams is ca9f285b473f… on main, flag off and flag on.
  • Off-path startup: 20 starts of each, alternating, flag off. Spawn to /health 200 takes 0.538 s on main and 0.539 s on the branch, and spawn to the first streamed token 0.548 s and 0.549 s. In 8 alternating decode rounds, chat reads 135.3 and 136.5 tok/s, with the same tokens.
  • Live receipt and reload:
    • pending at ready, then known about 1.9 s after start.
    • All 348 reply objects read known, each with token_sha256 equal to the reply's.
    • A restart gives the same content and components with a new instance.
    • Touching a shard gives files_changed in the snapshot and replies.
    • --idle-unload 5 parks; the next request reloads at epoch 2 and reads pending, then known with the same content.
    • --recall reads feature_excluded.
    • A resumed turn (7,552 of 7,738 tokens cached) gives the same prompt, request and token hashes as the same turn on a fresh server.

Raw results and scripts: https://gist.github.com/kotevcode/54b2d0bd8f14f51e0d47891c924a1b3b

@ashhart

ashhart commented Nov 25, 2026

Copy link
Copy Markdown
Owner

@kotevcode, we ran the remaining checks on your head 7d8bf415b3, on an M3 Ultra Mac with Qwen3.5-2B-MLX-4bit:

  • Final-tree tokens: prompt and decode tokens are equal to main in every row, and prompt and decode speed are level.
  • Flag-off startup: 0.661 s on main and 0.656 s on this head, measured to the first answered request (six starts each, alternating).
  • Live witness: with --execution-witness, the witness reads known on qwen3_5-2b/metal/tp1/mlx-q4g64/text about 2 s after start. Across a restart the content digest stays the same and the witness changes. A reply with "execution_witness": true matches the same request without the flag word for word.

It's in a landing train now.

  • Synthena

@ashhart
ashhart force-pushed the execution-witness-metal branch from 7d8bf41 to af97136 Compare November 25, 2026 19:15
@ashhart
ashhart merged commit d3d565d into ashhart:main Nov 25, 2026
2 of 11 checks passed
@ashhart

ashhart commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Thank you @kotevcode. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes.

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.

3 participants